nlme 错误“组的公式无效”,尽管指定了随机效应

nlme error "Invalid formula for groups" although random effect specified

提问人:Michelle 提问时间:12/29/2011 最后编辑:Michelle 更新时间:12/30/2011 访问量:22923

问:

我已经对此进行了一些搜索,但是我发现的邮件列表帖子与未指定随机效果的人相关联,而我这样做了。我还拥有 Pinheiro 和 Bates 的 Mixed Effect Models in S and S-Plus 一书,但无法从书中解决我的问题。nlme

我仍在进行营养数据分析,现在已经转向真实数据。这些数据来自一项人口调查,并采用重复测量设计,因为每个受访者都有两次 24 小时的营养素摄入量召回。

我已经成功地将 lme4 模型拟合到我的数据中,现在我试图找出如果我使用非线性方法会发生什么。我的数据快照如下:

head(Male.Data)
   RespondentID Age SampleWeight  IntakeDay IntakeAmt AgeFactor BoxCoxXY
2        100020  12    0.4952835 Day1Intake 12145.852     9to13 15.61196
7        100419  14    0.3632839 Day1Intake  9591.953    14to18 15.01444
8        100459  11    0.4952835 Day1Intake  7838.713     9to13 14.51458
12       101138  15    1.3258785 Day1Intake 11113.266    14to18 15.38541
14       101214   6    2.1198688 Day1Intake  7150.133      4to8 14.29022
18       101389   5    2.1198688 Day1Intake  5091.528      4to8 13.47928

有关数据的摘要信息为:

str(Male.Data)
'data.frame':   4498 obs. of  7 variables:
$ RespondentID: Factor w/ 4487 levels "100013","100020",..: 2 7 8 12 14 18 19 20 21 22 ...
$ Age         : int  12 14 11 15 6 5 10 2 2 9 ...
$ SampleWeight: num  0.495 0.363 0.495 1.326 2.12 ...
$ IntakeDay   : Factor w/ 2 levels "Day1Intake","Day2Intake": 1 1 1 1 1 1 1 1 1 1 ...
$ IntakeAmt   : num  12146 9592 7839 11113 7150 ...
$ AgeFactor   : Factor w/ 4 levels "1to3","4to8",..: 3 4 3 4 2 2 3 1 1 3 ...
$ BoxCoxXY    : num  15.6 15 14.5 15.4 14.3 ...

使用该软件包,我成功地拟合了一个线性混合效应模型(随机效应来自受试者,是与 相关的重复测量因子,它是 的变换):lme4IntakeDayBoxCoxXYIntakeAmt

Male.lme1 <- lmer(BoxCoxXY ~ AgeFactor + IntakeDay + (1|RespondentID),
        data = Male.Data, 
        weights = SampleWeight)

我一直在尝试使用该包来拟合非线性模型来比较两者,但我无法让我的语法起作用。我最初的问题是,我的数据似乎没有相关的 SelfStart 模型,所以我过去常常生成起始值(保存到名为 的数据框中的系数)。但现在我只收到错误:nlmegeeglmMale.nlme.start

Error in getGroups.data.frame(dataMix, eval(parse(text = paste("~1", deparse(groups[[2]]),  : 
Invalid formula for groups

我无法弄清楚我做错了什么,我使用的语法是:nlme

Male.nlme1 <- nlme(BoxCoxXY ~ AgeFactor + IntakeDay + RespondentID , data = Male.Data, 
fixed = AgeFactor + IntakeDay ~ 1, 
random = RespondentID ~ 1,
start=c(Male.nlme.start[,"Estimate"]))

我已经尝试了在整体模型规范中包含和不包含的分析,这似乎没有影响。RespondentID

我之所以坚持使用非线性方法,是因为SAS中的原始分析使用了非线性方法。虽然从LME分析来看,我的残差等看起来还算不错,但我很好奇非线性方法会产生什么影响。

如果有帮助,最后一次分析尝试的结果包括:traceback()RespondentID

5: stop("Invalid formula for groups")
4: getGroups.data.frame(dataMix, eval(parse(text = paste("~1", deparse(groups[[2]]), 
   sep = "|"))))
3: getGroups(dataMix, eval(parse(text = paste("~1", deparse(groups[[2]]), 
   sep = "|"))))
2: nlme.formula(BoxCoxXY ~ AgeFactor + IntakeDay, data = Male.Data, 
   fixed = AgeFactor + IntakeDay ~ 1, random = RespondentID ~ 
       1, start = c(Male.nlme.start[, "Estimate"]))
1: nlme(BoxCoxXY ~ AgeFactor + IntakeDay, data = Male.Data, fixed = AgeFactor + 
   IntakeDay ~ 1, random = RespondentID ~ 1, start = c(Male.nlme.start[, 
   "Estimate"])) 

谁能建议我哪里出错了?我开始怀疑 (1) 是否有太多的因子水平可以工作,或者 (2) 该方法只有在我提供开始参数时才有效,这与我拥有的数据似乎毫无意义,因为这是我的主题标识符。RespondentIDnlmeRespondentID

更新:为了回答 Ben,SAS 模型是固定效应的一般对数似然函数:nlmixed

ll1 <- log(1/sqrt(2*pi*Scale))
ll2 <- as.data.frame(-(BoxCoxXY - Intercept + AgeFactor + IntakeDay + u2)^2)/(2*Scale)+(Lambda.Value-1)*log(IntakeAmt)
ll <- ll1 + ll2
model IntakeAmt ~ general(ll)

哪里:

Scale= 和 的色散值geeglm

Lambda.Value= 与先前输出的最大对数似然值相关联的 lambda 值,该值用于通过公式转换为boxcox()IntakeAmtBoxCoxXYMale.Data$BoxCoxXY <- (Male.Data$IntakeAmt^Lambda.Value-1)/Lambda.Value

SAS 代码中的语句为:random

random u1 u2 ~ normal([0,0][&vu1,COV_U1U2,&vu2]) subject=RespondentID

因此,模型中有两个误差项,它们都作为随机效应拟合。第二个方括号表示按行顺序列出的随机效应方差矩阵的下三角形,并使用 SAS 语法中的 SAS 宏变量指定。

我得到的模型摘要是正常的单行概述,它显示了协变量矩阵 (BX) 加上一个误差分量,所以这里没有多大帮助。

第二次更新:我意识到我没有删除与女性受试者相关的 RespondentID 级别,因为我在整个数据帧上分解了 RespondentID,然后按性别划分为单独的数据框进行分析。我在删除 RespondentID 的未使用因子水平后重复了分析,但出现相同的错误。结果是一样的 - 很高兴知道。:)nlmelmer

R 语法错误 GLM 非线性函数

评论

1赞 Ben Bolker 12/29/2011
你不想要吗......??random = ~1|respondentID
0赞 Michelle 12/29/2011
感谢您的提示,刚刚尝试过并出现错误Error in nlme.formula(BoxCoxXY ~ AgeFactor + IntakeDay + RespondentID, : random formula must be a formula or list of formulae
0赞 Ben Bolker 12/29/2011
哎呀,我太习惯了,我想你可能也是。你的公式实际上似乎对公式没有意义——你真的期望响应是变量的总和吗?请记住,它从 Wilkinson-Rogers 公式构造了一个隐式线性模型。您实际预期的非线性模型是什么?lmenlmelme
0赞 Michelle 12/29/2011
@Ben我已经更新了主要问题,提供了有关模型的更多信息。它是用 SAS 宏语法编写的,因此我很难理解其中的一些语法。
4赞 JerryTheForester 7/8/2019
多年后,这个问题已经有解决方案了吗?我在 nlme 中遇到了完全相同的问题......

答: 暂无答案