Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 31, 2025

This PR adds interpretability guidance to GLM reports to help users understand how to transform coefficients for easier interpretation. The feature addresses the need for explainability text that assists users in making GLM results more interpretable.

What this PR does

Adds family-specific explainability guidance to the report_info section of GLM reports:

  • Binomial models: "For easier interpretation, the odds ratio can be calculated by taking the exponent of the coefficient (e.g., exp(beta))"
  • Poisson models: "For easier interpretation, the rate ratio can be calculated by taking the exponent of the coefficient (e.g., exp(beta))"
  • Other GLM families: "For easier interpretation, transformed coefficients can be calculated using the appropriate link function inverse (e.g., exp(beta) for log-link models)"

Example

Before (no explainability guidance):

library(report)
model <- glm(vs ~ disp, data = mtcars, family = binomial())
report(model)
#> ...95% Confidence Intervals (CIs) and p-values were computed using a 
#> Wald z-distribution approximation.

After (with explainability guidance):

library(report)
model <- glm(vs ~ disp, data = mtcars, family = binomial())
report(model)
#> ...95% Confidence Intervals (CIs) and p-values were computed using a 
#> Wald z-distribution approximation. For easier interpretation, the odds 
#> ratio can be calculated by taking the exponent of the coefficient 
#> (e.g., exp(beta)).

# Practical application:
coef(model)[2]  # -0.0216
exp(coef(model)[2])  # 0.9786 (odds ratio)

Implementation details

  • Created a dedicated report_info.glm() function that extends the existing report_info.lm() functionality
  • Uses insight::model_info() to detect GLM family and add appropriate guidance
  • Preserves all existing functionality for linear models (no changes to lm behavior)
  • Minimal change approach - only adds text, doesn't modify existing logic

Validation

  • Tested across multiple GLM families (binomial, poisson, gamma, inverse gaussian)
  • Linear models remain unchanged (no explainability text added)
  • R CMD check passes with no new errors
  • All existing tests continue to pass

Fixes #484.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits August 31, 2025 04:14
…terpretation

Co-authored-by: rempsyc <13123390+rempsyc@users.noreply.github.com>
Co-authored-by: rempsyc <13123390+rempsyc@users.noreply.github.com>
Co-authored-by: rempsyc <13123390+rempsyc@users.noreply.github.com>
Copilot AI changed the title [WIP] Adding explainability to summary for glm Add explainability guidance to GLM summary reports for coefficient interpretation Aug 31, 2025
Copilot AI requested a review from rempsyc August 31, 2025 04:17
Copilot finished work on behalf of rempsyc August 31, 2025 04:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding explainability to summary for glm

2 participants