我想用Friedman.test来重复测量。
我想比较(pre1
和after1
)与(pre2
after2
)之间的差异。 1和2是两种不同的药物。 Pre1(在服用药物1之前)1之后(服用药物2之后)。
示例:
df <- data.frame(Name= rep(c("a","b","c","d"), times=4), Blocks = c(rep("pre1",time=4), rep("after1",time=4), rep("pre2",time=4), rep("after2",time=4)), group= rep(c("1","1","1","1","2","2","2","2"), time=2), Value=runif(16, 5.0, 7.5))
friedman.test(Value ~ Blocks | Name, data=df)
对此我应该添加每个pre1和after1在一起的想法。 这样:
friedman.test(Value ~ Blocks | Name, data=df, groups = group)
ERROR: Error in model.frame.default(formula = Value ~ Blocks + Name, data = df, :
invalid type (pairlist) for variable '(...)'
为什么会出现这个错误?如何实现我的目标?
答案 0 :(得分:1)
对不起,迟到的回复,
基于this post,并建议使用data.table
:
library ( data.table, nlme )
Longitudinal <- data.table ( cbind (
expand.grid ( Subject = letters [ 1:4 ], Time = 1:2, Drug = 1:2 ),
Value = runif ( 16, 5.0, 7.5 )))
Longitudinal [, ValueRank := rank ( Value )]
Fit <- lme ( fixed = ValueRank ~ Time + Drug,
random = ~1|Subject, data = Longitudinal )
anova ( Fit )
希望这有帮助。