在nlme和lme4中安装相同的模型

Adr*_*ian 9 r lme4 mixed-models nlme

数据来自这里

library(nlme)
dat0 <- read.table("aids.dat2",head=T)
dat1 <- dat0[dat0$day<=90, ]   # use only first 90-day data
dat2 <- dat1[!apply(is.na(dat1),1,any),]  # remove missing data 

# Next, let's treat the data as longitudinal (or grouped) data 
aids.dat <- groupedData(lgcopy ~ day | patid, data=dat2)

# A NLME model fit, with random effects on all 4 parameters 
start <- c(10,0.5,6,0.005)  # starting value 

aids.dat$log10copy = log10(aids.dat$lgcopy)

nlme.fit <- nlme(log10copy ~ exp(p1-b1*day) + exp(p2-b2*day + 1),
                 fixed = list(p1 ~ 1, b1 ~ 1, p2 ~ 1, b2 ~ 1),
                 random = list(patid = pdDiag(list(p1 ~ 1, b1 ~ 1, p2 ~ 1, b2 ~ 1))),
                 data =aids.dat, start=c(start)) 
summary(nlme.fit)
Run Code Online (Sandbox Code Playgroud)

在这里,我nlmenlme包中使用非线性混合效果模型.该模型具有4种固定效果和4种随机效应.我在方差 - 协方差矩阵上指定了对角线结构,每个都patid形成一个组.

library(lme4)
deriv_mod <- deriv( ~ exp(p1 - b1*t) + exp(p2 - b2*t + 1), 
                    c("p1", "b1", "p2", "b2"), function(t, p1, b1, p2, b2){})
nlmer.fit <- nlmer(deriv_mod ~ list(p1 ~ 1, b1 ~ 1, p2 ~ 1, b2 ~ 1) + 
                     list(p1 ~ 1, b1 ~ 1, p2 ~ 1, b2 ~ 1), data = aids.dat, start = c(start))
Run Code Online (Sandbox Code Playgroud)

在这里,我想使用lme4包装适合相同的型号.从文档中看来,formulafor nlmer必须还有一个渐变组件,因此我deriv首先使用了该函数.但是,我不确定如何指定其余参数?该

deriv_mod ~ list(p1 ~ 1, b1 ~ 1, p2 ~ 1, b2 ~ 1) + 
                     list(p1 ~ 1, b1 ~ 1, p2 ~ 1, b2 ~ 1)
Run Code Online (Sandbox Code Playgroud)

是指定4个固定效果(在第一个列表对象中)和它们对应的4个随机效果(在第二个列表对象中).不过,我不太清楚如何指定对角线方差-协方差结构,确保观察被分组patid,就像我指定的random = list(patid = pdDiag(list(p1 ~ 1, b1 ~ 1, p2 ~ 1, b2 ~ 1)))nlme.

Ale*_*x W 3

指定固定效应FE1 ... FE4和独立随机效应的标准方法RE1 ... RE4如下所示

mod_fit <- lme4::nlmer(Y ~ FE1 + FE2 + FE3 + FE4 + 
  (1|RE1) + (1|RE2) + (1|RE3) + (1|RE4), data= dat)
Run Code Online (Sandbox Code Playgroud)

nlme包的语法与 package.json 略有不同lme4

mod_fit <- nlme::nlme(Y ~ FE1 + FE2 + FE3 + FE4 + 
      (1|RE1) + (1|RE2) + (1|RE3) + (1|RE4), 
  fixed= FE1 + FE2 + FE3 + FE4 ~ Y,
  groups= 1 ~ RE1 + RE2 + RE3 + RE4,
  data= dat)
Run Code Online (Sandbox Code Playgroud)

也就是说,我不确定我完全理解你问题的细微差别,所以你的情况可能意味着这需要稍微修改。如果您提供意见,我很乐意根据需要修改我的答案