我的数据嵌套在组级别。有五种不同的治疗方法。在每种治疗中,将四个参与者分组。它是关于竞争下参与者的捐赠行为(因变量=捐赠,度量,以€为单位)(解释性变量=治疗,顺序)。数据结构是这样的:
Treatment Session player.cumulative_donation:
CG uk4rlbdo 2.5
CG uk4rlbdo 1.4
CG uk4rlbdo 0
CG uk4rlbdo 1
CG dg0bqvit 0
CG dg0bqvit 0
CG dg0bqvit 0.5
CG dg0bqvit 0
TG1 g6n3z46r 1
TG1 g6n3z46r 0
TG1 g6n3z46r 0
TG1 g6n3z46r 0.2
基于Rcompanion计算方差分析后,我想使用multcomp函数执行Posthoc测试。
但是,如果我跑步
library(multcomp)
posthoc = glht(model,
linfct = mcp(Treatment="Tukey"))
我收到了我不理解的错误消息
Error in model.frame.lme(object) : object does not contain any data
Error in factor_contrasts(model) :
no ‘model.matrix’ method for ‘model’ found!
模型中存储了数据:
> model
Linear mixed-effects model fit by REML
Data: NULL
Log-restricted-likelihood: -166.8703
Fixed: Donation ~ Treatment
(Intercept) TreatmentTG1 TreatmentTG2 TreatmentTG3 TreatmentTG4
0.7492227 1.3343727 0.2981268 1.4943010 0.5274175
Random effects:
Formula: ~1 | Session
(Intercept) Residual
StdDev: 0.1759392 1.651152
Number of Observations: 88
Number of Groups: 27
变量是:
$ player.cumulative_donation: num 2.5 1.4 0 1 0 0 0.5 0 1 0 ...
$ player.treatmentgroup : chr "CG" "CG" "CG" "CG" ...
$ Session code : chr "uk4rlbdo" "uk4rlbdo" "uk4rlbdo" "uk4rlbdo" ...
编辑:R命令创建模型:
library(nlme)
model = lme(Donation ~ Treatment, random=~1|Session,
method="REML")
anova.lme(model,
type="sequential",
adjustSigma = FALSE)
如果数据在环境中是变量,则回归有效,但是对于下游分析,他们要求将其存储为lme对象内的data.frame:
例如,这很好用
library(nlme)
library(multcomp)
df = data.frame(Treatment=sample(c("TG1","TG2","TG3"),100,replace=TRUE),
Donation=rnorm(100),
Session = sample(c("uk4rlbdo","dg0bqvit"),100,replace=TRUE))
model = lme(Donation ~ Treatment, random=~1|Session,data=df)
glht(model,linfct=mcp(Treatment="Tukey"))
而当您将变量放入环境时,我会遇到相同的错误:
Donation = df$Donation
Treatment = df$Treatment
Session =df$Session
model = lme(Donation ~ Treatment, random=~1|Session)
glht(model,linfct=mcp(Treatment="Tukey"))