【问题标题】:predict() in lmer regression, but I need it only 2 categorieslmer回归中的predict(),但我只需要2个类别
【发布时间】:2014-03-25 12:18:59
【问题描述】:

我正在尝试估计一个多级模型。我的代码是:

fullModel2 <- lmer(pharmexp_2001 ~ gdp_1000_gm + health_exp_per_cap_1000_gm + life_exp +
                   labour_cost_1000_gm + (year_gm|lowerID), data=adat, REML=F)

导致以下模型:

Linear mixed model fit by maximum likelihood  ['lmerMod']
Formula: pharmexp_2001 ~ gdp_1000_gm + health_exp_per_cap_1000_gm + life_exp +      
         labour_cost_1000_gm + (year_gm | lowerID)
   Data: adat

     AIC      BIC   logLik deviance df.resid 
  1830.2   1859.9   -906.1   1812.2      191 

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-2.5360 -0.6853 -0.0842  0.4923  4.0051 

Random effects:
 Groups   Name        Variance Std.Dev. Corr 
 lowerID  (Intercept) 134.6851 11.6054       
          year_gm       0.4214  0.6492  -1.00
 Residual             487.5324 22.0801       
Number of obs: 200, groups: lowerID, 2

Fixed effects:
                            Estimate Std. Error t value
(Intercept)                -563.7924    75.4125  -7.476
gdp_1000_gm                  -0.9050     0.2051  -4.413
health_exp_per_cap_1000_gm   37.5394     6.3943   5.871
life_exp                      8.8571     0.9498   9.326
labour_cost_1000_gm          -1.3573     0.4684  -2.898

Correlation of Fixed Effects:
            (Intr) g_1000 h____1 lif_xp
gdp_1000_gm -0.068                     
hl____1000_  0.374 -0.254              
life_exp    -0.996  0.072 -0.393       
lbr_c_1000_ -0.133 -0.139 -0.802  0.142

我知道随机效应的相关性为-1是一个问题,但我有一个更大的问题。我必须绘制我的结果,但我只需要 2 行:当 lowerID=0lowerID=1 时。所以我想在 y 轴上绘制 pharmaexp_2001,在 x 轴上绘制 year,但我只需要 2 行(lowerID)。我知道我必须使用predict.merMod,但是如何绘制这些结果,只绘制这两行?目前我的情节有 21 行(因为我分析了 21 个国家的药品支出)。

【问题讨论】:

  • 能否解释一下随机效应部分的year_gm?

标签: r data-visualization lmer


【解决方案1】:

欢迎来到该网站,@Eszter Takács!

您只需要指定newdata 中的两个ID。这是一个基于R 中的sleepstudy 数据的示例。我假设您想在 y 轴上绘制 预测值。只需将代码替换为您的数据和变量,您将获得lowerID==0lowerID==1 的预测值。然后您可以使用您的代码为两个 ID 绘制两条线。

> (fm1 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy, REML=F))
Linear mixed model fit by maximum likelihood ['lmerMod']
Formula: Reaction ~ Days + (Days | Subject) 
   Data: sleepstudy 
      AIC       BIC    logLik  deviance 
1763.9393 1783.0971 -875.9697 1751.9393 
Random effects:
 Groups   Name        Std.Dev. Corr
 Subject  (Intercept) 23.781       
          Days         5.717   0.08
 Residual             25.592       
Number of obs: 180, groups: Subject, 18
Fixed Effects:
(Intercept)         Days  
     251.41        10.47  

> newdata = sleepstudy[sleepstudy$Subject==308 | sleepstudy$Subject==333,]
> str(p <- predict(fm1,newdata)) # new data, all RE
 Named num [1:20] 254 274 293 313 332 ...
 - attr(*, "names")= chr [1:20] "1" "2" "3" "4" ...

【讨论】:

    猜你喜欢
    • 2021-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-14
    • 1970-01-01
    • 1970-01-01
    • 2017-08-27
    • 1970-01-01
    相关资源
    最近更新 更多