首页 > 解决方案 > 在 R 中重新创建 spss GEE 回归表

问题描述

我有下面的(示例)数据集:

round<-c( 0.125150,  0.045800, -0.955299, -0.232007,  0.120880, -0.041525,  0.290473, -0.648752,  0.113264, -0.403685)
    square<-c(-0.634753,  0.000492, -0.178591, -0.202462, -0.592054, -0.583173, -0.632375, -0.176673, -0.680557, -0.062127)
    ideo<-c(0,1,0,1,0,1,0,0,1,1)
    ex<-data.frame(round,square,ideo)

当我在 SPSS 中运行 GEE 回归时,我将这张表作为结果。 在此处输入图像描述

我使用包geegeepackR 来运行相同的分析,我得到了这些结果:

#gee
summary(gee(ideo ~ square + round,data = ex, id = ideo,
    corstr = "independence"))
Coefficients:
            Estimate Naive S.E. Naive z Robust S.E. Robust z
(Intercept)   1.0541     0.4099   2.572      0.1328    7.937
square        1.1811     0.8321   1.419      0.4095    2.884
round         0.7072     0.5670   1.247      0.1593    4.439

#geepack
summary(geeglm(ideo ~ square + round,data = ex, id = ideo,
            corstr = "independence"))
Coefficients:
            Estimate Std.err  Wald Pr(>|W|)    
(Intercept)    1.054   0.133 63.00  2.1e-15 ***
square         1.181   0.410  8.32   0.0039 ** 
round          0.707   0.159 19.70  9.0e-06 ***
---

我想准确地重新创建 SPSS 表(不是结果,因为我使用了原始数据集的子集),但我不知道如何实现所有这些结果。

标签: r

解决方案


一点点tidyverse魔法就可以得到相同的结果——或多或少。

coef(summary(geeglm()))从必要的列中获取信息并计算:

library("tidyverse")
library("geepack")

coef(summary(geeglm(ideo ~ square + round,data = ex, id = ideo,
           corstr = "independence"))) %>% 
mutate(lowerWald = Estimate-1.96*Std.err, # Lower Wald CI
       upperWald=Estimate+1.96*Std.err,   # Upper Wald CI
       df=1, 
       ExpBeta = exp(Estimate)) %>%       # Transformed estimate
mutate(lWald=exp(lowerWald),              # Upper transformed
       uWald=exp(upperWald))              # Lower transformed

这会产生以下内容(使用您提供的数据)。可以修改列的顺序和名称以满足您的需要

  Estimate Std.err   Wald  Pr(>|W|) lowerWald upperWald df ExpBeta lWald uWald
1   1.0541  0.1328 62.997 2.109e-15    0.7938     1.314  1   2.869 2.212 3.723
2   1.1811  0.4095  8.318 3.925e-03    0.3784     1.984  1   3.258 1.460 7.270
3   0.7072  0.1593 19.704 9.042e-06    0.3949     1.019  1   2.028 1.484 2.772

推荐阅读