简体   繁体   English

在 R 中使用 multcomp 事后测试嵌套方差分析

[英]Posthoc test nested anova using multcomp in R

my data is nested on a group level.我的数据嵌套在组级别。 There are five different treatments.有五种不同的治疗方法。 Within every treatment, four participants are grouped.在每次治疗中,四名参与者被分组。 It is about donation behavior of those participants (dependent variable = Donation, metric, in €) under competition ( Explanatory variable = Treatment, ordinal).它是关于那些参与者的捐赠行为(因变量 = 捐赠,公制,以欧元为单位)在竞争(解释变量 = 治疗,序数)下。 The data structure is like this:数据结构是这样的:

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

After computing the ANOVA based on Rcompanion , I want to perform a Posthoc test using the multcomp function.基于Rcompanion计算方差分析后,我想使用 multcomp function 执行事后检验。

however, if I run但是,如果我跑

library(multcomp)

posthoc = glht(model,
               linfct = mcp(Treatment="Tukey"))

I get this error message which I don't understand我收到这条我不明白的错误信息

Error in model.frame.lme(object) : object does not contain any data
Error in factor_contrasts(model) : 
  no ‘model.matrix’ method for ‘model’ found!

There is data stored in model: model中存有数据:

> 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

The variables are:变量是:

$ 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" ...

EDIT: The R command to create model:编辑:创建 model 的 R 命令:

library(nlme)

model = lme(Donation ~ Treatment, random=~1|Session,
            method="REML")

anova.lme(model,
          type="sequential",
          adjustSigma = FALSE)

Output of dput(head(SPSS_Data.df,10)): dput(head(SPSS_Data.df,10))的 Output:

structure(list(Participant_id = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 
10), participant.id_in_session = c(1, 2, 3, 4, 1, 2, 3, 1, 2, 
3), participant.code = c("hcj5o43a", "ugiv2jlq", "53vepzb7", 
"j2k7noqy", "njm1sr5d", "c2phh8p1", "5xaot5ii", "lvfkfw72", "05pjmgwp", 
"o0yt5qbt"), `Session code` = c("uk4rlbdo", "uk4rlbdo", "uk4rlbdo", 
"uk4rlbdo", "dg0bqvit", "dg0bqvit", "dg0bqvit", "8stn6uxo", "8stn6uxo", 
"8stn6uxo"), player.cumulative_donation = c(2.5, 1.4, 0, 1, 0, 
0, 0.5, 0, 1, 0), player.treatmentgroup = c("CG", "CG", "CG", 
"CG", "CG", "CG", "CG", "CG", "CG", "CG"), TG_coded = c(0, 0, 
0, 0, 0, 0, 0, 0, 0, 0), CG_Dummy = c(1, 1, 1, 1, 1, 1, 1, 1, 
1, 1), TG1_Dummy = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), TG2_Dummy = c(0, 
0, 0, 0, 0, 0, 0, 0, 0, 0), TG3_Dummy = c(0, 0, 0, 0, 0, 0, 0, 
0, 0, 0), TG4_Dummy = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), Gruppe = c(1, 
1, 1, 1, 2, 2, 2, 3, 3, 3), `Perceived Competition` = c(2, 1, 
1, 1, 3, 1, 2, 2, 1, 1), `Influenced behavior` = c(2, 2, 1, 1, 
3, 1, 4, 1, 1, 1), `Donate more` = c(3, 3, 1, 1, 1, 3, 2, 1, 
1, 1), `Donate less` = c(3, 3, 1, 1, 3, 3, 3, 1, 1, 1)), row.names = c(NA, 
10L), class = "data.frame")

The regression works if the data is a variable in the environment, but for downstream analysis, they required it to be stored as a data.frame inside the lme object:如果数据是环境中的变量,则回归有效,但对于下游分析,他们要求将其作为 data.frame 存储在 lme object 中:

For example, this works perfectly例如,这非常有效

library(nlme)
library(multcomp)

SPSS_Data.df = data.frame(
"player.treatmentgroup"=sample(c("TG1","TG2","TG3"),100,replace=TRUE),
"player.cumulative_donation"=rnorm(100),
"Session code" = sample(c("uk4rlbdo","dg0bqvit"),100,replace=TRUE),
check.names=FALSE)

df = setNames(SPSS_Data.df[,c("player.cumulative_donation",
"player.treatmentgroup","Session code")],
              c("Donation","Treatment","Session")
              )

model = lme(Donation ~ Treatment, random=~1|Session,data=df)
glht(model,linfct=mcp(Treatment="Tukey"))

Whereas when you put the variable into the environment, i get the same error:而当您将变量放入环境中时,我得到了同样的错误:

Donation = df$Donation
Treatment = df$Treatment
Session =df$Session
model = lme(Donation ~ Treatment, random=~1|Session)
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!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM