Skip to content

Commit

Permalink
Add estimate_contrasts method to report() (#372)
Browse files Browse the repository at this point in the history
* add estimate_contrasts method to report

* Fix lints

* styler, lint

* attempt to use is_stan_glmer_avail

* lint

* remove cohen d

---------

Co-authored-by: Brenton M. Wiernik <[email protected]>
Co-authored-by: Daniel <[email protected]>
  • Loading branch information
3 people authored Jun 27, 2023
1 parent 6a2cc1c commit 75ae425
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 0 deletions.
3 changes: 3 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ Suggests:
rmarkdown,
rstanarm,
survival,
modelbased,
emmeans,
testthat
VignetteBuilder:
knitr
Expand Down Expand Up @@ -108,6 +110,7 @@ Collate:
'report.compare_performance.R'
'report.data.frame.R'
'report.default.R'
'report.estimate_contrasts.R'
'report.factor.R'
'report.glm.R'
'report.glmmTMB.R'
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ S3method(report,character)
S3method(report,compare_performance)
S3method(report,data.frame)
S3method(report,default)
S3method(report,estimate_contrasts)
S3method(report,factor)
S3method(report,glm)
S3method(report,glmmTMB)
Expand Down Expand Up @@ -201,6 +202,7 @@ S3method(report_table,character)
S3method(report_table,compare_performance)
S3method(report_table,data.frame)
S3method(report_table,default)
S3method(report_table,estimate_contrasts)
S3method(report_table,factor)
S3method(report_table,glm)
S3method(report_table,glmmTMB)
Expand Down Expand Up @@ -230,6 +232,7 @@ S3method(report_text,character)
S3method(report_text,compare_performance)
S3method(report_text,data.frame)
S3method(report_text,default)
S3method(report_text,estimate_contrasts)
S3method(report_text,factor)
S3method(report_text,glm)
S3method(report_text,glmmTMB)
Expand Down
52 changes: 52 additions & 0 deletions R/report.estimate_contrasts.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#' Reporting `estimate_contrasts` objects
#'
#' Create reports for `estimate_contrasts` objects.
#'
#' @param x Object of class `estimate_contrasts`.
#' @param table Provide the output of `report_table()` to avoid its
#' re-computation.
#' @inheritParams report
#'
#' @inherit report return seealso
#'
#' @examplesIf requireNamespace("modelbased", quietly = TRUE) && requireNamespace("emmeans", quietly = TRUE)
#' library(modelbased)
#' model <- lm(Sepal.Width ~ Species, data = iris)
#' contr <- estimate_contrasts(model)
#' report(contr)
#' @return An object of class [report()].
#' @export
report.estimate_contrasts <- function(x, ...) {
table <- report_table(x, ...)
text <- report_text(x, table = table, ...)

as.report(text, table = table, ...)
}

# report_table ------------------------------------------------------------

#' @rdname report.estimate_contrasts
#' @export
report_table.estimate_contrasts <- function(x, ...) {
as.report_table(x)
}

# report_text ------------------------------------------------------------

#' @rdname report.estimate_contrasts
#' @export
report_text.estimate_contrasts <- function(x, table = NULL, ...) {
f_table <- insight::format_table(table)

text <- paste0("The difference between ", x$Level1, " and ", x$Level2, " is ",
ifelse(x$Difference < 0, " negative", "positive"), " and statistically ",
ifelse(x$p < 0.05, "significant", "non-significant"),
" (difference = ", f_table$Difference, ", 95% CI ", f_table$`95% CI`, ", ",
names(f_table)[6], " = ", f_table[[6]], ", ", insight::format_p(table$p), ")",
collapse = ". "
)

text <- paste("The marginal contrasts analysis suggests the following.", paste0(text, collapse = ""))

as.report_text(text)
}
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ reference:
- report.lm
- report.stanreg
- report.test_performance
- report.estimate_contrasts

- title: Report Non-Statistical Objects
desc: |
Expand Down
70 changes: 70 additions & 0 deletions man/report.estimate_contrasts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 75ae425

Please sign in to comment.