3

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
  • ALPB is level of ALP before treatment.
  • ALPM is level of ALP after.
  • Group is the column heading for all the different groups.

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

Alex
  • 33
  • 4
  • It would be helpful if you added a sample of your data or a made-up sample with the same characteristics and organised in exactly the same way, so that we have an idea of the layout and content of the matrix. On a first look, the problem seems to be that you have more than one observation for each combination of grouping factors (i.e. of ALPM and Group, in your code), while the Friedman test requires exactly one. See ?friedman.test : "groups and blocks are obtained from the column and row indices, respectively" . – InverniE Jan 16 '20 at 11:49
  • I've added a link to a screenshot of my data in r! thank you for your help. Since the test requires one observation for each combo of grouping factors - is there a way to resolve that for my data? – Alex Jan 16 '20 at 14:13

1 Answers1

3

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]))
StupidWolf
  • 45,075
  • 17
  • 40
  • 72