我正在使用nlme运行自启动的三参数逻辑模型,并希望阐明当模型中存在协变量时应如何选择起始值。
创建示例数据框:
sampledf <- tibble(
age = rep(c(0, 3, 6, 9, 12, 15, 18, 21), 4),
mass = c(1, 4, 8, 12, 16, 20, 22, 23,
1, 5, 8, 13, 17, 21, 24.5, 24.5,
1, 2.5, 6.5, 10, 14, 18.5, 20.5, 21,
1, 5, 8, 13, 17, 21, 24.5, 24.5),
treatment = c(rep(0:1, each=8, 2)),
year = c(rep(0:1, each=16))) %>%
slice(rep(1:n(), each = 3))
id = c("rae", "raphael", "reshmi", "rudy", "ruth", "roland", "remy", "roxy", "red", "randy", "raj", "roy")
sampledf <- sampledf %>%
arrange(age) %>%
mutate(id = rep(id, 8),
id = as.factor(id), year = as.factor(year), treatment=as.factor(treatment))
以图形方式显示S型曲线:
ggplot(sampledf, aes(age, mass, col=treatment, linetype=year)) +
geom_point() +
geom_smooth(method="gam", formula = y ~ s(x, k = 4))
因为该模型为每个参数取3个起始值{例如,Asym = c(23.0,26.1,24.5)},这是否意味着列表中的前两个起始值应为治疗组的估计值,而第三,应该将两个年度的估计值一起平均吗?或者,第三个值应该是“治疗= 0,年= 0”的估计值吗?此外,在模型摘要中,假设每个参数有3个固定效果估算值(例如Intercept.Asym,Xmid.Asym,Scal.Asym),如何确定截距?即使没有估计值代表“治疗= 0,年= 1”,“治疗= 0,年= 0”组是否是参考点?
model1 <- nlme(mass ~ SSlogis(age, Asym, xmid, scal),
fixed=list(Asym + xmid + scal ~ treatment + year),
random = Asym + xmid ~ 1 | id,
start=list(fixed=c(Asym=c(23.0, 26.1, 24.5),
xmid=c(9.33, 9.21, 9.1),
scal=c(3.63, 3.85, 3.7))),
data=sampledf)
summary(model1)
我如何确定要使用的起始值:
sampledf %>%
group_by(treatment) %>%
do(fit = nls(mass ~ SSlogis(age, Asym, xmid, scal),
data = .)) %>%
tidy(fit) %>%
select(treatment, term, estimate) %>%
spread(term, estimate)