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是二进制的,所以我不确定该怎么做。

最佳答案

像这样尝试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

关于r - 如何在NLME中选择协变量的起始值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47057907/

10-12 18:47