I will give a sample below of how my data is organized but every time I run Friedman's using frieman.test(y =, groups = , blocks= ) it gives me an error that my data is not from an unreplicated complete block design despite the fact that it is.
score | treatment | day |
---|---|---|
10 | 1 | 1 |
20 | 1 | 1 |
40 | 1 | 1 |
7 | 2 | 1 |
100 | 2 | 1 |
58 | 2 | 1 |
98 | 3 | 1 |
89 | 3 | 1 |
40 | 3 | 1 |
70 | 4 | 1 |
10 | 4 | 1 |
28 | 4 | 1 |
86 | 5 | 1 |
200 | 5 | 1 |
40 | 5 | 1 |
77 | 1 | 2 |
100 | 1 | 2 |
90 | 1 | 2 |
33 | 2 | 2 |
15 | 2 | 2 |
25 | 2 | 2 |
23 | 3 | 2 |
54 | 3 | 2 |
67 | 3 | 2 |
1 | 4 | 2 |
2 | 4 | 2 |
400 | 4 | 2 |
16 | 5 | 2 |
10 | 5 | 2 |
90 | 5 | 2 |
library(readr)
sample_data$treatment <- as.factor(sample_data$treatment) #setting treatment as categorical independent variable
sample_data$day <- as.factor(sample_data$day) #setting day as categorical independent variable
summary(sample_data)
friedman3 <- friedman.test(y = sample_data$score, groups = sample_data$treatment, blocks = sample_data$day)
summary(friedman3)
the code above gives me the error I described earlier.
However when I convert the csv data to a matrix, Friedman's works but the answer seems wrong as SPSS gives a different result for the degrees of freedom.
sample_data$treatment <- as.factor(sample_data$treatment) #converting to categorical independent variable
sample_data$day <- as.factor(sample_data$day) #converting to categorical independent variable
data = as.matrix(sample_data)
friedman.test(data)
friedman2 <- friedman.test(y = data$score, groups = data$treatment, blocks = data$day)
summary(friedman2)
Any idea what I am doing incorrectly?
I am aware that Friedman's gives me chi-square but I am also wondering how can I get the test statistic instead of the chi-square value.
I am using Rstudio and I am new to R. And I want to know how to specify groups as treatment and day as blocks.
CodePudding user response:
We could summarise the data by taking the mean
of the 'score' and then use that summarised data in friedman.test
sample_data1 <- aggregate(score ~ ., sample_data, FUN = mean)
friedman.test(sample_data1$score, groups = sample_data1$treatment,
blocks = sample_data1$day)