Friedman test error, possibly wrong test?

心已入冬 提交于 2021-02-11 13:50:27

问题


I have the following data:

df<-structure(list(participant_id = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L), 
.Label = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32"), class = "factor"), 
tool = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), 
.Label = c("pig", "silicone", "sponge"), class = "factor"), 
value = c(1, 3, 2, 4, 2, 1, 4, 3, 4, 4, 3, 1, 3, 2, 3, 2, 1, 2, 3, 4, 3, 2, 2, 2, 2, 1, 1, 4, 2, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 1, 2, 1, 1, 1, 1, NA, 2, 1, 2, 4, 1, 1, 2, 5, 4, 4, 3, 4, 4, 4, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4, 5, 5, 4, 4, 5, 4, 3, 3, 2, 4, 4, 3, 5)),
row.names = c(NA, -96L), class = c("tbl_df", "tbl", "data.frame"))

Its 32 or so students who were asked to rate three different objects (the "tool" column) on a 1-5 likert-type scale how well they liked it (the "value" column).

So the idea is to compare the three types of tools and see if the scores of how well the students liked it are statistically different.

Originally I was thinking kruskal-wallis test to compare the groups, but it was pointed out to me that because this is a within-subjects design and the students themselves rate all three objects, I should use a Friedman-test.

So I run this code:

 test.fried<-df%>%friedman_test(value~tool|participant_id)

And I receive this error:

"Error in friedman.test.default(c(1, 3, 2, 4, 2, 1, 4, 3, 4, 4, 3, 1, 3, : not an unreplicated complete block design"

Now this error has been asked about: here and here, so I looked into the comments listed.

  • I made sure my groups were coded as factors
  • I did table(df$participant_id,df$tool) to make sure I didn't have missing combinations or doubled up combinations.

Am I missing something obvious? Is this even the right test?


回答1:


You have a missing value for value in participant_id 25 for sponge so you will have to impute a value, or remove that participant. Removing is simple:

df.sub <- subset(df, subset=df$participant_id != 25)
df.sub <- drop.levels(df.sub)
friedman.test(value~tool | participant_id, df.sub)
# 
#   Friedman rank sum test
# 
# data:  value and tool and participant_id
# Friedman chi-squared = 42.596, df = 2, p-value = 5.627e-10

Note. You did not have to make participant_id a factor. It is easier to drop if it is a numeric value:

df$participant_id <- as.numeric(df$participant_id) 
friedman.test(value~tool | participant_id, df, subset=participant_id != 25)
# 
#   Friedman rank sum test
# 
# data:  value and tool and participant_id
# Friedman chi-squared = 42.596, df = 2, p-value = 5.627e-10


来源:https://stackoverflow.com/questions/59866458/friedman-test-error-possibly-wrong-test

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!