使用Rnlme软件包的非线性混合效应模型

时间:2018-10-01 16:03:18

标签: r lme4 mixed-models nlme longitudinal

我有一个面板纵向数据集。我知道一些变量应该与我的建模目标线性相关,从本质上讲,我希望仅对每个组使用随机截距作为随机效果。但是,我的问题是在nlme中很难同时包含线性和非线性项。

以下是示例数据:

library(nlme)
library(data.table)
library(lattice)

temp<- data.table(Group = rep("A",10),
              Age = c(1:10),
              Value = c(1/(1:10) + rnorm(10, mean = 0, sd = 0.05)) +
                seq(1, by = 0.4, length.out = 10),
              Var1 = seq(1, by = 0.4, length.out = 10)
              )

temp2<-data.table(Group = rep("B",10),
              Age = c(1:10),
              Value = c(1/(1:10) + rnorm(10, mean = 0, sd = 0.1)) +
                seq(1, by = -1, length.out = 10),
              Var1 = seq(1, by = -1, length.out = 10)
              )

temp3 <- rbindlist(list(temp, temp2))

xyplot(data = temp3, Value ~ Age| Group, type="l")

gdata <- groupedData(Value ~ Age | Group, data = temp3)

如果是线性混合效果模型,则直观地知道:

lme(data=gdata, Value ~ Age_function + Var1, random = ~1|Group)

但是我想使用SSlogis在那儿有一个非线性的参数化老化曲线。这是我在R中尝试过的方法:

initVals <- getInitial(Value ~ SSlogis(Age, Asym, xmid, scal), data = gdata)

nm1 <- nlme(Value ~ SSlogis(Age, Asym, xmid, scal),
             data = gdata,
             fixed = Asym + xmid + scal ~ Var1,
             random = Asym + xmid + scal ~ 1|Group,
             start = initVals)

显然它给了我错误:

Error in nlme.formula(Value ~ SSlogis(Age, Asym, xmid, scal), data = gdata,  : 
  starting values for the 'fixed' component are not the correct length

我对如何在nlme中指定固定和随机效果感到非常困惑。任何帮助表示赞赏。

0 个答案:

没有答案