如何在NLME中选择协变量的起始值

时间:2017-11-01 15:07:44

标签: r nonlinear-functions nlme

library(nlme)
Loblolly$age2 <- as.factor(ifelse(Loblolly$age < 12.5, 0, 1))

这里我定义了一个我感兴趣的二进制协变量。

model <- nlme(height ~ (R0) + 1,
               data = Loblolly,
               fixed = list(R0 ~ 1 + (age2)),
               random = list(Seed = pdDiag(list(R0 ~ 1))),
               start = list(fixed = c(R0 = -8.5, age2 = 1)))

运行它会给我错误,

Error in nlme.formula(height ~ (R0) + 1, data = Loblolly, fixed = list(R0 ~  : 
  step halving factor reduced below minimum in PNLS step

更改起始值后,它可以正常工作。

model2 <- nlme(height ~ (R0) + 1,
               data = Loblolly,
               fixed = list(R0 ~ 1 + (age2)),
               random = list(Seed = pdDiag(list(R0 ~ 1))),
               start = list(fixed = c(R0 = 0, age2 = 30)), verbose=TRUE)

选择age2的起始值有哪些方法?我考虑使用nls2拟合非线性最小二乘模型,但这也需要指定一组起始值。

我想也许我可以绘制数据height ~ age2,但是因为age2是二进制的...我不知道如何去做。

1 个答案:

答案 0 :(得分:1)

请尝试lm,如下所示:

fm.lm <- lm(height ~ age2, Loblollly) # modified Loblolly as per question
st <- coef(fm.lm)
names(st)[1] <- "R0"
nlme(height ~ (R0) + 1, data = Loblolly,
               fixed = list(R0 ~ 1 + (age2)),
               random = list(Seed = pdDiag(list(R0 ~ 1))),
               start = list(fixed = st))

,并提供:

Nonlinear mixed-effects model fit by maximum likelihood
  Model: height ~ (R0) + 1 
  Data: Loblolly 
  Log-likelihood: -305.1093
  Fixed: list(R0 ~ 1 + (age2)) 
R0.(Intercept)       R0.age21 
      12.96167       36.80548 

Random effects:
 Formula: R0 ~ 1 | Seed
        R0.(Intercept) Residual
StdDev:   0.0002791602 9.145988

Number of Observations: 84
Number of Groups: 14