如何在R中绘制交叉分类逻辑多层次模型的随机效应?

时间:2014-01-19 14:05:56

标签: r data-visualization

我在R中估计了一个交叉分类的后勤混合模型,有两种类型的二级主题:34个选举日期和408个城市。 1级观察是选民投票率(从属)和2个独立变量的聚合比例。然后在选举日期和一些控制方面有一些特点。我估计了主要自变量与选举类型(选举日期的宏观特征)之间的跨层次互动。因此,效果在选举日期随机估计。现在我想绘制随机效果:绘图中的34条回归线,有4种不同颜色(根据宏观层面:不同类型的选举)。

有谁知道如何在R中绘制这样的东西?

更新: 谢谢你的提示!我对R很新。我知道如何估计我的模型,但除此之外我还有很多需要学习的东西。

这是我的最终型号。 “gemnr”是市级。 “日期”是我所谈论的选举日期。 “Windchill”和“Rain”是对“Date”的随机效应,并与“Provincie”,“Gemeente”和“Europa”三种类型的选举互动。其余变量是控件。 因变量是选民的真实比例:cbind(opkomst,nnietgestemd),它代表投票数(opkomst)和非投票人数(nnietgestemd)。

# Model with controls and interactions.
model3b <- glmer (cbind(opkomst, nnietgestemd) ~
       (1|gemnr)+(1+Windchill+Rain|Date) + Windchill + Windspeed + Rain + SP + lag_popkomst + Provincie + Gemeente + Europa + NB + OL + loginw 
       + Provincie:Windchill + Gemeente:Windchill + Europa:Windchill + Provincie:Rain + Gemeente:Rain + Europa:Rain, family=binomial(link=logit))

这就是结果:

Generalized linear mixed model fit by maximum likelihood ['glmerMod']
 Family: binomial ( logit )
Formula: cbind(opkomst, nnietgestemd) ~ (1 | gemnr) + (1 + Windchill +      Rain | Date) + Windchill + Windspeed + Rain + SP + lag_popkomst +      Provincie + Gemeente + Europa + NB + OL + loginw + Provincie:Windchill +      Gemeente:Windchill + Europa:Windchill + Provincie:Rain +      Gemeente:Rain + Europa:Rain 

      AIC       BIC    logLik  deviance 
1452503.3 1452691.4 -726226.6 1452453.3 

Random effects:
 Groups Name        Variance  Std.Dev. Corr       
 gemnr  (Intercept) 0.0146186 0.12091             
 Date   (Intercept) 0.1902650 0.43619             
        Windchill   0.0009727 0.03119  -0.07      
        Rain        0.0103655 0.10181   0.59 -0.10
Number of obs: 13735, groups: gemnr, 408; Date, 34

Fixed effects:
                       Estimate  Std. Error z value             Pr(>|z|)    
(Intercept)         -0.23067667  0.12124970    -1.9             0.057107 .  
Windchill           -0.00768949  0.00834125    -0.9             0.356600    
Windspeed            0.01040831  0.00017884    58.2 < 0.0000000000000002 ***
Rain                -0.00157012  0.02908864    -0.1             0.956953    
SP                   0.00045626  0.00001432    31.9 < 0.0000000000000002 ***
lag_popkomst         2.10911785  0.00386440   545.8 < 0.0000000000000002 ***
Provincie           -1.09414033  0.25162607    -4.3     0.00001372100383 ***
Gemeente            -0.60849053  0.18353633    -3.3             0.000915 ***
Europa              -1.21169484  0.21694178    -5.6     0.00000002332356 ***
NB                   0.07397575  0.01053297     7.0     0.00000000000217 ***
OL                   0.00288172  0.00821660     0.4             0.725799    
loginw              -0.10297623  0.00721768   -14.3 < 0.0000000000000002 ***
Windchill:Provincie  0.01743852  0.01769197     1.0             0.324293    
Windchill:Gemeente   0.01010439  0.01292002     0.8             0.434172    
Windchill:Europa     0.01664707  0.01522839     1.1             0.274323    
Rain:Provincie      -0.13692131  0.05956872    -2.3             0.021531 *  
Rain:Gemeente       -0.03330741  0.04340056    -0.8             0.442819    
Rain:Europa         -0.04864840  0.05142619    -0.9             0.344156    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

0 个答案:

没有答案