0

我正在尝试通过对不同治疗组中的受试者的重复测量来分析一些数据。这是我的数据的一个子集,其中包含在第 1、3 和 21 天进行的观察(完整的数据集在第 3 和 21 天之间有额外的观察)。

mydata <- data.frame(
  Subject  = c(13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 29, 30, 31, 32, 33, 
           34, 35, 36, 37, 38, 39, 40, 62, 63, 64, 65, 13, 14, 15, 16, 17, 18, 
           19, 20, 21, 22, 23, 24, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 
           40, 62, 63, 64, 65, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 
           29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 62, 63, 64, 65), 
  Day       = as.numeric(c(rep(c("1", "3", "21"), each=28))), 
  Treatment = c(rep(c("B", "A", "C", "B", "C", "A", "A", "B", "A", "C", "B", "C", 
                  "A", "A", "B", "A", "C", "B", "C", "A", "A"), each = 4)), 
  Obs       = c(6.472687, 7.017110, 6.200715, 6.613928, 6.829968, 7.387583, 7.367293, 
            8.018853, 7.527408, 6.746739, 7.296910, 6.983360, 6.816621, 6.571689, 
            5.911261, 6.954988, 7.624122, 7.669865, 7.676225, 7.263593, 7.704737, 
            7.328716, 7.295610, 5.964180, 6.880814, 6.926342, 6.926342, 7.562293, 
            6.677607, 7.023526, 6.441864, 7.020875, 7.478931, 7.495336, 7.427709, 
            7.633020, 7.382091, 7.359731, 7.285889, 7.496863, 6.632403, 6.171196, 
            6.306012, 7.253833, 7.594852, 6.915225, 7.220147, 7.298227, 7.573612, 
            7.366550, 7.560513, 7.289078, 7.287802, 7.155336, 7.394452, 7.465383, 
            6.976048, 7.222966, 6.584153, 7.013223, 7.569905, 7.459185, 7.504068, 
            7.801867, 7.598728, 7.475841, 7.511873, 7.518384, 6.618589, 5.854754, 
            6.125749, 6.962720, 7.540600, 7.379861, 7.344189, 7.362815, 7.805802, 
            7.764172, 7.789844, 7.616437, NA, NA, NA, NA))

我想使用线性混合模型(使用 nlme)分析我的数据:

mymodel <- lme(Obs ~ Treatment * Day, random = ~1 | Subject, correlation = corAR1(form = ~1 | Subject), data=mydata, na.action=na.omit)

由于我对实验最后一天的差异最感兴趣,我真的很喜欢第 21 天的中心,但 R 似乎使用最低值作为数值变量的参考水平。我可以将第 21 天设置为 0,但这会打乱时间序列,这对自相关结构很重要,并且将 Day 更改为一个因子只会给我一条错误消息:

MEEM(object, conLin, control$niterEM) 中的错误:第 0 级反解中的奇点,块 1

那么,如何以第 21 天作为 Day 的参考水平来测试 Treatment 的效果呢?

4

1 回答 1

0

尝试

mydata$Day = relevel(mydata$Day, ref="Day21")

在运行模型之前。(我认为在你的模型中Subject应该写而不是Sample),至少对于你的例子,因为没有Samplein mydata

编辑

原始示例已被编辑,但同样的方法应该仍然有效:

mydata$Day = factor(mydata$Day, levels=c(21, 3, 1))


mymodel <- lme(Obs ~ Treatment * Day, random = ~1 | Subject, correlation = 
                corAR1(form = ~1 | Subject), data=mydata, na.action=na.omit)
summary(mymodel)

这使:

Fixed effects: Obs ~ Treatment * Day 
Value Std.Error DF  t-value p-value
(Intercept)      7.635586 0.1159703 46 65.84086  0.0000
TreatmentB      -0.965811 0.1682325 25 -5.74093  0.0000
TreatmentC      -0.169050 0.1682325 25 -1.00486  0.3246
Day3            -0.208276 0.1133072 46 -1.83815  0.0725
Day1            -0.452858 0.1306224 46 -3.46693  0.0012
TreatmentB:Day3  0.229415 0.1636327 46  1.40201  0.1676
TreatmentC:Day3  0.060868 0.1636327 46  0.37198  0.7116
TreatmentB:Day1  0.352958 0.1932224 46  1.82669  0.0742
TreatmentC:Day1  0.334850 0.1932224 46  1.73298  0.0898
于 2014-03-14T20:00:01.533 回答