Reputation: 33
enter image description hereI have some data relating to levels of a chemical in the blood before and after treatment and there are 4 treatment groups - ABCD. I have been told I can run a Friedman test to compare all of these variables at once. The code I've tried is:
attach(LiverData.Wide)
friedman.test(ALPB ~ ALPM | Group)
I get this error:
Error in friedman.test.default(c(80L, 37L, 52L, 36L, 39L, 48L, 71L, 81L, :
not an unreplicated complete block design
so I need to work out how to get the data into block form so that I can run the test - any ideas how?
NB: I am a novice at R so sorry for a very basic question!
Also, I am only focusing on ALPB and ALPM - I am not interested in the other columns
Upvotes: 3
Views: 3053
Reputation: 46908
It requires an unreplicated data, meaning if you have replicates, you either summarize them or consider the observation as a block
For example:
LiverData.Wide = data.frame(
obs=rep(1:10,4),
APLB = rnorm(40,rep(1:4,each=10),1),
APLM = rnorm(40,rep(2*(1:4),each=10),1),
Group = rep(c("A","B","C","D"),each=10)
)
Then you average the measurement per group and test the difference between APLB and APLM using a matrix:
sumData = aggregate(APLB ~ APLM_grp + Group,data=LiverData.Wide,mean)
friedman.test(as.matrix(sumData[,2:3]))
Or if you consider observation as a block:
friedman.test(as.matrix(LiverData.Wide[,2:3]))
Upvotes: 3