Joe Crozier
Joe Crozier

Reputation: 1036

Friedman test error, possibly wrong test?

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.

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

Upvotes: 0

Views: 1900

Answers (1)

dcarlson
dcarlson

Reputation: 11056

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

Upvotes: 1

Related Questions