mcp2matrix模型,linfct = linfct中的错误:“整数”类的变量“Methode”作为/不包含在“模型”中

问题描述

我不明白为什么它在这里不起作用是我的代码

     library(lme4,multcomp)

tijd <- c(7.667,9.5,6.467,10.033,9.767,29.133,15.933,8.1,8.6,12.3,5.867,13.667,12.933,11.933,27.2,11.567,10.9,12.567,9.033,12.6,13.133,17.067,14.333,15.2,9.1,9.167,8.4,11.4,18.467,15.633,10.4,10.767,12.7,7.667,9.867,36.167,20.4,33.8,15.767,20.1,10.533,17.7,62.667,21.133,40.133,9.2,19.467,8.867,20.333,14.367,10.167,28.4,11.367,10.867,22.1,24.8,13.3,10.967,12.333,28.867,21.1)

week <- c(1,1,2,3,3)

Methode <- c(1,4,3)

freq <- c(c(5.9,5.9,8,10,10))

ID <-c(1,5,6,7,6)

week <- as.factor(week)
Methode <- as.factor(Methode)
ID <- as.factor(ID)


M1 <- lmer(log(tijd) ~ Methode + (1|freq) + (1|week) + (1|ID),data = data)
summary(M1)
anova(M1,type = "III",test = "F")

plot(M1)
plot(cooks.distance(M1))


summary(glht(M1,linfct = mcp(Methode = "Tukey")))

这是我的数据集的第一行:https://imgur.com/RYr9nNp 我目前正在写我的学士论文,如果你能帮助我,那就太好了。

提前致谢:)

解决方法

在您的 lmer 代码中,您依赖于 data 但您没有将 data$Methode 转换为因子,那么您的代码应该是:

data$week <- as.factor(data$week)
data$Methode <- as.factor(data$Methode)
data$ID <- as.factor(data$ID)

M1 <- lmer(log(tijd) ~ Methode + (1|freq) + (1|week) + (1|ID),data = data)

您在图片中显示的数据不包含与您的 lmer 代码相同的列名,因此您必须注意(例如:frequentie 和 freq)