You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用emmeans函数对GLM回归结果进行逆变换?

使用emmeans获取泊松GLM的响应尺度估计值(逆变换/指数化)

1. 安装并加载emmeans包

如果未安装过emmeans,先执行安装命令:

install.packages("emmeans")

加载包:

library(emmeans)

2. 获取各变量的响应尺度估计值

泊松GLM采用log链接函数,type = "response"参数会自动对模型的对数尺度估计值做指数化(逆变换),得到原始响应尺度(即预期的Subject Total计数)结果。

针对分类变量(Quarter、int2)

直接指定变量即可,emmeans会计算每个水平的预期计数:

# 获取Quarter各水平的响应尺度估计值
emmeans(fit1a, ~ Quarter, type = "response")

# 获取int2各水平的响应尺度估计值
emmeans(fit1a, ~ int2, type = "response")

针对连续变量(time_since_intervention2)

连续变量需指定具体时间点计算估计值(默认用变量均值),可通过at参数自定义感兴趣的时间点:

# 自定义时间点(示例:0、5、10),计算对应预期计数
emmeans(fit1a, ~ time_since_intervention2, type = "response", 
        at = list(time_since_intervention2 = c(0, 5, 10)))

3. 进阶:查看多变量组合效应

若需将其他协变量调整至均值水平,同时查看多变量组合的预期计数,可使用cov.reduce = mean:

emmeans(fit1a, ~ Quarter + int2 + time_since_intervention2, 
        type = "response", cov.reduce = mean,
        at = list(time_since_intervention2 = 0)) # 指定干预后时间为0的场景

结果解读

输出中的emmean列是指数化后的响应尺度估计值(即预期的Subject Total),SE为标准误,lower.CL和upper.CL是置信区间,全部基于原始计数尺度。

内容的提问来源于stack exchange,提问作者j.rahilly

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 22:20:31