r - 在 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 回归时,我将这张表作为结果。
我使用包gee
和geepack
R 来运行相同的分析,我得到了这些结果:
#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 表(不是结果,因为我使用了原始数据集的子集),但我不知道如何实现所有这些结果。
解决方案
一点点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
推荐阅读
- javascript - 如何检查 JSON.parse() 的输入在 ejs 中是否有效
- python - 如何使用 Pydantic 验证复杂的嵌套数据结构?
- python - asyncio loop.run_until_complete 在使用 loop.run_in_executor 从 asyncio.gather 返回所有结果之前完成
- xml - 使用 awk 编辑特定标签下的值
- django - 无法将关键字“电话”解析为字段 django
- c++ - 将 HEXA 64 位数字转换为 int
- react-native - React Native run-android on Apple M1 芯片抛出错误,“无法为脚本打开 dsl 通用类缓存”
- javascript - 单击按钮时数字不更新。控制台还给出了“游戏”未再次定义的错误。任何帮助表示赞赏
- c# - 如何找到正确的路径以统一保存数据
- rust - 两个可变引用如何同时存在?