微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

可视化二元逻辑随机斜率模型

如何解决可视化二元逻辑随机斜率模型

我使用以下数据运行了一个二元逻辑随机斜率模型:

 serve country conscription    sex education income         religion immigrant proud trusting outgoing         age
1    Yes     ALG            1   male         3      5   Very important         0     1        2        2 -15.7403361
2    Yes     ALG            1 female         3      6 Rather important         0     2        4        2 -12.7403361
3    Yes     ALG            1 female         3      6   Very important         0     1        3        3 -10.7403361
4    Yes     ALG            1 female         3      5   Very important         0     1        3        4  -8.7403361
5    Yes     ALG            1 female         2      7   Very important         0     1        4        4  -1.7403361
6    Yes     ALG            1   male         4      5   Very important         0     1        3        4  -0.7403361
7    Yes     ALG            1   male         3      7   Very important         0     1        2        2   4.2596639
8    Yes     ALG            1 female         2      2 Rather important         0     1        3        4   7.2596639
9    Yes     ALG            1   male         1      5 Rather important         0     1        3        2  22.2596639
11   Yes     ALG            1 female         4      5   Very important         0     1        3        1 -13.7403361

模型看起来像这样:

Generalized linear mixed model fit by maximum likelihood (Adaptive Gauss-hermite Quadrature,nAGQ = 0) ['glmerMod']
 Family: binomial  ( logit )
Formula: serve ~ age + sex + income + religion + proud + trusting + outgoing +      conscription + (1 + proud | country)
   Data: WVS.2
Control: glmerControl(optimizer = "bobyqa")

     AIC      BIC   logLik deviance df.resid 
 26133.6  26359.2 -13038.8  26077.6    23283 

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-4.5789 -0.9022  0.4386  0.6850  3.5584 

Random effects:
 Groups  Name        Variance Std.Dev. Corr             
 country (Intercept) 0.70584  0.8401                    
         proud2      0.05847  0.2418   -0.31            
         proud3      0.18141  0.4259   -0.37  0.79      
         proud4      0.75998  0.8718    0.14  0.58  0.81
Number of obs: 23311,groups:  country,20

Fixed effects:
                          Estimate Std. Error z value Pr(>|z|)    
(Intercept)               0.139479   0.248397   0.562  0.57444    
age                      -0.006126   0.001319  -4.645 3.40e-06 ***
sexmale                   0.652698   0.030950  21.089  < 2e-16 ***
income                   -0.006549   0.007549  -0.867  0.38569    
religionRather important  0.146834   0.053087   2.766  0.00568 ** 
religionVery important    0.299748   0.051477   5.823 5.78e-09 ***
proud2                   -0.178368   0.066784  -2.671  0.00757 ** 
proud3                   -0.340180   0.117835  -2.887  0.00389 ** 
proud4                   -0.346386   0.245852  -1.409  0.15886    
trusting2                 0.105620   0.057906   1.824  0.06815 .  
trusting3                 0.173238   0.058896   2.941  0.00327 ** 
trusting4                 0.338042   0.057763   5.852 4.85e-09 ***
trusting5                 0.281655   0.063626   4.427 9.57e-06 ***
outgoing2                -0.170605   0.065585  -2.601  0.00929 ** 
outgoing3                -0.110182   0.065934  -1.671  0.09470 .  
outgoing4                 0.117553   0.063268   1.858  0.06317 .  
outgoing5                 0.218266   0.067077   3.254  0.00114 ** 
conscription1             0.023910   0.338071   0.071  0.94362    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

我希望能够将其可视化,使其看起来像此页面上的第一个图: https://kzee.github.io/LogisticSpaghetti_Demo.html

我可以像第一步一样创建新的数据框

df1 <- dplyr::select(WVS.2,country,proud,serve)
df1$age <- 0
df1$sex <- 0
df1$income <- 0
df1$religion <- 0
df1$trusting <- 0
df1$outgoing <- 0
df1$conscription <- 0

但是接下来的几个步骤不起作用。我无法在指南中弄清楚不同的变量是什么,所以这给我带来了问题。此外,我相信示例中的预测变量是整数(“女性早晨的愤怒”),而我的预测变量是 1-4 的名义变量。因此,我不确定如何更改代码。任何帮助,将不胜感激。谢谢。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。