我正在尝试使用nlme软件包在R中使用重复测量(MMRM)模型拟合混合模型。
数据结构如下: 每个患者属于三组之一(grp)并被分配到治疗组(trt)。 在6次就诊(访视)期间测量患者结果(y)。
我想在不同的访问中使用具有异构方差的复合对称模型(如SAS的PROC MIXED的CSH类型,https://support.sas.com/documentation/cdl/en/statug/63347/HTML/default/viewer.htm#statug_mixed_sect020.htm)。
为此,我使用lme中的相关参数将相关结构设置为CS(corCompSymm)和权重参数,因此方差是访问的函数。
我也尝试过访问corCompSymm本身的form参数。
我遇到的问题:无论我是否在 lme 的调用中设置权重参数,我都会得到相同的结果(换句话说,我似乎得到了CS模型而不是CSH模型。)
执行下面的代码,你会注意到模型参数估计的协方差矩阵的对角线是相同的,无论使用什么模型表明重量参数被忽略。
remove(list = objects())
library(nlme)
set.seed(55)
npatients = 200;
nvisits = 6;
#---
# Generate some data:
subject_table = data.frame(subject = sprintf("S%03d", 1:npatients),
trt = sample(x = c("P", "D"), replace = T, size = npatients),
grp = sample(x = c("A", "B", "C"), replace = T, size = npatients))
subject_table = merge(subject_table,
data.frame(visit.number = 1:6))
subject_table = transform(subject_table,
visit = sprintf("V%02d", visit.number),
y = rnorm(nrow(subject_table), mean = 0, sd = visit.number^2))
subject_table = transform(subject_table,
visit = factor(visit),
subject = factor(subject, ordered = T, levels = sort(unique(as.character(subject)))),
grp = factor(grp),
trt = factor(trt))
#---
# Fit MMRM model to data using nlme
cs_model = lme(y ~ trt*visit*grp, # fixed effects
random = ~1|subject, # random effects
data = subject_table, # data
correlation = corCompSymm(form=~1|subject)) # CS correlation matrix within patient
csh_model_v1 = lme(y ~ trt*visit*grp, # fixed effects
random = ~1|subject, # random effects
data = subject_table, # data
weights = varIdent(~1|visit), # different "weight" within each visit (I think)
correlation = corCompSymm(form=~1|subject)) # CS correlation matrix within patient
csh_model_v2 = lme(y ~ trt*visit*grp, # fixed effects
random = ~1|subject, # random effects
data = subject_table, # data
weights = varIdent(~visit|subject), # different "weight" within each visit (I think)
correlation = corCompSymm(form=~1|subject)) # CS correlation matrix within patient
csh_model_v3 = lme(y ~ trt*visit*grp, # fixed effects
random = ~1|subject, # random effects
data = subject_table, # data
correlation = corCompSymm(form=~visit|subject)) # CS correlation matrix within patient
diag(vcov(cs_model))
diag(vcov(csh_model_v1))
diag(vcov(csh_model_v2))
diag(vcov(csh_model_v3))
问题: 如何让nlme为不同的访问拟合不同的方差参数?
答案 0 :(得分:2)
在几个死胡同之后,似乎问题是确保在对varIdent的调用中设置了正确的参数。
正确的做法似乎是:
.html()
看起来一样,但请注意,传递给varIdent的参数被明确标识为" form"。如果这被解释为其他任何方式,我曾预料会发生崩溃,但我错了。