如何为有序广义估计方程的geese对象计算置信区间?
为
geese对象(有序GEE模型)计算置信区间的方法 ordgee()输出的geese对象无法直接用broom包的tidy()或conf.int()函数处理,以下是两种可行的解决方案:
方法1:手动提取参数计算置信区间
利用geese对象内置的系数和方差-协方差矩阵,通过大样本正态近似计算置信区间:
# 提取模型系数 coefs <- coef(model1) # 从方差-协方差矩阵中提取标准误 ses <- sqrt(diag(model1$vbeta)) # 计算95%置信区间(z临界值取1.96) ci_lower <- coefs - 1.96 * ses ci_upper <- coefs + 1.96 * ses # 整理为结构化数据框 result_df <- data.frame( term = names(coefs), estimate = coefs, std.error = ses, conf.low = ci_lower, conf.high = ci_upper ) print(result_df)
如果需要其他置信水平,替换对应的z临界值即可(如99%置信水平用2.576)。
方法2:自定义函数适配broom风格
如果想要更贴近tidy()的输出格式,可编写自定义函数,同时输出p值:
tidy_geese <- function(model, conf.level = 0.95) { z_crit <- qnorm((1 + conf.level)/2) coefs <- coef(model) ses <- sqrt(diag(model$vbeta)) ci_lower <- coefs - z_crit * ses ci_upper <- coefs + z_crit * ses data.frame( term = names(coefs), estimate = coefs, std.error = ses, conf.low = ci_lower, conf.high = ci_upper, p.value = 2 * pnorm(abs(coefs/ses), lower.tail = FALSE) ) } # 调用函数获取结果 tidy_result <- tidy_geese(model1) print(tidy_result)
注意事项
model1$vbeta是geese对象的系数方差-协方差矩阵,取对角线元素开平方即为标准误,这是GEE模型标准误的官方计算方式。- 有序GEE模型会包含截距项(阈值参数)的结果,若仅需自变量的置信区间,可通过筛选
term列提取对应行。
内容的提问来源于stack exchange,提问作者Erin Riordan
相关产品推荐
相关产品推荐

