将数值变量指定为lme4中的因子

时间:2018-03-13 00:56:53

标签: r lme4

如果有问题的变量不是 lmer,有没有办法在false内指定对比度矩阵?作为示例,具有组的2×4混合模型的玩具数据,受试者之间的因子和受试者内因子的时间。我在时间水平上测试组间的分组差异,但这更多是一个技术问题,关于是否可以将数值变量指定为lmer内的因子(即,将它们保持为数字外的数字) lmer)。

lmer

请注意,set.seed(345) A0 <- rnorm(4,2,.5) B0 <- rnorm(4,2+3,.5) A1 <- rnorm(4,6,.5) B1 <- rnorm(4,6+2,.5) A2 <- rnorm(4,10,.5) B2 <- rnorm(4,10+1,.5) A3 <- rnorm(4,14,.5) B3 <- rnorm(4,14+0,.5) score <- c(A0,B0,A1,B1,A2,B2,A3,B3) id <- rep(1:8,times = 4, length = 32) time <- rep(0:3, each = 8, length = 32) group <- rep(c("A","B"), times =2, each = 4, length = 32) df <- data.frame(id = id, group = group, time = time, score = score) 因子是一个数字变量,已包含在time命令中的模型中。

factor()

这本身就可以正常使用。但是,当我使用相同的summary(lmer(score ~ group*factor(time) + (1|id), data = df)) 语法指定contrasts时:

factor(time)

我收到错误:

summary(lmer(score ~ group*factor(time) + (1|id), data = df, contrasts = list(factor(time) = contr.helmert(4), group = contr.helmert(2))))

...我假设是指定Error: unexpected '=' in "summary(lmer(score ~ group*factor(time) + (1|id), data = df, contrasts = list(factor(time) =" 命令中time变量的对比矩阵。

如果我没有在factor()来电中致电time一个因素......

contrasts =

它会返回一个结果,但会忽略该因子,并显示警告消息....

summary(lmer(score ~ group*factor(time) + (1|id), data = df, contrasts = list(time = contr.helmert(4), group = contr.helmert(2))))

我知道我在这里违反了1: In model.matrix.default(fixedform, fr, contrasts) : variable 'time' is absent, its contrast will be ignored 2: In model.matrix.default(fixedform, fr, contrasts) : variable 'time' is absent, its contrast will be ignored 3: In model.matrix.default(fixedform, fr, contrasts) : variable 'time' is absent, its contrast will be ignored 4: In model.matrix.default(fixedform, fr, contrasts) : variable 'time' is absent, its contrast will be ignored 5: In model.matrix.default(fixedform, fr, contrasts) : variable 'time' is absent, its contrast will be ignored 6: In model.matrix.default(fixedform, fr, contrasts) : variable 'time' is absent, its contrast will be ignored 7: In model.matrix.default(fixedform, fr, contrasts) : variable 'time' is absent, its contrast will be ignored 8: In model.matrix.default(fixedform, fr, contrasts) : variable 'time' is absent, its contrast will be ignored 9: In model.matrix.default(fixedform, fr, contrasts) : variable 'time' is absent, its contrast will be ignored 10: In model.matrix.default(fixedform, fr, contrasts) : variable 'time' is absent, its contrast will be ignored 的语法,但我试图证明我将喜欢实现的目标,同时承认我不知道如何这样做或者如果我想做的话甚至是可能的。

0 个答案:

没有答案