diff --git a/.gitignore b/.gitignore index 4c41f03e..aeffd7a2 100644 --- a/.gitignore +++ b/.gitignore @@ -53,3 +53,5 @@ revdep/data.sqlite revdep/ docs *.tar.gz +*.Rcheck/ +report_*.tar.gz diff --git a/DESCRIPTION b/DESCRIPTION index b634d97b..c9317338 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: report Type: Package Title: Automated Reporting of Results and Statistical Models -Version: 0.6.1.2 +Version: 0.6.1.3 Authors@R: c(person(given = "Dominique", family = "Makowski", diff --git a/NEWS.md b/NEWS.md index 82cb0f28..869cc922 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # report 0.6.x +New features + +* `report.glm()`: added explainability guidance for interpreting GLM coefficients (odds ratios for binomial models, rate ratios for Poisson models) to help users understand how to transform coefficients for easier interpretation (#484) + Bug fixes * Enhanced copilot environment setup with complete reprex dependency management (pandoc, knitr, rmarkdown, clipr) to prevent "reprex appears to crash R" errors diff --git a/R/report.glm.R b/R/report.glm.R index a74a0b94..0afb6f4c 100644 --- a/R/report.glm.R +++ b/R/report.glm.R @@ -24,7 +24,37 @@ report_model.glm <- report_model.lm report_performance.glm <- report_performance.lm #' @export -report_info.glm <- report_info.lm +report_info.glm <- function(x, + effectsize = NULL, + include_effectsize = FALSE, + parameters = NULL, + ...) { + # Get the standard info from the lm method + info_text <- report_info.lm(x, effectsize = effectsize, include_effectsize = include_effectsize, parameters = parameters, ...) + + # Add GLM-specific explainability guidance + model_info <- insight::model_info(x) + explainability_text <- "" + + if (model_info$is_binomial) { + explainability_text <- " For easier interpretation, the odds ratio can be calculated by taking the exponent of the coefficient (e.g., exp(beta))." + } else if (model_info$is_poisson) { + explainability_text <- " For easier interpretation, the rate ratio can be calculated by taking the exponent of the coefficient (e.g., exp(beta))." + } else if (!model_info$is_linear) { + explainability_text <- " For easier interpretation, transformed coefficients can be calculated using the appropriate link function inverse (e.g., exp(beta) for log-link models)." + } + + # Combine the existing info text with the new explainability text + combined_text <- paste0(as.character(info_text), explainability_text) + + # Preserve the summary attribute from the original info_text + summary_text <- summary(info_text) + if (!is.null(explainability_text) && nzchar(explainability_text)) { + summary_text <- paste0(as.character(summary_text), explainability_text) + } + + as.report_info(combined_text, summary = summary_text) +} #' @export report_text.glm <- report_text.lm