首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有范畴协变量的非线性混合模型:按群求参数估计

具有范畴协变量的非线性混合模型:按群求参数估计
EN

Stack Overflow用户
提问于 2022-09-19 15:37:00
回答 1查看 29关注 0票数 0

在拟合具有交叉范畴协变量的非线性混合模型后,如何为每一组组合编写模型方程(带有参数估计)?

代码语言:javascript
复制
library(ggplot2)
library(tidyr)
library(dplyr)

data(CO2)

使用CO2数据集作为皮涅罗和贝茨2000年中的引用

代码语言:javascript
复制
ggplot(CO2, aes(x=conc, y=uptake, group=Plant))+
  geom_line()+
  facet_grid(Treatment ~ Type)

根据皮涅罗和贝茨8.2.2节中的模型,用带有偏移量的渐近回归模型拟合模型,允许AsymlrcTypeTreatment的变化而变化(但要求c0是常数)。

代码语言:javascript
复制
library(nlme)
fm4CO2.nlme <- nlme(uptake ~ SSasympOff(conc, Asym, lrc, c0), data=CO2, 
                    fixed= list(Asym + lrc ~ Type * Treatment, c0 ~ 1),
                    random = Asym + lrc ~ 1,
                    start = c(32.412, 0, 0, 0, -4.5603,0, 0, 0, 49.344))

summary(fm4CO2.nlme)

Nonlinear mixed-effects model fit by maximum likelihood
  Model: uptake ~ SSasympOff(conc, Asym, lrc, c0) 
  Data: CO2 
      AIC      BIC   logLik
  388.418 420.0186 -181.209

Random effects:
 Formula: list(Asym ~ 1, lrc ~ 1)
 Level: Plant
 Structure: General positive-definite, Log-Cholesky parametrization
                 StdDev     Corr  
Asym.(Intercept) 2.34968017 As.(I)
lrc.(Intercept)  0.07960176 -0.92 
Residual         1.79195963       

Fixed effects:  list(Asym + lrc ~ Type * Treatment, c0 ~ 1) 
                                          Value Std.Error DF   t-value p-value
Asym.(Intercept)                       41.81755  1.562449 64  26.76410  0.0000
Asym.TypeMississippi                  -10.53047  2.208351 64  -4.76848  0.0000
Asym.Treatmentchilled                  -2.96942  2.213205 64  -1.34169  0.1844
Asym.TypeMississippi:Treatmentchilled -10.89926  3.112279 64  -3.50202  0.0008
lrc.(Intercept)                        -4.55726  0.096292 64 -47.32762  0.0000
lrc.TypeMississippi                    -0.10411  0.121685 64  -0.85557  0.3954
lrc.Treatmentchilled                   -0.17124  0.111962 64  -1.52947  0.1311
lrc.TypeMississippi:Treatmentchilled    0.74124  0.221716 64   3.34322  0.0014
c0                                     50.50804  4.364848 64  11.57155  0.000

(输出截断)

我知道如何用条件预测值(使用植物信息“植物”)和边际预测值(忽略植物信息;“固定”)绘制建模数据。

代码语言:javascript
复制
plot(augPred(fm4CO2.nlme, level=0:1))

我知道如何在数据框架中添加边际预测值(忽略植物随机效应的影响)。

代码语言:javascript
复制
CO2$predict=predict(fm4CO2.nlme, CO2 , level=0)

对于每一个Type * Treatment 组合,是否有一种简单的方法来获得四个模型方程的参数?

EN

回答 1

Stack Overflow用户

发布于 2022-09-19 15:37:00

是!感谢这个总是有用的emmeans包,这是非常简单的!对于每个参数,在~与原始模型的fixed列表匹配之后,确保模型方程匹配。

代码语言:javascript
复制
library(emmeans)
emmeans(fm4CO2.nlme,  ~ Type * Treatment, param="Asym")

lower.CL upper.CL魁北克非冰镇41.8 1.48 64 38.9 44.8密西西比州非冰鲜31.3 1.48 28.3 34.2魁北克冰镇38.8 1.49 64 35.9 41.8密西西比州冷冻17.4 1.44 64 14.5 20.3置信水平: 0.95

代码语言:javascript
复制
 emmeans(fm4CO2.nlme,  ~ Type * Treatment, param="lrc")

lower.CL upper.CL魁北克省非冰镇-4.56 0.0910 64 -4.74 -4.38密西西比非冰镇-4.66 0.1015 64 -4.86 -4.46魁北克-4.73 64 -4.91 -4.55密西西比州冰镇-4.09 0.1715 64 -4.43 -3.75置信度: 0.95

代码语言:javascript
复制
emmeans(fm4CO2.nlme,  ~ 1, param="c0")

1平均SE df lower.CL upper.CL总体使用50.5 4.12 64 42.3 58.7置信度: 0.95

在一个数据框架中收集这些值:

代码语言:javascript
复制
Asym_vals <- emmeans(fm4CO2.nlme,  ~ Type * Treatment, param="Asym") %>%
  as.data.frame()%>%
  rename_with(.fn=~paste0(., ".Asym"), .cols=emmean:upper.CL)

lrc_vals <- emmeans(fm4CO2.nlme,  ~ Type * Treatment, param="lrc") %>%
  as.data.frame()%>%
  rename_with(.fn=~paste0(., ".lrc"), .cols=emmean:upper.CL)

c0_vals <- emmeans(fm4CO2.nlme,  ~ 1, param="c0") %>%
  as.data.frame()%>%
  rename_with(.fn=~paste0(., ".c0"), .cols=emmean:upper.CL)


modeleqns <- Asym_vals %>% 
  left_join(lrc_vals, by=c("Type", "Treatment"), suffix=c(".Asym", ".lrc"))%>%
  merge(c0_vals, by=NULL)%>%
  select(Type, Treatment, starts_with("emmean."))
modeleqns

Type Treatment emmean.Asym emmean.lrc emmean.c0 1 Quebec nonchilled 41.81755 -4.557257 50.50804 2 Mississippi nonchilled 31.28708 -4.661367 50.50804 3 Quebec chilled 38.84812 -4.728499 50.50804 4 Mississippi chilled 17.41839 -4.091365 50.50804

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73775946

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档