nlme错误“组的无效公式”虽然指定了随机效果

时间:2011-12-29 03:51:49

标签: r syntax-error glm nonlinear-functions

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

我还在研究我的营养数据分析,现在已转向实际数据。这些数据来自人口调查,并采用重复测量设计,因为每位受访者都有两次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 ...

使用lme4包,我已成功使用线性混合效果模型(随机效果来自主体,IntakeDay是与BoxCoxXY相关的重复测量因子,是IntakeAmt)的变换:

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

我一直在尝试使用nlme包来查看拟合非线性模型来比较两者,但我无法使用我的语法。我最初的问题是我的数据似乎没有相关的SelfStart模型,因此我使用geeglm生成起始值(系数保存到名为Male.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)RespondentIDnlme的因子级别是否过多,或者(2)该方法只有在为{{1}提供启动参数时才有效这对我的数据似乎没有意义,因为这是我的主题标识符。

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

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()IntakeAmt转换为BoxCoxXY

SAS代码中的Male.Data$BoxCoxXY <- (Male.Data$IntakeAmt^Lambda.Value-1)/Lambda.Value语句为:

random

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

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

第二次更新:我意识到我没有删除与女性受试者相关的RespondentID级别,因为我在整个数据框架中分解了RespondentID,然后按性别划分为单独的数据框进行分析。在为RespondentID删除未使用的因子级别后,我重复了random u1 u2 ~ normal([0,0][&vu1,COV_U1U2,&vu2]) subject=RespondentID 分析,我得到了同样的错误。 nlme结果相同 - 这很有用。 :)

0 个答案:

没有答案