diff --git a/DESCRIPTION b/DESCRIPTION index ab52c93ac..bd5799535 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: modelbased Title: Estimation of Model-Based Predictions, Contrasts and Means -Version: 0.18.0.5 +Version: 0.18.0.6 Authors@R: c(person(given = "Dominique", family = "Makowski", diff --git a/NEWS.md b/NEWS.md index 498c23269..b566ff9c7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,20 @@ # modelbased (devel) +## Breaking Changes + +* Table headers and footers are now harmonized to conceptually align with the + package documentation (see the `estimate` argument in `?estimate_means`, as + well as the vignettes on the modelisation-approach + (https://easystats.github.io/modelbased/articles/post_estimation_framework.html) + and technical details on marginalization + (https://easystats.github.io/modelbased/articles/technical_marginalization.html)). + Specifically, `estimate` defines the *unit of interest* for your *estimand*, + distinguishing between predictions *conditioned* on specific, theoretical + individual levels and *marginal* predictions averaged over empirical + observations at the sample or population level. Furthermore, table footers for + mixed models are now more informative, detailing how random effects are + handled. + ## Changes * `effectsize = "emmeans"` in `estimate_contrasts()` now also works for `polr` diff --git a/R/data.R b/R/data.R index 180f09305..f56abb8df 100644 --- a/R/data.R +++ b/R/data.R @@ -68,7 +68,7 @@ NULL #' @docType data -#' @title Sample dataset from patients with somatic symptons +#' @title Sample dataset from patients with somatic symptoms #' @name stigma #' @keywords data #' diff --git a/R/estimate_contrasts.R b/R/estimate_contrasts.R index f49b783d8..e92b36a26 100644 --- a/R/estimate_contrasts.R +++ b/R/estimate_contrasts.R @@ -600,15 +600,15 @@ estimate_contrasts.default <- function( suffix <- "Inequality Analysis" type <- "inequality" } else { - suffix <- "Contrasts Analysis" + suffix <- "Contrasts" } attr(out, "table_title") <- c( switch( estimate, - specific = paste("Model-based", suffix), - typical = paste("Marginal", suffix), - average = paste("Averaged", suffix), - population = paste("Counterfactual", suffix, "(G-computation)") + specific = , + typical = paste("Conditional", suffix), + average = paste("Marginal", suffix), + population = paste("Marginal", suffix, "(G-computation)") ), "blue" ) diff --git a/R/estimate_means.R b/R/estimate_means.R index 9ef4803f9..ae2beea14 100644 --- a/R/estimate_means.R +++ b/R/estimate_means.R @@ -527,10 +527,10 @@ estimate_means <- function( attr(means, "table_title") <- c( switch( estimate, - specific = "Model-based Predictions", - typical = "Estimated Marginal Means", - average = "Average Predictions", - population = "Average Counterfactual Predictions" + specific = , + typical = "Conditional Predictions", + average = "Marginal Predictions", + population = "Marginal Predictions (G-computation)" ), "blue" ) diff --git a/R/estimate_predicted.R b/R/estimate_predicted.R index dffd9d318..72f1553d4 100644 --- a/R/estimate_predicted.R +++ b/R/estimate_predicted.R @@ -588,7 +588,7 @@ estimate_relation <- function( attr(out, "datagrid") <- data attr(out, "focal_terms") <- grid_specs$at_specs$varname attr(out, "preserve_range") <- grid_specs$preserve_range - attr(out, "table_title") <- c("Model-based Predictions", "blue") + attr(out, "table_title") <- c("Conditional Predictions", "blue") attr(out, "coef_name") <- "Predicted" attr(out, "model_info") <- insight::model_info(model, response = 1) attr(out, "predict") <- predict diff --git a/R/get_emcontrasts.R b/R/get_emcontrasts.R index b3303ed15..265634c2b 100644 --- a/R/get_emcontrasts.R +++ b/R/get_emcontrasts.R @@ -71,7 +71,11 @@ get_emcontrasts <- function( fun_args$mode <- ordinal$mode } .check_ordinal_response_filter(my_args$response_filter, ordinal$mode) - .check_ordinal_response_filter(my_args$response_contrast_filter, ordinal$mode, "contrast") + .check_ordinal_response_filter( + my_args$response_contrast_filter, + ordinal$mode, + "contrast" + ) } # add dots @@ -199,6 +203,11 @@ get_emcontrasts <- function( keep_iterations <- FALSE } + # emmeans is always conditioning on a typical cluster + if (insight::is_mixed_model(model)) { + attr(estimated, "re_form_na") <- TRUE + } + attr(out, "contrast") <- my_args$contrast attr(out, "predict") <- predict attr(out, "at") <- my_args$by diff --git a/R/get_emmeans.R b/R/get_emmeans.R index 2d4e8ad4e..97b9ea941 100644 --- a/R/get_emmeans.R +++ b/R/get_emmeans.R @@ -122,6 +122,11 @@ get_emmeans <- function( keep_iterations <- FALSE } + # emmeans is always conditioning on a typical cluster + if (insight::is_mixed_model(model)) { + attr(estimated, "re_form_na") <- TRUE + } + attr(estimated, "at") <- my_args$by attr(estimated, "by") <- my_args$by attr(estimated, "predict") <- predict @@ -318,7 +323,9 @@ get_emmeans <- function( } estimate_name <- x@misc$estName if (!is.null(estimate_name) && estimate_name %in% colnames(means)) { - colnames(means)[colnames(means) == estimate_name] <- .emmeans_ordinal_estimate_names[[ordinal_mode]] + colnames(means)[colnames(means) == estimate_name] <- .emmeans_ordinal_estimate_names[[ + ordinal_mode + ]] } .clean_pseudo_factor_emmeans_ordinal( means, @@ -603,7 +610,11 @@ get_emmeans <- function( # we cannot use the response in `by` (or `contrast`) for the other modes. # `ordinal_mode` is the mode the user asked for, not the mode that we use # internally for slopes -.check_ordinal_response_filter <- function(response_filter, ordinal_mode, argument = "by") { +.check_ordinal_response_filter <- function( + response_filter, + ordinal_mode, + argument = "by" +) { if (!is.null(response_filter) && !identical(ordinal_mode, "prob")) { insight::format_error(paste0( "The response `", diff --git a/R/get_marginalcontrasts.R b/R/get_marginalcontrasts.R index f5fa89edf..920eadcc3 100644 --- a/R/get_marginalcontrasts.R +++ b/R/get_marginalcontrasts.R @@ -18,6 +18,7 @@ get_marginalcontrasts <- function( ) { # check if available insight::check_if_installed("marginaleffects", minimum_version = "0.29.0") + dots <- list(...) # temporarily overwrite settings that error on "too many" rows me_option <- getOption("marginaleffects_safe") @@ -135,7 +136,10 @@ get_marginalcontrasts <- function( } else { slope_filter <- .parse_by_filter(my_args$by) } - slope_filter <- .present_filter_values(insight::get_data(model, verbose = FALSE), slope_filter) + slope_filter <- .present_filter_values( + insight::get_data(model, verbose = FALSE), + slope_filter + ) # sanity check - we need at least two slopes to compare. We use the # original `by`, because a group in a `comparison` formula replaces it if ( @@ -167,7 +171,6 @@ get_marginalcontrasts <- function( # the hypothesis compares all slopes, so we cannot filter the contrasts # later. Instead, we only keep the data rows that pass the filter. The # slopes are averaged within each group of `by`, so they don't change. - dots <- list(...) if ( identical(estimate, "average") && length(slope_filter) && @@ -228,6 +231,11 @@ get_marginalcontrasts <- function( # Last step: Save information in attributes -------------------------------- # --------------------------------------------------------------------------- + # handle brms-alias + if (!is.null(dots$re_formula)) { + dots$re.form <- dots$re_formula + } + out <- .add_attributes( out, by = my_args$by, @@ -244,7 +252,10 @@ get_marginalcontrasts <- function( context_effects = my_args$context_effects, iterations = iterations, keep_iterations = keep_iterations - ) + ), + # needed for some additional information for mixed models + model = model, + re_form_na = !is.null(dots$re.form) && is.na(dots$re.form) ) out <- .rename_focal_attributes(out) @@ -319,7 +330,10 @@ get_marginalcontrasts <- function( .parse_by_filter <- function(by) { by_filter <- list() for (i in by[grepl("=", by, fixed = TRUE)]) { - filter_value <- insight::trim_ws(unlist(strsplit(i, "=", fixed = TRUE), use.names = FALSE)) + filter_value <- insight::trim_ws(unlist( + strsplit(i, "=", fixed = TRUE), + use.names = FALSE + )) if (length(filter_value) > 1) { value <- .safe(eval(str2lang(filter_value[2]))) if (!is.null(value)) { diff --git a/R/get_marginalmeans.R b/R/get_marginalmeans.R index 4138f5ed0..cb358e2bc 100644 --- a/R/get_marginalmeans.R +++ b/R/get_marginalmeans.R @@ -309,6 +309,11 @@ get_marginalmeans <- function( # Last step: Save information in attributes -------------------------------- # --------------------------------------------------------------------------- + # handle brms-alias + if (!is.null(dots$re_formula)) { + dots$re.form <- dots$re_formula + } + means <- .add_attributes( means, by = my_args$by, @@ -329,7 +334,10 @@ get_marginalmeans <- function( vcov = vcov_means, equivalence = dots$equivalence ) - ) + ), + # needed for some additional information for mixed models + model = model, + re_form_na = !is.null(dots$re.form) && is.na(dots$re.form) ) class(means) <- unique(c("marginaleffects_means", class(means))) @@ -673,14 +681,47 @@ get_marginalmeans <- function( # - renamed_focal: focal terms with the name of an output column, named by # their old names, with the new names ".1" as values #' @keywords internal -.add_attributes <- function(x, by = NULL, model_info = NULL, info = NULL) { +.add_attributes <- function( + x, + by = NULL, + model_info = NULL, + info = NULL, + model = NULL, + re_form_na = NULL +) { attr(x, "at") <- by attr(x, "by") <- by attr(x, "model_info") <- model_info + # extract information, required for mixed models handling + if (!is.null(model)) { + response <- insight::find_response(model, combine = FALSE) + re_intercept <- insight::find_random(model, flatten = TRUE, split_nested = TRUE) + } else { + response <- re_form_na <- re_intercept <- NULL + } + # compact list info <- insight::compact_list(info) + # some special handling for mixed models - we need this information for + # printing an informative table footer. + if (isTRUE(model_info$is_mixed)) { + # if we have mixed models, we don't want the response in the adusted-for + # information, so we check and remove it here, if necessary + if (!is.null(info$adjusted_for) && !is.null(response)) { + info$adjusted_for <- setdiff(info$adjusted_for, response) + } + # we definitely don't want the random-intercept in the "adjusted for" list + info$adjusted_for <- setdiff(info$adjusted_for, re_intercept) + # save information about random effects (cluster/grouping variable) + if (!isTRUE(re_form_na)) { + info$re_intercept <- re_intercept + } + # save info if re.form was NA + info$re_form_na <- isTRUE(re_form_na) + } + if (!is.null(info) && length(info)) { if (!is.null(info$at_specs$varname)) { attr(x, "focal_terms") <- info$at_specs$varname @@ -704,7 +745,7 @@ get_marginalmeans <- function( "contrast", "estimate", "p_adjust", "transform", "transform_arg", "datagrid", "preserve_range", "coef_name", "slope", "ci", "model_info", "contrast_filter", "null", "iterations", "keep_iterations", "joint_test", "omnibus_test", "vcov", - "equivalence", "context_effects", "renamed_focal" + "equivalence", "context_effects", "renamed_focal", "re_intercept", "re_form_na" ) } diff --git a/R/table_footer.R b/R/table_footer.R index f82650d6e..ee675c6d0 100644 --- a/R/table_footer.R +++ b/R/table_footer.R @@ -7,6 +7,8 @@ datagrid <- info$datagrid p_adjust <- info$p_adjust adjusted_for <- info$adjusted_for + re_intercept <- info$re_intercept + re_form_na <- info$re_form_na transform <- info$transform model_info <- info$model_info marginalization <- info$estimate @@ -18,6 +20,7 @@ } # name of predicted response ----------------------------------------------- + # -------------------------------------------------------------------------- if (isTRUE(info$joint_test)) { table_footer <- NULL @@ -29,6 +32,7 @@ } # modulated predictors (focal terms) --------------------------------------- + # -------------------------------------------------------------------------- if (!is.null(by) && !isTRUE(info$joint_test) && !inherits(by, "formula")) { modulate_string <- switch(type, inequality = , contrasts = "contrasted", "modulated") @@ -42,6 +46,8 @@ } # predictors controlled (non-focal terms) ---------------------------------- + # -------------------------------------------------------------------------- + if (!is.null(adjusted_for) && length(adjusted_for) >= 1 && !all(is.na(adjusted_for))) { # if we have values of adjusted terms, add these here if (all(adjusted_for %in% colnames(x))) { @@ -51,6 +57,11 @@ } else { ref_cat_data <- NULL } + + # if we have values at which non-focal terms are held constant, we want + # them in a separate string; same for predictors we average over + averaged_over <- held_constant <- list() + if (!is.null(ref_cat_data)) { # get values at which non-focal terms are hold constant adjusted_values <- lapply(adjusted_for, function(i) ref_cat_data[[i]][1]) @@ -63,28 +74,82 @@ adjusted_for[av], adjusted_values[[av]] ) + # add to final list + held_constant <- c(held_constant, adjusted_for[av]) } else if (identical(type, "predictions")) { adjusted_for[av] <- sprintf("%s (%s)", adjusted_for[av], adjusted_values[[av]]) + # add to final list + held_constant <- c(held_constant, adjusted_for[av]) + } else { + # add to final list - we have factors that are averaged over levels, + # not hold constant at a certain level + averaged_over <- c(averaged_over, adjusted_for[av]) } } } - # The "predictors averaged" line does not strictly apply to `estimate = - # "average"`, because we average across all predictions, we do not take an - # "average value" of a non-focal predictor. Thus, we skip this line in the - # footer - if (!identical(marginalization, "average")) { - average_string <- switch(type, predictions = "controlled", "averaged") + + # convert to strings + held_constant <- unlist(held_constant, use.names = FALSE) + averaged_over <- unlist(averaged_over, use.names = FALSE) + + # first, information about non-focal terms that were hold constant at + # specific values or levels + if (!is.null(held_constant)) { table_footer <- paste0( table_footer, - "\nPredictors ", - average_string, - ": ", - toString(adjusted_for) + paste0("\nPredictors held at: ", toString(held_constant)) + ) + } + + # then, information about non-focal terms that were averaged over levels + # or within groups + if ( + !is.null(averaged_over) && !is.null(marginalization) && length(marginalization) == 1 + ) { + average_string <- paste( + "Predictors averaged over", + switch( + marginalization, + typical = "(balanced grid)", + average = , + population = , + counterfactual = "(sample)", + "" + ) + ) + table_footer <- paste0( + table_footer, + paste0("\n", average_string, ": ", toString(averaged_over)) ) } } + # Random effects handling ------------------------------------------------ + # -------------------------------------------------------------------------- + + if (!is.null(re_intercept) && !isTRUE(re_form_na) && !is.null(marginalization)) { + if (marginalization %in% c("average", "population", "counterfactual")) { + table_footer <- paste0( + table_footer, + "\nRandom effects: Marginalized across clusters." + ) + } else { + table_footer <- paste0( + table_footer, + "\nRandom effects: Averaged over a balanced grid of cluster levels." + ) + } + } + + if (isTRUE(re_form_na)) { + table_footer <- paste0( + table_footer, + "\nRandom effects: Conditional on a typical cluster." + ) + } + # P-value adjustment footer ------------------------------------------------ + # -------------------------------------------------------------------------- if (!is.null(p_adjust) && "p" %in% names(x)) { if (p_adjust == "none") { @@ -99,6 +164,7 @@ } # leave early for joint tests ---------------------------------------------- + # -------------------------------------------------------------------------- if (isTRUE(info$joint_test)) { if (!is.null(info$null) && info$omnibus_test) { @@ -112,6 +178,7 @@ } # tell user about scale of predictions / contrasts ------------------------- + # -------------------------------------------------------------------------- result_type <- switch( type, @@ -164,6 +231,7 @@ } # tell user about prediction intervals ------------------------------------- + # -------------------------------------------------------------------------- if ( identical(type, "predictions") && @@ -174,6 +242,7 @@ } # Parameter labels for special hypothesis testing -------------------------- + # -------------------------------------------------------------------------- # for special hypothesis testing, like "(b1 - b2) = (b4 - b3)", we want to # add information about the parameter names @@ -209,7 +278,9 @@ } } - # ROPE? + # ROPE? -------------------------------------------------------------------- + # -------------------------------------------------------------------------- + if (!is.null(rope)) { table_footer <- paste0( table_footer, @@ -227,6 +298,7 @@ # name of the link-scale, including a transformation ------------------------- +# ---------------------------------------------------------------------------- .link_transform_label <- function(transform, model = NULL) { if (is.character(transform) && length(transform) == 1) { diff --git a/inst/WORDLIST b/inst/WORDLIST index 4c62a1973..bc5391fe3 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -82,6 +82,7 @@ behaviour bootES brglm brms +callout cdot ception codecov @@ -161,3 +162,31 @@ visualise walkthrough ’ ’s +Adelie +anonymized +CASMIN +CKD +colours +counterfactuals +customizations +DAGs +estimand +estimands +Estimands +Excursus +facto +IBS +L'Approche +MCMCglmm +metacognition +modélisation +Modélisation +MOR +overadjustment +PHQ +positivity +Positivity +Sidak +Ulcerative +Vive +VPC diff --git a/man/stigma.Rd b/man/stigma.Rd index 4d6d296af..c41aa196c 100644 --- a/man/stigma.Rd +++ b/man/stigma.Rd @@ -3,7 +3,7 @@ \docType{data} \name{stigma} \alias{stigma} -\title{Sample dataset from patients with somatic symptons} +\title{Sample dataset from patients with somatic symptoms} \description{ An artificial, anonymized data set based on a project related to the development and persistence of somatic symptoms. diff --git a/tests/testthat/_snaps/betareg.md b/tests/testthat/_snaps/betareg.md index f5414f889..57b8e20b4 100644 --- a/tests/testthat/_snaps/betareg.md +++ b/tests/testthat/_snaps/betareg.md @@ -3,7 +3,7 @@ Code print(out, zap_small = TRUE) Output - Estimated Marginal Means + Conditional Predictions batch | Proportion | SE | 95% CI | z ------------------------------------------------ @@ -20,7 +20,7 @@ Variable predicted: yield Predictors modulated: batch - Predictors averaged: temp (3.3e+02) + Predictors held at: temp (3.3e+02) Predictions are on the response-scale. # estimate_relation for betareg @@ -28,7 +28,7 @@ Code print(out, zap_small = TRUE) Output - Model-based Predictions + Conditional Predictions batch | Predicted | 95% CI -------------------------------- @@ -45,6 +45,6 @@ Variable predicted: yield Predictors modulated: batch - Predictors controlled: temp (3.3e+02) + Predictors held at: temp (3.3e+02) Predictions are on the response-scale. diff --git a/tests/testthat/_snaps/brms.md b/tests/testthat/_snaps/brms.md index e96144b43..a203edd35 100644 --- a/tests/testthat/_snaps/brms.md +++ b/tests/testthat/_snaps/brms.md @@ -3,7 +3,7 @@ Code print(out) Output - Model-based Predictions: rt + Conditional Predictions: rt Row | rt | Predicted | SE | 95% CI -------------------------------------------- @@ -13,7 +13,7 @@ 4 | 1.54 | 1.20 | 0.85 | [0.32, 3.37] 5 | 1.48 | 1.19 | 0.83 | [0.33, 3.38] - Model-based Predictions: response + Conditional Predictions: response Row | response | Predicted | SE | 95% CI ------------------------------------------------ @@ -32,7 +32,7 @@ Code print(out, table_width = Inf) Output - Model-based Predictions: rt + Conditional Predictions: rt Row | rt | Predicted | SE | 95% CI | iter_1 | iter_2 | iter_3 ----------------------------------------------------------------------- @@ -42,7 +42,7 @@ 4 | 1.54 | 1.20 | 0.85 | [0.32, 3.37] | 0.42 | 1.29 | 1.28 5 | 1.48 | 1.19 | 0.83 | [0.33, 3.38] | 2.15 | 0.51 | 1.38 - Model-based Predictions: response + Conditional Predictions: response Row | response | Predicted | SE | 95% CI | iter_1 | iter_2 | iter_3 --------------------------------------------------------------------------- diff --git a/tests/testthat/_snaps/estimate_contrasts.md b/tests/testthat/_snaps/estimate_contrasts.md index 736383b01..8f68b4b38 100644 --- a/tests/testthat/_snaps/estimate_contrasts.md +++ b/tests/testthat/_snaps/estimate_contrasts.md @@ -4,7 +4,7 @@ print(estimate_contrasts(model, contrast = c("vs", "am"), by = "gear", backend = "marginaleffects"), zap_small = TRUE, table_width = Inf) Output - Marginal Contrasts Analysis + Conditional Contrasts Level1 | Level2 | gear | Difference | SE | 95% CI | t(25) | p ------------------------------------------------------------------------------------ @@ -37,7 +37,7 @@ print(estimate_contrasts(m, c("time", "coffee"), backend = "marginaleffects", p_adjust = "none"), zap_small = TRUE, table_width = Inf) Output - Marginal Contrasts Analysis + Conditional Contrasts Level1 | Level2 | Difference | SE | 95% CI | t(113) | p --------------------------------------------------------------------------------------------- @@ -59,7 +59,7 @@ Variable predicted: alertness Predictors contrasted: time, coffee - Predictors averaged: sex + Predictors averaged over (balanced grid): sex p-values are uncorrected. --- @@ -69,7 +69,7 @@ p_adjust = "none", comparison = ratio ~ reference | coffee), zap_small = TRUE, table_width = Inf) Output - Marginal Contrasts Analysis + Conditional Contrasts Level1 | Level2 | coffee | Ratio | SE | 95% CI | t(113) | p ---------------------------------------------------------------------------- @@ -80,7 +80,7 @@ Variable predicted: alertness Predictors contrasted: time - Predictors averaged: sex + Predictors averaged over (balanced grid): sex p-values are uncorrected. --- @@ -90,7 +90,7 @@ p_adjust = "none", comparison = "(b2-b1)=(b4-b3)"), zap_small = TRUE, table_width = Inf) Output - Marginal Contrasts Analysis + Conditional Contrasts Parameter | Difference | SE | 95% CI | t(113) | p ---------------------------------------------------------------- @@ -98,7 +98,7 @@ Variable predicted: alertness Predictors contrasted: time, coffee - Predictors averaged: sex + Predictors averaged over (balanced grid): sex p-values are uncorrected. Parameters: b2 = time [noon], coffee [coffee] @@ -112,7 +112,7 @@ print(estimate_contrasts(m, c("time", "coffee"), backend = "marginaleffects", p_adjust = "none", comparison = "b5=b3"), zap_small = TRUE, table_width = Inf) Output - Marginal Contrasts Analysis + Conditional Contrasts Parameter | Difference | SE | 95% CI | t(113) | p -------------------------------------------------------------- @@ -120,7 +120,7 @@ Variable predicted: alertness Predictors contrasted: time, coffee - Predictors averaged: sex + Predictors averaged over (balanced grid): sex p-values are uncorrected. Parameters: b5 = time [noon], coffee [control] @@ -132,7 +132,7 @@ estimate_contrasts(fit, c("e42dep", "c172code"), comparison = "b6-b3=0", backend = "marginaleffects") Output - Marginal Contrasts Analysis + Conditional Contrasts Parameter | Difference | SE | 95% CI | t(800) | p -------------------------------------------------------------- @@ -140,7 +140,8 @@ Variable predicted: neg_c_7 Predictors contrasted: e42dep, c172code - Predictors averaged: c12hour (42), barthtot (65), c161sex + Predictors held at: c12hour (42), barthtot (65) + Predictors averaged over (balanced grid): c161sex p-values are uncorrected. Parameters: b6 = e42dep [slightly dependent], c172code [intermediate level of education] @@ -154,7 +155,7 @@ No variable was specified for contrast estimation. Selecting `contrast = "Species"`. Output - Marginal Contrasts Analysis + Conditional Contrasts Level1 | Level2 | Difference | 95% CI | SE | z | p ----------------------------------------------------------------------------- @@ -174,7 +175,7 @@ Message We selected `contrast=c("Species")`. Output - Marginal Contrasts Analysis + Conditional Contrasts Level1 | Level2 | Difference | SE | 95% CI | z | p ----------------------------------------------------------------------------- @@ -195,7 +196,7 @@ No variable was specified for contrast estimation. Selecting `contrast = "Species"`. Output - Marginal Contrasts Analysis + Conditional Contrasts Level1 | Level2 | Difference | 95% CI | SE | z | p ---------------------------------------------------------------------------- @@ -215,7 +216,7 @@ Message We selected `contrast=c("Species")`. Output - Marginal Contrasts Analysis + Conditional Contrasts Level1 | Level2 | Difference | SE | 95% CI | z | p ----------------------------------------------------------------------------- @@ -230,30 +231,11 @@ # estimate_contrasts - filtering works - Code - print(estimate_contrasts(fit, "c172code", backend = "marginaleffects"), - table_width = Inf, zap_small = TRUE) - Output - Marginal Contrasts Analysis - - Level1 | Level2 | Difference | SE | 95% CI | t(827) | p - -------------------------------------------------------------------- - mid | low | -0.09 | 0.34 | [-0.76, 0.58] | -0.25 | 0.802 - high | low | 0.61 | 0.43 | [-0.24, 1.45] | 1.40 | 0.162 - high | mid | 0.69 | 0.36 | [-0.02, 1.40] | 1.92 | 0.055 - - Variable predicted: neg_c_7 - Predictors contrasted: c172code - Predictors averaged: e16sex, c161sex - p-values are uncorrected. - ---- - Code print(estimate_contrasts(fit, c("c161sex", "c172code"), backend = "marginaleffects"), table_width = Inf, zap_small = TRUE) Output - Marginal Contrasts Analysis + Conditional Contrasts Level1 | Level2 | Difference | SE | 95% CI | t(825) | p ------------------------------------------------------------------------------- @@ -275,321 +257,16 @@ Variable predicted: neg_c_7 Predictors contrasted: c161sex, c172code - Predictors averaged: e16sex - p-values are uncorrected. - ---- - - Code - print(estimate_contrasts(fit, "c161sex", "c172code", backend = "marginaleffects"), - table_width = Inf, zap_small = TRUE) - Output - Marginal Contrasts Analysis - - Level1 | Level2 | c172code | Difference | SE | 95% CI | t(825) | p - ------------------------------------------------------------------------------- - Female | Male | low | 1.05 | 0.69 | [-0.31, 2.40] | 1.51 | 0.131 - Female | Male | mid | 0.56 | 0.42 | [-0.26, 1.38] | 1.35 | 0.178 - Female | Male | high | 0.96 | 0.69 | [-0.39, 2.30] | 1.40 | 0.163 - - Variable predicted: neg_c_7 - Predictors contrasted: c161sex - Predictors averaged: e16sex - p-values are uncorrected. - ---- - - Code - print(estimate_slopes(fit, "barthtot", backend = "marginaleffects"), - table_width = Inf, zap_small = TRUE) - Output - Estimated Marginal Effects - - Slope | SE | 95% CI | t(810) | p - ----------------------------------------------- - -0.05 | 0.00 | [-0.06, -0.05] | -12.77 | < .001 - - Marginal effects estimated for barthtot - Type of slope was dY/dX - ---- - - Code - print(estimate_slopes(fit, "barthtot", by = "c172code", backend = "marginaleffects"), - table_width = Inf, zap_small = TRUE) - Output - Estimated Marginal Effects - - c172code | Slope | SE | 95% CI | t(808) | p - ---------------------------------------------------------- - low | -0.06 | 0.01 | [-0.08, -0.05] | -7.08 | < .001 - mid | -0.05 | 0.01 | [-0.06, -0.04] | -9.82 | < .001 - high | -0.05 | 0.01 | [-0.07, -0.03] | -4.53 | < .001 - - Marginal effects estimated for barthtot - Type of slope was dY/dX - ---- - - Code - print(estimate_contrasts(fit, "barthtot", "c172code", backend = "marginaleffects"), - table_width = Inf, zap_small = TRUE) - Output - Marginal Contrasts Analysis - - Level1 | Level2 | Difference | SE | 95% CI | t(808) | p - -------------------------------------------------------------------- - mid | low | 0.01 | 0.01 | [-0.01, 0.03] | 1.17 | 0.243 - high | low | 0.02 | 0.01 | [-0.01, 0.04] | 1.10 | 0.270 - high | mid | 0.00 | 0.01 | [-0.02, 0.03] | 0.27 | 0.786 - - Variable predicted: neg_c_7 - Predictors contrasted: barthtot - Predictors averaged: e16sex, barthtot (65) - p-values are uncorrected. - ---- - - Code - print(estimate_contrasts(fit, "barthtot", c("c172code", "e16sex"), backend = "marginaleffects"), - table_width = Inf, zap_small = TRUE) - Output - Marginal Contrasts Analysis - - Level1 | Level2 | Difference | SE | 95% CI | t(803) | p - ------------------------------------------------------------------------------- - low, female | low, male | -0.01 | 0.02 | [-0.04, 0.03] | -0.35 | 0.729 - mid, male | low, male | -0.01 | 0.02 | [-0.04, 0.02] | -0.46 | 0.648 - mid, female | low, male | 0.02 | 0.01 | [-0.01, 0.05] | 1.24 | 0.217 - high, male | low, male | 0.00 | 0.02 | [-0.05, 0.04] | -0.16 | 0.876 - high, female | low, male | 0.02 | 0.02 | [-0.01, 0.06] | 1.19 | 0.236 - mid, male | low, female | 0.00 | 0.02 | [-0.03, 0.03] | -0.08 | 0.940 - mid, female | low, female | 0.02 | 0.01 | [ 0.00, 0.05] | 1.76 | 0.079 - high, male | low, female | 0.00 | 0.02 | [-0.04, 0.05] | 0.12 | 0.908 - high, female | low, female | 0.03 | 0.02 | [-0.01, 0.06] | 1.58 | 0.115 - mid, female | mid, male | 0.03 | 0.01 | [ 0.00, 0.05] | 2.23 | 0.026 - high, male | mid, male | 0.00 | 0.02 | [-0.04, 0.05] | 0.18 | 0.859 - high, female | mid, male | 0.03 | 0.02 | [ 0.00, 0.06] | 1.83 | 0.068 - high, male | mid, female | -0.02 | 0.02 | [-0.06, 0.02] | -1.08 | 0.280 - high, female | mid, female | 0.00 | 0.01 | [-0.02, 0.03] | 0.26 | 0.792 - high, female | high, male | 0.03 | 0.02 | [-0.02, 0.07] | 1.11 | 0.269 - - Variable predicted: neg_c_7 - Predictors contrasted: barthtot - Predictors averaged: barthtot (65) - p-values are uncorrected. - -# estimate_contrasts - simple contrasts and with - in levels works - - Code - print(estimate_contrasts(model, "Species", backend = "marginaleffects"), - table_width = Inf) - Output - Marginal Contrasts Analysis - - Level1 | Level2 | Difference | SE | 95% CI | t(146) | p - ---------------------------------------------------------------------------- - versicolor | setosa | 1.46 | 0.11 | [1.24, 1.68] | 13.01 | < .001 - virginica | setosa | 1.95 | 0.10 | [1.75, 2.14] | 19.47 | < .001 - virginica | versicolor | 0.49 | 0.09 | [0.31, 0.67] | 5.41 | < .001 - - Variable predicted: Sepal.Length - Predictors contrasted: Species - Predictors averaged: Sepal.Width (3.1) - p-values are uncorrected. - ---- - - Code - print(estimate_contrasts(m, c("time", "coffee"), backend = "marginaleffects"), - zap_small = TRUE, table_width = Inf) - Output - Marginal Contrasts Analysis - - Level1 | Level2 | Difference | SE | 95% CI | t(113) | p - --------------------------------------------------------------------------------------------- - morning, control | morning, coffee | -5.78 | 1.99 | [-9.73, -1.83] | -2.90 | 0.004 - noon, coffee | morning, coffee | -1.93 | 1.99 | [-5.88, 2.02] | -0.97 | 0.336 - noon, control | morning, coffee | 0.00 | 1.99 | [-3.95, 3.95] | 0.00 | > .999 - afternoon, coffee | morning, coffee | 1.93 | 1.99 | [-2.02, 5.88] | 0.97 | 0.336 - afternoon, control | morning, coffee | 0.00 | 1.99 | [-3.95, 3.95] | 0.00 | > .999 - noon, coffee | morning, control | 3.86 | 1.99 | [-0.09, 7.81] | 1.93 | 0.056 - noon, control | morning, control | 5.78 | 1.99 | [ 1.83, 9.73] | 2.90 | 0.004 - afternoon, coffee | morning, control | 7.71 | 1.99 | [ 3.76, 11.66] | 3.87 | < .001 - afternoon, control | morning, control | 5.78 | 1.99 | [ 1.83, 9.73] | 2.90 | 0.004 - noon, control | noon, coffee | 1.93 | 1.99 | [-2.02, 5.88] | 0.97 | 0.336 - afternoon, coffee | noon, coffee | 3.86 | 1.99 | [-0.09, 7.81] | 1.93 | 0.056 - afternoon, control | noon, coffee | 1.93 | 1.99 | [-2.02, 5.88] | 0.97 | 0.336 - afternoon, coffee | noon, control | 1.93 | 1.99 | [-2.02, 5.88] | 0.97 | 0.336 - afternoon, control | noon, control | 0.00 | 1.99 | [-3.95, 3.95] | 0.00 | > .999 - afternoon, control | afternoon, coffee | -1.93 | 1.99 | [-5.88, 2.02] | -0.97 | 0.336 - - Variable predicted: alertness - Predictors contrasted: time, coffee - Predictors averaged: sex - p-values are uncorrected. - ---- - - Code - print(estimate_contrasts(m, contrast = "time", by = "coffee", backend = "marginaleffects"), - zap_small = TRUE, table_width = Inf) - Output - Marginal Contrasts Analysis - - Level1 | Level2 | coffee | Difference | SE | 95% CI | t(113) | p - ----------------------------------------------------------------------------------- - noon | morning | coffee | -1.93 | 1.99 | [-5.88, 2.02] | -0.97 | 0.336 - afternoon | morning | coffee | 1.93 | 1.99 | [-2.02, 5.88] | 0.97 | 0.336 - afternoon | noon | coffee | 3.86 | 1.99 | [-0.09, 7.81] | 1.93 | 0.056 - noon | morning | control | 5.78 | 1.99 | [ 1.83, 9.73] | 2.90 | 0.004 - afternoon | morning | control | 5.78 | 1.99 | [ 1.83, 9.73] | 2.90 | 0.004 - afternoon | noon | control | 0.00 | 1.99 | [-3.95, 3.95] | 0.00 | > .999 - - Variable predicted: alertness - Predictors contrasted: time - Predictors averaged: sex + Predictors averaged over (balanced grid): e16sex p-values are uncorrected. ---- - - Code - print(estimate_contrasts(model, contrast = c("mined", "spp"), backend = "marginaleffects"), - zap_small = TRUE, table_width = Inf) - Output - Marginal Contrasts Analysis - - Level1 | Level2 | Difference | SE | 95% CI | z | p - ----------------------------------------------------------------------------- - yes, PR | yes, GP | 0.06 | 0.05 | [-0.04, 0.16] | 1.10 | 0.271 - yes, DM | yes, GP | 0.32 | 0.11 | [ 0.10, 0.54] | 2.89 | 0.004 - yes, EC-A | yes, GP | 0.04 | 0.05 | [-0.05, 0.13] | 0.80 | 0.421 - yes, EC-L | yes, GP | 0.17 | 0.08 | [ 0.02, 0.32] | 2.19 | 0.028 - yes, DES-L | yes, GP | 0.43 | 0.14 | [ 0.17, 0.70] | 3.19 | 0.001 - yes, DF | yes, GP | 0.43 | 0.14 | [ 0.17, 0.70] | 3.19 | 0.001 - no, GP | yes, GP | 2.59 | 0.55 | [ 1.50, 3.67] | 4.67 | < .001 - no, PR | yes, GP | 0.51 | 0.16 | [ 0.20, 0.82] | 3.21 | 0.001 - no, DM | yes, GP | 2.86 | 0.61 | [ 1.68, 4.05] | 4.73 | < .001 - no, EC-A | yes, GP | 1.10 | 0.27 | [ 0.57, 1.64] | 4.03 | < .001 - no, EC-L | yes, GP | 4.67 | 0.94 | [ 2.82, 6.52] | 4.95 | < .001 - no, DES-L | yes, GP | 4.62 | 0.93 | [ 2.79, 6.45] | 4.95 | < .001 - no, DF | yes, GP | 2.24 | 0.49 | [ 1.28, 3.20] | 4.58 | < .001 - yes, DM | yes, PR | 0.26 | 0.11 | [ 0.05, 0.48] | 2.43 | 0.015 - yes, EC-A | yes, PR | -0.02 | 0.06 | [-0.13, 0.09] | -0.33 | 0.740 - yes, EC-L | yes, PR | 0.11 | 0.08 | [-0.04, 0.27] | 1.43 | 0.154 - yes, DES-L | yes, PR | 0.38 | 0.13 | [ 0.12, 0.64] | 2.86 | 0.004 - yes, DF | yes, PR | 0.38 | 0.13 | [ 0.12, 0.64] | 2.86 | 0.004 - no, GP | yes, PR | 2.53 | 0.56 | [ 1.44, 3.62] | 4.54 | < .001 - no, PR | yes, PR | 0.45 | 0.16 | [ 0.13, 0.77] | 2.75 | 0.006 - no, DM | yes, PR | 2.80 | 0.61 | [ 1.61, 4.00] | 4.61 | < .001 - no, EC-A | yes, PR | 1.05 | 0.28 | [ 0.50, 1.59] | 3.76 | < .001 - no, EC-L | yes, PR | 4.61 | 0.95 | [ 2.76, 6.47] | 4.87 | < .001 - no, DES-L | yes, PR | 4.56 | 0.94 | [ 2.73, 6.40] | 4.87 | < .001 - no, DF | yes, PR | 2.18 | 0.49 | [ 1.22, 3.15] | 4.44 | < .001 - yes, EC-A | yes, DM | -0.28 | 0.11 | [-0.50, -0.07] | -2.59 | 0.010 - yes, EC-L | yes, DM | -0.15 | 0.11 | [-0.36, 0.06] | -1.39 | 0.164 - yes, DES-L | yes, DM | 0.11 | 0.13 | [-0.14, 0.36] | 0.89 | 0.375 - yes, DF | yes, DM | 0.11 | 0.13 | [-0.14, 0.36] | 0.89 | 0.375 - no, GP | yes, DM | 2.27 | 0.58 | [ 1.14, 3.40] | 3.93 | < .001 - no, PR | yes, DM | 0.19 | 0.20 | [-0.21, 0.58] | 0.93 | 0.352 - no, DM | yes, DM | 2.54 | 0.63 | [ 1.31, 3.77] | 4.04 | < .001 - no, EC-A | yes, DM | 0.78 | 0.31 | [ 0.18, 1.38] | 2.56 | 0.011 - no, EC-L | yes, DM | 4.35 | 0.96 | [ 2.46, 6.24] | 4.51 | < .001 - no, DES-L | yes, DM | 4.30 | 0.95 | [ 2.43, 6.17] | 4.51 | < .001 - no, DF | yes, DM | 1.92 | 0.51 | [ 0.91, 2.93] | 3.74 | < .001 - yes, EC-L | yes, EC-A | 0.13 | 0.08 | [-0.02, 0.29] | 1.68 | 0.093 - yes, DES-L | yes, EC-A | 0.40 | 0.13 | [ 0.14, 0.66] | 2.97 | 0.003 - yes, DF | yes, EC-A | 0.40 | 0.13 | [ 0.14, 0.66] | 2.97 | 0.003 - no, GP | yes, EC-A | 2.55 | 0.56 | [ 1.46, 3.64] | 4.58 | < .001 - no, PR | yes, EC-A | 0.47 | 0.16 | [ 0.15, 0.79] | 2.90 | 0.004 - no, DM | yes, EC-A | 2.82 | 0.61 | [ 1.63, 4.01] | 4.65 | < .001 - no, EC-A | yes, EC-A | 1.06 | 0.28 | [ 0.52, 1.61] | 3.85 | < .001 - no, EC-L | yes, EC-A | 4.63 | 0.95 | [ 2.78, 6.48] | 4.90 | < .001 - no, DES-L | yes, EC-A | 4.58 | 0.94 | [ 2.75, 6.42] | 4.90 | < .001 - no, DF | yes, EC-A | 2.20 | 0.49 | [ 1.24, 3.17] | 4.49 | < .001 - yes, DES-L | yes, EC-L | 0.26 | 0.13 | [ 0.02, 0.51] | 2.08 | 0.037 - yes, DF | yes, EC-L | 0.26 | 0.13 | [ 0.02, 0.51] | 2.08 | 0.037 - no, GP | yes, EC-L | 2.42 | 0.57 | [ 1.31, 3.53] | 4.28 | < .001 - no, PR | yes, EC-L | 0.34 | 0.18 | [-0.01, 0.69] | 1.89 | 0.058 - no, DM | yes, EC-L | 2.69 | 0.62 | [ 1.48, 3.90] | 4.37 | < .001 - no, EC-A | yes, EC-L | 0.93 | 0.29 | [ 0.37, 1.50] | 3.23 | 0.001 - no, EC-L | yes, EC-L | 4.50 | 0.95 | [ 2.63, 6.37] | 4.72 | < .001 - no, DES-L | yes, EC-L | 4.45 | 0.94 | [ 2.60, 6.30] | 4.71 | < .001 - no, DF | yes, EC-L | 2.07 | 0.50 | [ 1.09, 3.05] | 4.14 | < .001 - yes, DF | yes, DES-L | 0.00 | 0.13 | [-0.26, 0.26] | 0.00 | > .999 - no, GP | yes, DES-L | 2.15 | 0.59 | [ 1.00, 3.31] | 3.67 | < .001 - no, PR | yes, DES-L | 0.07 | 0.22 | [-0.36, 0.50] | 0.33 | 0.738 - no, DM | yes, DES-L | 2.43 | 0.64 | [ 1.18, 3.68] | 3.81 | < .001 - no, EC-A | yes, DES-L | 0.67 | 0.32 | [ 0.04, 1.29] | 2.09 | 0.037 - no, EC-L | yes, DES-L | 4.24 | 0.97 | [ 2.33, 6.14] | 4.36 | < .001 - no, DES-L | yes, DES-L | 4.19 | 0.96 | [ 2.30, 6.07] | 4.35 | < .001 - no, DF | yes, DES-L | 1.81 | 0.52 | [ 0.78, 2.83] | 3.45 | < .001 - no, GP | yes, DF | 2.15 | 0.59 | [ 1.00, 3.31] | 3.67 | < .001 - no, PR | yes, DF | 0.07 | 0.22 | [-0.36, 0.50] | 0.33 | 0.738 - no, DM | yes, DF | 2.43 | 0.64 | [ 1.18, 3.68] | 3.81 | < .001 - no, EC-A | yes, DF | 0.67 | 0.32 | [ 0.04, 1.29] | 2.09 | 0.037 - no, EC-L | yes, DF | 4.24 | 0.97 | [ 2.33, 6.14] | 4.36 | < .001 - no, DES-L | yes, DF | 4.19 | 0.96 | [ 2.30, 6.07] | 4.35 | < .001 - no, DF | yes, DF | 1.81 | 0.52 | [ 0.78, 2.83] | 3.45 | < .001 - no, PR | no, GP | -2.08 | 0.48 | [-3.02, -1.14] | -4.35 | < .001 - no, DM | no, GP | 0.27 | 0.37 | [-0.46, 1.00] | 0.73 | 0.466 - no, EC-A | no, GP | -1.49 | 0.41 | [-2.29, -0.68] | -3.61 | < .001 - no, EC-L | no, GP | 2.08 | 0.58 | [ 0.95, 3.21] | 3.61 | < .001 - no, DES-L | no, GP | 2.03 | 0.57 | [ 0.92, 3.15] | 3.57 | < .001 - no, DF | no, GP | -0.35 | 0.35 | [-1.04, 0.35] | -0.98 | 0.328 - no, DM | no, PR | 2.35 | 0.53 | [ 1.32, 3.39] | 4.47 | < .001 - no, EC-A | no, PR | 0.59 | 0.23 | [ 0.14, 1.05] | 2.56 | 0.011 - no, EC-L | no, PR | 4.16 | 0.86 | [ 2.49, 5.84] | 4.87 | < .001 - no, DES-L | no, PR | 4.11 | 0.85 | [ 2.45, 5.77] | 4.86 | < .001 - no, DF | no, PR | 1.73 | 0.42 | [ 0.92, 2.55] | 4.15 | < .001 - no, EC-A | no, DM | -1.76 | 0.46 | [-2.65, -0.87] | -3.86 | < .001 - no, EC-L | no, DM | 1.81 | 0.55 | [ 0.73, 2.89] | 3.29 | < .001 - no, DES-L | no, DM | 1.76 | 0.54 | [ 0.70, 2.82] | 3.24 | 0.001 - no, DF | no, DM | -0.62 | 0.38 | [-1.36, 0.12] | -1.65 | 0.100 - no, EC-L | no, EC-A | 3.57 | 0.77 | [ 2.07, 5.07] | 4.66 | < .001 - no, DES-L | no, EC-A | 3.52 | 0.76 | [ 2.03, 5.00] | 4.65 | < .001 - no, DF | no, EC-A | 1.14 | 0.36 | [ 0.43, 1.85] | 3.16 | 0.002 - no, DES-L | no, EC-L | -0.05 | 0.48 | [-0.99, 0.89] | -0.10 | 0.918 - no, DF | no, EC-L | -2.43 | 0.61 | [-3.63, -1.22] | -3.95 | < .001 - no, DF | no, DES-L | -2.38 | 0.61 | [-3.57, -1.19] | -3.92 | < .001 - - Variable predicted: count - Predictors contrasted: mined, spp - Predictors averaged: cover (8.7e-11), site - p-values are uncorrected. - Contrasts are on the response-scale. - ---- - - Code - print(estimate_contrasts(model, contrast = "mined", by = "spp", backend = "marginaleffects"), - zap_small = TRUE, table_width = Inf) - Output - Marginal Contrasts Analysis - - Level1 | Level2 | spp | Difference | SE | 95% CI | z | p - -------------------------------------------------------------------------- - no | yes | GP | 2.59 | 0.55 | [1.50, 3.67] | 4.67 | < .001 - no | yes | PR | 0.45 | 0.16 | [0.13, 0.77] | 2.75 | 0.006 - no | yes | DM | 2.54 | 0.63 | [1.31, 3.77] | 4.04 | < .001 - no | yes | EC-A | 1.06 | 0.28 | [0.52, 1.61] | 3.85 | < .001 - no | yes | EC-L | 4.50 | 0.95 | [2.63, 6.37] | 4.72 | < .001 - no | yes | DES-L | 4.19 | 0.96 | [2.30, 6.07] | 4.35 | < .001 - no | yes | DF | 1.81 | 0.52 | [0.78, 2.83] | 3.45 | < .001 - - Variable predicted: count - Predictors contrasted: mined - Predictors averaged: cover (8.7e-11), site - p-values are uncorrected. - Contrasts are on the response-scale. - # estimate_contrasts - examples from docs work as intendec Code print(estimate_contrasts(model, contrast = "Petal.Width", by = "Species"), zap_small = TRUE, table_width = Inf) Output - Marginal Contrasts Analysis + Conditional Contrasts Level1 | Level2 | Difference | SE | 95% CI | t(144) | p ---------------------------------------------------------------------------- @@ -599,291 +276,7 @@ Variable predicted: Sepal.Width Predictors contrasted: Petal.Width - Predictors averaged: Petal.Width (1.2) - p-values are uncorrected. - ---- - - Code - print(estimate_contrasts(model, contrast = c("Species", "Petal.Width"), length = 2), - zap_small = TRUE, table_width = Inf) - Output - Marginal Contrasts Analysis - - Level1 | Level2 | Difference | SE | 95% CI | t(144) | p - ---------------------------------------------------------------------------------------- - setosa, 2.5 | setosa, 0.1 | 2.01 | 0.98 | [ 0.08, 3.94] | 2.06 | 0.041 - versicolor, 0.1 | setosa, 0.1 | -1.83 | 0.28 | [-2.38, -1.28] | -6.55 | < .001 - versicolor, 2.5 | setosa, 0.1 | 0.70 | 0.27 | [ 0.17, 1.23] | 2.61 | 0.010 - virginica, 0.1 | setosa, 0.1 | -1.55 | 0.31 | [-2.17, -0.93] | -4.95 | < .001 - virginica, 2.5 | setosa, 0.1 | -0.03 | 0.11 | [-0.25, 0.19] | -0.29 | 0.773 - versicolor, 0.1 | setosa, 2.5 | -3.84 | 0.96 | [-5.73, -1.95] | -4.01 | < .001 - versicolor, 2.5 | setosa, 2.5 | -1.31 | 0.95 | [-3.19, 0.58] | -1.37 | 0.172 - virginica, 0.1 | setosa, 2.5 | -3.56 | 0.97 | [-5.47, -1.65] | -3.68 | < .001 - virginica, 2.5 | setosa, 2.5 | -2.04 | 0.92 | [-3.86, -0.22] | -2.21 | 0.028 - versicolor, 2.5 | versicolor, 0.1 | 2.53 | 0.52 | [ 1.50, 3.56] | 4.86 | < .001 - virginica, 0.1 | versicolor, 0.1 | 0.28 | 0.41 | [-0.52, 1.08] | 0.69 | 0.492 - virginica, 2.5 | versicolor, 0.1 | 1.80 | 0.28 | [ 1.24, 2.35] | 6.35 | < .001 - virginica, 0.1 | versicolor, 2.5 | -2.25 | 0.40 | [-3.04, -1.46] | -5.64 | < .001 - virginica, 2.5 | versicolor, 2.5 | -0.73 | 0.27 | [-1.27, -0.20] | -2.70 | 0.008 - virginica, 2.5 | virginica, 0.1 | 1.52 | 0.37 | [ 0.77, 2.26] | 4.04 | < .001 - - Variable predicted: Sepal.Width - Predictors contrasted: Species, Petal.Width - p-values are uncorrected. - ---- - - Code - print(estimate_contrasts(model, contrast = c("Species", "Petal.Width=c(1, 2)")), - zap_small = TRUE, table_width = Inf) - Output - Marginal Contrasts Analysis - - Level1 | Level2 | Difference | SE | 95% CI | t(144) | p - ------------------------------------------------------------------------------------ - setosa, 2 | setosa, 1 | 0.84 | 0.41 | [ 0.03, 1.64] | 2.06 | 0.041 - versicolor, 1 | setosa, 1 | -1.63 | 0.32 | [-2.27, -1.00] | -5.09 | < .001 - versicolor, 2 | setosa, 1 | -0.58 | 0.35 | [-1.26, 0.10] | -1.68 | 0.096 - virginica, 1 | setosa, 1 | -1.73 | 0.35 | [-2.43, -1.04] | -4.93 | < .001 - virginica, 2 | setosa, 1 | -1.10 | 0.31 | [-1.72, -0.48] | -3.52 | < .001 - versicolor, 1 | setosa, 2 | -2.47 | 0.72 | [-3.89, -1.05] | -3.43 | < .001 - versicolor, 2 | setosa, 2 | -1.42 | 0.73 | [-2.86, 0.03] | -1.94 | 0.055 - virginica, 1 | setosa, 2 | -2.57 | 0.73 | [-4.02, -1.12] | -3.50 | < .001 - virginica, 2 | setosa, 2 | -1.94 | 0.72 | [-3.35, -0.52] | -2.71 | 0.008 - versicolor, 2 | versicolor, 1 | 1.05 | 0.22 | [ 0.62, 1.48] | 4.86 | < .001 - virginica, 1 | versicolor, 1 | -0.10 | 0.19 | [-0.47, 0.27] | -0.54 | 0.589 - virginica, 2 | versicolor, 1 | 0.53 | 0.09 | [ 0.35, 0.71] | 5.72 | < .001 - virginica, 1 | versicolor, 2 | -1.15 | 0.23 | [-1.60, -0.71] | -5.13 | < .001 - virginica, 2 | versicolor, 2 | -0.52 | 0.16 | [-0.84, -0.21] | -3.31 | 0.001 - virginica, 2 | virginica, 1 | 0.63 | 0.16 | [ 0.32, 0.94] | 4.04 | < .001 - - Variable predicted: Sepal.Width - Predictors contrasted: Species, Petal.Width=c(1, 2) - p-values are uncorrected. - ---- - - Code - print(estimate_contrasts(model, by = "Petal.Width", length = 4), zap_small = TRUE, - table_width = Inf) - Message - We selected `contrast=c("Species")`. - Output - Marginal Contrasts Analysis - - Level1 | Level2 | Petal.Width | Difference | SE | 95% CI | t(144) | p - -------------------------------------------------------------------------------------------- - versicolor | setosa | 0.10 | -1.83 | 0.28 | [-2.38, -1.28] | -6.55 | < .001 - virginica | setosa | 0.10 | -1.55 | 0.31 | [-2.17, -0.93] | -4.95 | < .001 - virginica | versicolor | 0.10 | 0.28 | 0.41 | [-0.52, 1.08] | 0.69 | 0.492 - versicolor | setosa | 0.90 | -1.65 | 0.29 | [-2.22, -1.08] | -5.74 | < .001 - virginica | setosa | 0.90 | -1.71 | 0.32 | [-2.35, -1.07] | -5.28 | < .001 - virginica | versicolor | 0.90 | -0.06 | 0.21 | [-0.47, 0.35] | -0.28 | 0.780 - versicolor | setosa | 1.70 | -1.48 | 0.60 | [-2.67, -0.29] | -2.47 | 0.015 - virginica | setosa | 1.70 | -1.88 | 0.60 | [-3.06, -0.70] | -3.14 | 0.002 - virginica | versicolor | 1.70 | -0.40 | 0.11 | [-0.62, -0.17] | -3.50 | < .001 - versicolor | setosa | 2.50 | -1.31 | 0.95 | [-3.19, 0.58] | -1.37 | 0.172 - virginica | setosa | 2.50 | -2.04 | 0.92 | [-3.86, -0.22] | -2.21 | 0.028 - virginica | versicolor | 2.50 | -0.73 | 0.27 | [-1.27, -0.20] | -2.70 | 0.008 - - Variable predicted: Sepal.Width - Predictors contrasted: Species - p-values are uncorrected. - -# estimate_contrasts - test all combinations of contrast and by, with filtering - - Code - print(estimate_contrasts(model2, c("grp", "time", "x")), zap_small = TRUE, - table_width = Inf) - Output - Marginal Contrasts Analysis - - Level1 | Level2 | Difference | SE | 95% CI | t(992) | p - -------------------------------------------------------------------------------------- - control, 1, b | control, 1, a | 0.15 | 0.13 | [-0.10, 0.40] | 1.20 | 0.231 - control, 2, a | control, 1, a | 0.03 | 0.13 | [-0.23, 0.28] | 0.19 | 0.847 - control, 2, b | control, 1, a | 0.09 | 0.13 | [-0.16, 0.34] | 0.73 | 0.465 - treatment, 1, a | control, 1, a | 0.19 | 0.13 | [-0.06, 0.45] | 1.49 | 0.137 - treatment, 1, b | control, 1, a | -0.03 | 0.13 | [-0.28, 0.22] | -0.22 | 0.824 - treatment, 2, a | control, 1, a | 0.02 | 0.13 | [-0.23, 0.27] | 0.19 | 0.850 - treatment, 2, b | control, 1, a | 0.05 | 0.12 | [-0.19, 0.28] | 0.37 | 0.712 - control, 2, a | control, 1, b | -0.12 | 0.13 | [-0.38, 0.13] | -0.97 | 0.332 - control, 2, b | control, 1, b | -0.06 | 0.12 | [-0.30, 0.19] | -0.46 | 0.648 - treatment, 1, a | control, 1, b | 0.04 | 0.13 | [-0.20, 0.29] | 0.34 | 0.730 - treatment, 1, b | control, 1, b | -0.18 | 0.12 | [-0.42, 0.06] | -1.45 | 0.147 - treatment, 2, a | control, 1, b | -0.13 | 0.12 | [-0.37, 0.12] | -1.02 | 0.307 - treatment, 2, b | control, 1, b | -0.10 | 0.12 | [-0.34, 0.13] | -0.89 | 0.376 - control, 2, b | control, 2, a | 0.07 | 0.13 | [-0.19, 0.32] | 0.52 | 0.604 - treatment, 1, a | control, 2, a | 0.17 | 0.13 | [-0.09, 0.43] | 1.26 | 0.207 - treatment, 1, b | control, 2, a | -0.05 | 0.13 | [-0.31, 0.20] | -0.41 | 0.680 - treatment, 2, a | control, 2, a | 0.00 | 0.13 | [-0.26, 0.25] | -0.01 | 0.991 - treatment, 2, b | control, 2, a | 0.02 | 0.13 | [-0.23, 0.27] | 0.16 | 0.876 - treatment, 1, a | control, 2, b | 0.10 | 0.13 | [-0.15, 0.35] | 0.78 | 0.437 - treatment, 1, b | control, 2, b | -0.12 | 0.13 | [-0.37, 0.12] | -0.97 | 0.333 - treatment, 2, a | control, 2, b | -0.07 | 0.13 | [-0.32, 0.18] | -0.55 | 0.582 - treatment, 2, b | control, 2, b | -0.05 | 0.12 | [-0.29, 0.19] | -0.40 | 0.691 - treatment, 1, b | treatment, 1, a | -0.22 | 0.13 | [-0.47, 0.03] | -1.73 | 0.083 - treatment, 2, a | treatment, 1, a | -0.17 | 0.13 | [-0.42, 0.08] | -1.32 | 0.187 - treatment, 2, b | treatment, 1, a | -0.15 | 0.12 | [-0.39, 0.09] | -1.20 | 0.230 - treatment, 2, a | treatment, 1, b | 0.05 | 0.12 | [-0.19, 0.30] | 0.42 | 0.676 - treatment, 2, b | treatment, 1, b | 0.07 | 0.12 | [-0.16, 0.31] | 0.61 | 0.541 - treatment, 2, b | treatment, 2, a | 0.02 | 0.12 | [-0.21, 0.26] | 0.18 | 0.861 - - Variable predicted: score - Predictors contrasted: grp, time, x - p-values are uncorrected. - ---- - - Code - print(estimate_contrasts(model2, c("grp", "time"), by = "x"), zap_small = TRUE, - table_width = Inf) - Output - Marginal Contrasts Analysis - - Level1 | Level2 | x | Difference | SE | 95% CI | t(992) | p - ------------------------------------------------------------------------------------ - control, 2 | control, 1 | a | 0.03 | 0.13 | [-0.23, 0.28] | 0.19 | 0.847 - treatment, 1 | control, 1 | a | 0.19 | 0.13 | [-0.06, 0.45] | 1.49 | 0.137 - treatment, 2 | control, 1 | a | 0.02 | 0.13 | [-0.23, 0.27] | 0.19 | 0.850 - treatment, 1 | control, 2 | a | 0.17 | 0.13 | [-0.09, 0.43] | 1.26 | 0.207 - treatment, 2 | control, 2 | a | 0.00 | 0.13 | [-0.26, 0.25] | -0.01 | 0.991 - treatment, 2 | treatment, 1 | a | -0.17 | 0.13 | [-0.42, 0.08] | -1.32 | 0.187 - control, 2 | control, 1 | b | -0.06 | 0.12 | [-0.30, 0.19] | -0.46 | 0.648 - treatment, 1 | control, 1 | b | -0.18 | 0.12 | [-0.42, 0.06] | -1.45 | 0.147 - treatment, 2 | control, 1 | b | -0.10 | 0.12 | [-0.34, 0.13] | -0.89 | 0.376 - treatment, 1 | control, 2 | b | -0.12 | 0.13 | [-0.37, 0.12] | -0.97 | 0.333 - treatment, 2 | control, 2 | b | -0.05 | 0.12 | [-0.29, 0.19] | -0.40 | 0.691 - treatment, 2 | treatment, 1 | b | 0.07 | 0.12 | [-0.16, 0.31] | 0.61 | 0.541 - - Variable predicted: score - Predictors contrasted: grp, time - p-values are uncorrected. - ---- - - Code - print(estimate_contrasts(model2, "grp", by = c("time", "x")), zap_small = TRUE, - table_width = Inf) - Output - Marginal Contrasts Analysis - - Level1 | Level2 | time | x | Difference | SE | 95% CI | t(992) | p - ----------------------------------------------------------------------------------- - treatment | control | 1 | a | 0.19 | 0.13 | [-0.06, 0.45] | 1.49 | 0.137 - treatment | control | 2 | a | 0.00 | 0.13 | [-0.26, 0.25] | -0.01 | 0.991 - treatment | control | 1 | b | -0.18 | 0.12 | [-0.42, 0.06] | -1.45 | 0.147 - treatment | control | 2 | b | -0.05 | 0.12 | [-0.29, 0.19] | -0.40 | 0.691 - - Variable predicted: score - Predictors contrasted: grp - p-values are uncorrected. - ---- - - Code - print(estimate_contrasts(model2, "grp", by = "time"), zap_small = TRUE, - table_width = Inf) - Output - Marginal Contrasts Analysis - - Level1 | Level2 | time | Difference | SE | 95% CI | t(992) | p - ------------------------------------------------------------------------------- - treatment | control | 1 | 0.01 | 0.09 | [-0.17, 0.18] | 0.09 | 0.931 - treatment | control | 2 | -0.02 | 0.09 | [-0.20, 0.15] | -0.28 | 0.780 - - Variable predicted: score - Predictors contrasted: grp - Predictors averaged: x - p-values are uncorrected. - ---- - - Code - print(estimate_contrasts(model2, c("grp", "time", "x='a'")), zap_small = TRUE, - table_width = Inf) - Output - Marginal Contrasts Analysis - - Level1 | Level2 | Difference | SE | 95% CI | t(992) | p - -------------------------------------------------------------------------------- - control, 2 | control, 1 | 0.03 | 0.13 | [-0.23, 0.28] | 0.19 | 0.847 - treatment, 1 | control, 1 | 0.19 | 0.13 | [-0.06, 0.45] | 1.49 | 0.137 - treatment, 2 | control, 1 | 0.02 | 0.13 | [-0.23, 0.27] | 0.19 | 0.850 - treatment, 1 | control, 2 | 0.17 | 0.13 | [-0.09, 0.43] | 1.26 | 0.207 - treatment, 2 | control, 2 | 0.00 | 0.13 | [-0.26, 0.25] | -0.01 | 0.991 - treatment, 2 | treatment, 1 | -0.17 | 0.13 | [-0.42, 0.08] | -1.32 | 0.187 - - Variable predicted: score - Predictors contrasted: grp, time, x='a' - p-values are uncorrected. - ---- - - Code - print(estimate_contrasts(model2, c("grp", "time=1"), by = "x"), zap_small = TRUE, - table_width = Inf) - Output - Marginal Contrasts Analysis - - Level1 | Level2 | x | Difference | SE | 95% CI | t(992) | p - ---------------------------------------------------------------------------- - treatment | control | a | 0.19 | 0.13 | [-0.06, 0.45] | 1.49 | 0.137 - treatment | control | b | -0.18 | 0.12 | [-0.42, 0.06] | -1.45 | 0.147 - - Variable predicted: score - Predictors contrasted: grp, time=1 - p-values are uncorrected. - ---- - - Code - print(estimate_contrasts(model2, "grp", by = c("time", "x='a'")), zap_small = TRUE, - table_width = Inf) - Output - Marginal Contrasts Analysis - - Level1 | Level2 | time | x | Difference | SE | 95% CI | t(992) | p - ----------------------------------------------------------------------------------- - treatment | control | 1 | a | 0.19 | 0.13 | [-0.06, 0.45] | 1.49 | 0.137 - treatment | control | 2 | a | 0.00 | 0.13 | [-0.26, 0.25] | -0.01 | 0.991 - - Variable predicted: score - Predictors contrasted: grp - p-values are uncorrected. - ---- - - Code - print(estimate_contrasts(model2, "time=c(1,2)", by = "grp"), zap_small = TRUE, - table_width = Inf) - Output - Marginal Contrasts Analysis - - Level1 | Level2 | grp | Difference | SE | 95% CI | t(994) | p - -------------------------------------------------------------------------------- - 2 | 1 | control | 0.14 | 0.11 | [-0.08, 0.36] | 1.24 | 0.216 - 2 | 1 | treatment | -0.07 | 0.11 | [-0.28, 0.14] | -0.63 | 0.529 - - Variable predicted: score - Predictors contrasted: time=c(1,2) - p-values are uncorrected. - ---- - - Code - print(estimate_contrasts(model2, c("grp", "time=2")), zap_small = TRUE, - table_width = Inf) - Output - Marginal Contrasts Analysis - - Level1 | Level2 | Difference | SE | 95% CI | t(994) | p - ------------------------------------------------------------------------ - treatment | control | -0.15 | 0.11 | [-0.36, 0.05] | -1.47 | 0.143 - - Variable predicted: score - Predictors contrasted: grp, time=2 + Predictors held at: Petal.Width (1.2) p-values are uncorrected. # estimate_contrast, slopes with emmeans-2 @@ -891,7 +284,7 @@ Code print(out, table_width = Inf) Output - Marginal Contrasts Analysis + Conditional Contrasts Level1 | Level2 | Difference | 95% CI | p ---------------------------------------------------------- diff --git a/tests/testthat/_snaps/estimate_contrasts_counterfactual.md b/tests/testthat/_snaps/estimate_contrasts_counterfactual.md index 3bee94140..dbeb5874b 100644 --- a/tests/testthat/_snaps/estimate_contrasts_counterfactual.md +++ b/tests/testthat/_snaps/estimate_contrasts_counterfactual.md @@ -3,7 +3,7 @@ Code print(out, table_width = Inf) Output - Counterfactual Contrasts Analysis (G-computation) + Marginal Contrasts (G-computation) Level1 | Level2 | Difference | SE | 95% CI | z | p ------------------------------------------------------------------ @@ -11,7 +11,9 @@ Variable predicted: QoL Predictors contrasted: treatment - Predictors averaged: time, education, hospital (0.95), age (0.22), phq4 (-0.076), ID + Predictors held at: hospital (0.95), age (0.22), phq4 (-0.076) + Predictors averaged over (sample): time, education + Random effects: Marginalized across clusters. p-values are uncorrected. --- @@ -19,7 +21,7 @@ Code print(out, table_width = Inf) Output - Counterfactual Contrasts Analysis (G-computation) + Marginal Contrasts (G-computation) Level1 | Level2 | time | Difference | SE | 95% CI | z | p ----------------------------------------------------------------------------- @@ -29,6 +31,8 @@ Variable predicted: QoL Predictors contrasted: treatment - Predictors averaged: education, hospital (0.95), age (0.22), phq4 (-0.076), ID + Predictors held at: hospital (0.95), age (0.22), phq4 (-0.076) + Predictors averaged over (sample): education + Random effects: Marginalized across clusters. p-values are uncorrected. diff --git a/tests/testthat/_snaps/estimate_means_mixed.md b/tests/testthat/_snaps/estimate_means_mixed.md index 5cc62fcbe..8f1f9ac94 100644 --- a/tests/testthat/_snaps/estimate_means_mixed.md +++ b/tests/testthat/_snaps/estimate_means_mixed.md @@ -3,7 +3,7 @@ Code estimate_means(m, c("mined", "spp"), backend = "marginaleffects", predict = "inverse_link") Output - Estimated Marginal Means + Conditional Predictions mined | spp | Mean | SE | 95% CI | z -------------------------------------------------- @@ -24,7 +24,7 @@ Variable predicted: count Predictors modulated: mined, spp - Predictors averaged: site + Random effects: Averaged over a balanced grid of cluster levels. Predictions are on the response-scale. --- @@ -32,7 +32,7 @@ Code estimate_means(m, c("mined", "spp"), backend = "marginaleffects") Output - Estimated Marginal Means + Conditional Predictions mined | spp | Mean | SE | 95% CI | z -------------------------------------------------- @@ -53,7 +53,7 @@ Variable predicted: count Predictors modulated: mined, spp - Predictors averaged: site + Random effects: Averaged over a balanced grid of cluster levels. Predictions are on the response-scale. --- @@ -61,7 +61,7 @@ Code estimate_means(m, c("mined", "spp"), backend = "marginaleffects") Output - Estimated Marginal Means + Conditional Predictions mined | spp | Mean | 95% CI ----------------------------------- diff --git a/tests/testthat/_snaps/estimate_means_print_footer.md b/tests/testthat/_snaps/estimate_means_print_footer.md new file mode 100644 index 000000000..c26bf77e2 --- /dev/null +++ b/tests/testthat/_snaps/estimate_means_print_footer.md @@ -0,0 +1,143 @@ +# estimate_means - print footer for estimate types and re.form + + Code + print(estimate_means(model, "sex", estimate = "specific")) + Output + Conditional Predictions + + sex | Mean | SE | 95% CI | t(328) + ------------------------------------------------------ + female | 3611.50 | 59.73 | [3494.00, 3729.01] | 60.46 + male | 4148.88 | 38.84 | [4072.48, 4225.28] | 106.83 + + Variable predicted: body_mass + Predictors modulated: sex + Predictors held at: species (Adelie), bill_len (44) + +--- + + Code + print(estimate_means(model, "sex", estimate = "typical")) + Output + Conditional Predictions + + sex | Mean | SE | 95% CI | t(328) + ------------------------------------------------------ + female | 3873.98 | 25.06 | [3824.69, 3923.27] | 154.61 + male | 4411.36 | 32.43 | [4347.56, 4475.15] | 136.03 + + Variable predicted: body_mass + Predictors modulated: sex + Predictors held at: bill_len (44) + Predictors averaged over (balanced grid): species + +--- + + Code + print(estimate_means(model, "sex", estimate = "average")) + Output + Marginal Predictions + + sex | Mean | SE | 95% CI | t(328) + ------------------------------------------------------ + female | 3868.92 | 23.72 | [3822.27, 3915.58] | 163.13 + male | 4545.49 | 23.74 | [4498.79, 4592.19] | 191.49 + + Variable predicted: body_mass + Predictors modulated: sex + Predictors held at: bill_len (44) + Predictors averaged over (sample): species + +--- + + Code + print(estimate_means(model, "sex", estimate = "population")) + Output + Marginal Predictions (G-computation) + + sex | Mean | SE | 95% CI | t(328) + ------------------------------------------------------ + female | 3939.15 | 27.46 | [3885.12, 3993.17] | 143.44 + male | 4476.52 | 27.38 | [4422.66, 4530.38] | 163.50 + + Variable predicted: body_mass + Predictors modulated: sex + Predictors held at: bill_len (44) + Predictors averaged over (sample): species + +--- + + Code + print(estimate_means(m, by = "period", estimate = "typical")) + Output + Conditional Predictions + + period | Probability | SE | 95% CI | z + ------------------------------------------------- + 1 | 0.22 | 0.04 | [0.14, 0.29] | 5.76 + 2 | 0.10 | 0.03 | [0.04, 0.15] | 3.66 + 3 | 0.08 | 0.02 | [0.04, 0.13] | 3.39 + 4 | 0.06 | 0.02 | [0.01, 0.10] | 2.50 + + Variable predicted: cbind(incidence, size - incidence) + Predictors modulated: period + Random effects: Averaged over a balanced grid of cluster levels. + Predictions are on the response-scale. + +--- + + Code + print(estimate_means(m, by = "period", estimate = "typical", re.form = NA)) + Output + Conditional Predictions + + period | Probability | SE | 95% CI | z + ------------------------------------------------- + 1 | 0.20 | 0.04 | [0.13, 0.27] | 5.36 + 2 | 0.08 | 0.02 | [0.04, 0.13] | 3.52 + 3 | 0.07 | 0.02 | [0.03, 0.12] | 3.27 + 4 | 0.05 | 0.02 | [0.01, 0.09] | 2.44 + + Variable predicted: cbind(incidence, size - incidence) + Predictors modulated: period + Random effects: Conditional on a typical cluster. + Predictions are on the response-scale. + +--- + + Code + print(estimate_means(m, by = "period", estimate = "average")) + Output + Marginal Predictions + + period | Probability | SE | 95% CI | z + ------------------------------------------------- + 1 | 0.22 | 0.04 | [0.14, 0.29] | 5.76 + 2 | 0.09 | 0.03 | [0.04, 0.14] | 3.65 + 3 | 0.08 | 0.02 | [0.03, 0.13] | 3.38 + 4 | 0.06 | 0.02 | [0.01, 0.10] | 2.50 + + Variable predicted: cbind(incidence, size - incidence) + Predictors modulated: period + Random effects: Marginalized across clusters. + Predictions are on the response-scale. + +--- + + Code + print(estimate_means(m, by = "period", estimate = "average", re.form = NA)) + Output + Marginal Predictions + + period | Probability | SE | 95% CI | z + ------------------------------------------------- + 1 | 0.20 | 0.04 | [0.13, 0.27] | 5.36 + 2 | 0.08 | 0.02 | [0.04, 0.13] | 3.52 + 3 | 0.07 | 0.02 | [0.03, 0.12] | 3.27 + 4 | 0.05 | 0.02 | [0.01, 0.09] | 2.44 + + Variable predicted: cbind(incidence, size - incidence) + Predictors modulated: period + Random effects: Conditional on a typical cluster. + Predictions are on the response-scale. + diff --git a/tests/testthat/_snaps/joint_test.md b/tests/testthat/_snaps/joint_test.md index 2567a8d60..193122a89 100644 --- a/tests/testthat/_snaps/joint_test.md +++ b/tests/testthat/_snaps/joint_test.md @@ -3,7 +3,7 @@ Code estimate_contrasts(m, contrast = "time", by = "coffee", comparison = "joint") Output - Marginal Joint Test + Conditional Joint Test Contrast | coffee | df1 | df2 | F | p --------------------------------------------- diff --git a/tests/testthat/_snaps/plot-ordinal/plot-ordinal-bracl.svg b/tests/testthat/_snaps/plot-ordinal/plot-ordinal-bracl.svg index 6553f8ae2..48b824030 100644 --- a/tests/testthat/_snaps/plot-ordinal/plot-ordinal-bracl.svg +++ b/tests/testthat/_snaps/plot-ordinal/plot-ordinal-bracl.svg @@ -27,17 +27,17 @@ - - - - - - - + + + + + + + - - + + @@ -48,13 +48,13 @@ 10% 20% -30% +30% 40% 50% - + - + diff --git a/tests/testthat/_snaps/print.md b/tests/testthat/_snaps/print.md index e6edff890..a0ecea4ef 100644 --- a/tests/testthat/_snaps/print.md +++ b/tests/testthat/_snaps/print.md @@ -33,9 +33,9 @@ | 100 | high level of education | Female | 13.21 | 0.84 | (11.56, 14.85) | 15.75 | +=========+=================================+=========+=======+======+================+========+ | Variable predicted: neg_c_7
Predictors modulated: c12hour = c(50, 100), c172code, | - | c161sex
Predictors averaged: barthtot (65) | + | c161sex
Predictors held at: barthtot (65) | +=========+=================================+=========+=======+======+================+========+ - Table: Estimated Marginal Means + Table: Conditional Predictions # estimate_contrasts - by with special character @@ -43,7 +43,7 @@ print(estimate_contrasts(fit, "c172code", "barthtot = [sd]", backend = "marginaleffects", p_adjust = "holm"), table_width = Inf, zap_small = TRUE) Output - Marginal Contrasts Analysis + Conditional Contrasts Level1 | Level2 | barthtot | Difference | SE | 95% CI | t(810) | p -------------------------------------------------------------------------------- @@ -67,7 +67,7 @@ print(estimate_contrasts(fit, c("c172code", "barthtot = [sd]"), backend = "marginaleffects", p_adjust = "holm"), table_width = Inf, zap_small = TRUE) Output - Marginal Contrasts Analysis + Conditional Contrasts Level1 | Level2 | Difference | SE | 95% CI | t(810) | p ---------------------------------------------------------------------------------- @@ -118,7 +118,7 @@ print(estimate_contrasts(fit, "c172code", "barthtot = [sd]", backend = "marginaleffects"), table_width = Inf, zap_small = TRUE) Output - Marginal Contrasts Analysis + Conditional Contrasts Level1 | Level2 | barthtot | Difference | SE | 95% CI | t(810) | p ------------------------------------------------------------------------------- @@ -142,7 +142,7 @@ print(estimate_contrasts(fit, c("c172code", "barthtot = [sd]"), backend = "marginaleffects"), table_width = Inf, zap_small = TRUE) Output - Marginal Contrasts Analysis + Conditional Contrasts Level1 | Level2 | Difference | SE | 95% CI | t(810) | p ---------------------------------------------------------------------------------- @@ -194,7 +194,7 @@ "Female", "Male")), backend = "marginaleffects"), table_width = Inf, zap_small = TRUE) Output - Estimated Marginal Means + Conditional Predictions c172code | c161sex | Mean | SE | 95% CI | t(825) ----------------------------------------------------------- @@ -205,7 +205,7 @@ Variable predicted: neg_c_7 Predictors modulated: c172code = c('low', 'high'), c161sex = c('Female', 'Male') - Predictors averaged: e16sex + Predictors averaged over (balanced grid): e16sex --- @@ -214,7 +214,7 @@ "c161sex = c('Female', 'Male')"), backend = "marginaleffects"), table_width = Inf, zap_small = TRUE) Output - Estimated Marginal Means + Conditional Predictions c172code | c161sex | Mean | SE | 95% CI | t(825) ----------------------------------------------------------- @@ -225,14 +225,14 @@ Variable predicted: neg_c_7 Predictors modulated: c172code = c('low', 'high'), c161sex = c('Female', 'Male') - Predictors averaged: e16sex + Predictors averaged over (balanced grid): e16sex # estimate_epectation - don't print empty RE columns Code print(estimate_expectation(m, by = "spp", predict = "conditional"), zap_small = TRUE) Output - Model-based Predictions + Conditional Predictions spp | Predicted | SE | CI --------------------------------------- @@ -246,7 +246,7 @@ Variable predicted: count Predictors modulated: spp - Predictors controlled: mined (yes) + Predictors held at: mined (yes) Predictions are on the conditional-scale. # print - layouts and include data grid @@ -254,7 +254,7 @@ Code print(out) Output - Estimated Marginal Means + Conditional Predictions Species | Mean | SE | 95% CI | t(147) ------------------------------------------------ @@ -270,9 +270,9 @@ Code print(out, select = "minimal") Output - Estimated Marginal Means + Conditional Predictions - Species | Mean (CI) + Species | Mean (95% CI) ------------------------------ setosa | 1.46 (1.34, 1.58) versicolor | 4.26 (4.14, 4.38) @@ -286,13 +286,13 @@ Code print(out, select = "minimal") Output - Marginal Contrasts Analysis + Conditional Contrasts - Level1 | Level2 | Difference (CI) | p - ---------------------------------------------------- - versicolor | setosa | 2.80 (2.63, 2.97) | <0.001 - virginica | setosa | 4.09 (3.92, 4.26) | <0.001 - virginica | versicolor | 1.29 (1.12, 1.46) | <0.001 + Level1 | Level2 | Difference (95% CI) | p + ------------------------------------------------------ + versicolor | setosa | 2.80 (2.63, 2.97) | <0.001 + virginica | setosa | 4.09 (3.92, 4.26) | <0.001 + virginica | versicolor | 1.29 (1.12, 1.46) | <0.001 Variable predicted: Petal.Length Predictors contrasted: Species @@ -303,9 +303,9 @@ Code print(out, select = "{estimate}{stars}|{ci}") Output - Marginal Contrasts Analysis + Conditional Contrasts - Level1 | Level2 | Difference | CI + Level1 | Level2 | Difference | 95% CI ------------------------------------------------- versicolor | setosa | 2.80*** | 2.63, 2.97 virginica | setosa | 4.09*** | 3.92, 4.26 @@ -320,7 +320,7 @@ Code print(estimate_relation(m, by = "qsec")) Output - Model-based Predictions + Conditional Predictions qsec | Predicted | SE | 95% CI --------------------------------------- @@ -337,14 +337,14 @@ Variable predicted: wt Predictors modulated: qsec - Predictors controlled: mpg (20) + Predictors held at: mpg (20) --- Code print(estimate_relation(m, by = "qsec"), include_grid = TRUE) Output - Model-based Predictions + Conditional Predictions qsec | mpg | Predicted | SE | 95% CI ----------------------------------------------- @@ -361,5 +361,5 @@ Variable predicted: wt Predictors modulated: qsec - Predictors controlled: mpg (20) + Predictors held at: mpg (20) diff --git a/tests/testthat/_snaps/transform_response.md b/tests/testthat/_snaps/transform_response.md index 7d0fd64a3..c9b28abea 100644 --- a/tests/testthat/_snaps/transform_response.md +++ b/tests/testthat/_snaps/transform_response.md @@ -3,7 +3,7 @@ Code out Output - Estimated Marginal Means + Conditional Predictions speed | Mean | SE | 95% CI | t(48) ------------------------------------------ @@ -27,7 +27,7 @@ Code out1 Output - Estimated Marginal Means + Conditional Predictions speed | Mean | 95% CI | df ------------------------------------- diff --git a/tests/testthat/_snaps/windows/estimate_contrasts.md b/tests/testthat/_snaps/windows/estimate_contrasts.md index aa1afe550..833145bb6 100644 --- a/tests/testthat/_snaps/windows/estimate_contrasts.md +++ b/tests/testthat/_snaps/windows/estimate_contrasts.md @@ -4,7 +4,7 @@ print(estimate_contrasts(model, contrast = c("three", "vs", "am"), backend = "marginaleffects"), digits = 1, zap_small = TRUE, table_width = Inf) Output - Marginal Contrasts Analysis + Conditional Contrasts Level1 | Level2 | Difference | SE | 95% CI | t(24) | p ---------------------------------------------------------------------------------------------- @@ -47,7 +47,7 @@ print(estimate_contrasts(model, contrast = "am", backend = "marginaleffects"), zap_small = TRUE, table_width = Inf) Output - Marginal Contrasts Analysis + Conditional Contrasts Level1 | Level2 | Difference | SE | 95% CI | t(24) | p ------------------------------------------------------------------- @@ -55,6 +55,617 @@ Variable predicted: mpg Predictors contrasted: am - Predictors averaged: three, vs + Predictors averaged over (balanced grid): three, vs + p-values are uncorrected. + +# estimate_contrasts - filtering works + + Code + print(estimate_contrasts(fit, "c172code", backend = "marginaleffects"), + table_width = Inf, zap_small = TRUE) + Output + Conditional Contrasts + + Level1 | Level2 | Difference | SE | 95% CI | t(827) | p + -------------------------------------------------------------------- + mid | low | -0.09 | 0.34 | [-0.76, 0.58] | -0.25 | 0.802 + high | low | 0.61 | 0.43 | [-0.24, 1.45] | 1.40 | 0.162 + high | mid | 0.69 | 0.36 | [-0.02, 1.40] | 1.92 | 0.055 + + Variable predicted: neg_c_7 + Predictors contrasted: c172code + Predictors averaged over (balanced grid): e16sex, c161sex + p-values are uncorrected. + +--- + + Code + print(estimate_contrasts(fit, "c161sex", "c172code", backend = "marginaleffects"), + table_width = Inf, zap_small = TRUE) + Output + Conditional Contrasts + + Level1 | Level2 | c172code | Difference | SE | 95% CI | t(825) | p + ------------------------------------------------------------------------------- + Female | Male | low | 1.05 | 0.69 | [-0.31, 2.40] | 1.51 | 0.131 + Female | Male | mid | 0.56 | 0.42 | [-0.26, 1.38] | 1.35 | 0.178 + Female | Male | high | 0.96 | 0.69 | [-0.39, 2.30] | 1.40 | 0.163 + + Variable predicted: neg_c_7 + Predictors contrasted: c161sex + Predictors averaged over (balanced grid): e16sex + p-values are uncorrected. + +--- + + Code + print(estimate_slopes(fit, "barthtot", backend = "marginaleffects"), + table_width = Inf, zap_small = TRUE) + Output + Estimated Marginal Effects + + Slope | SE | 95% CI | t(810) | p + ----------------------------------------------- + -0.05 | 0.00 | [-0.06, -0.05] | -12.77 | < .001 + + Marginal effects estimated for barthtot + Type of slope was dY/dX + +--- + + Code + print(estimate_slopes(fit, "barthtot", by = "c172code", backend = "marginaleffects"), + table_width = Inf, zap_small = TRUE) + Output + Estimated Marginal Effects + + c172code | Slope | SE | 95% CI | t(808) | p + ---------------------------------------------------------- + low | -0.06 | 0.01 | [-0.08, -0.05] | -7.08 | < .001 + mid | -0.05 | 0.01 | [-0.06, -0.04] | -9.82 | < .001 + high | -0.05 | 0.01 | [-0.07, -0.03] | -4.53 | < .001 + + Marginal effects estimated for barthtot + Type of slope was dY/dX + +--- + + Code + print(estimate_contrasts(fit, "barthtot", "c172code", backend = "marginaleffects"), + table_width = Inf, zap_small = TRUE) + Output + Conditional Contrasts + + Level1 | Level2 | Difference | SE | 95% CI | t(808) | p + -------------------------------------------------------------------- + mid | low | 0.01 | 0.01 | [-0.01, 0.03] | 1.17 | 0.243 + high | low | 0.02 | 0.01 | [-0.01, 0.04] | 1.10 | 0.270 + high | mid | 0.00 | 0.01 | [-0.02, 0.03] | 0.27 | 0.786 + + Variable predicted: neg_c_7 + Predictors contrasted: barthtot + Predictors held at: barthtot (65) + Predictors averaged over (balanced grid): e16sex + p-values are uncorrected. + +--- + + Code + print(estimate_contrasts(fit, "barthtot", c("c172code", "e16sex"), backend = "marginaleffects"), + table_width = Inf, zap_small = TRUE) + Output + Conditional Contrasts + + Level1 | Level2 | Difference | SE | 95% CI | t(803) | p + ------------------------------------------------------------------------------- + low, female | low, male | -0.01 | 0.02 | [-0.04, 0.03] | -0.35 | 0.729 + mid, male | low, male | -0.01 | 0.02 | [-0.04, 0.02] | -0.46 | 0.648 + mid, female | low, male | 0.02 | 0.01 | [-0.01, 0.05] | 1.24 | 0.217 + high, male | low, male | 0.00 | 0.02 | [-0.05, 0.04] | -0.16 | 0.876 + high, female | low, male | 0.02 | 0.02 | [-0.01, 0.06] | 1.19 | 0.236 + mid, male | low, female | 0.00 | 0.02 | [-0.03, 0.03] | -0.08 | 0.940 + mid, female | low, female | 0.02 | 0.01 | [ 0.00, 0.05] | 1.76 | 0.079 + high, male | low, female | 0.00 | 0.02 | [-0.04, 0.05] | 0.12 | 0.908 + high, female | low, female | 0.03 | 0.02 | [-0.01, 0.06] | 1.58 | 0.115 + mid, female | mid, male | 0.03 | 0.01 | [ 0.00, 0.05] | 2.23 | 0.026 + high, male | mid, male | 0.00 | 0.02 | [-0.04, 0.05] | 0.18 | 0.859 + high, female | mid, male | 0.03 | 0.02 | [ 0.00, 0.06] | 1.83 | 0.068 + high, male | mid, female | -0.02 | 0.02 | [-0.06, 0.02] | -1.08 | 0.280 + high, female | mid, female | 0.00 | 0.01 | [-0.02, 0.03] | 0.26 | 0.792 + high, female | high, male | 0.03 | 0.02 | [-0.02, 0.07] | 1.11 | 0.269 + + Variable predicted: neg_c_7 + Predictors contrasted: barthtot + Predictors held at: barthtot (65) + p-values are uncorrected. + +# estimate_contrasts - simple contrasts and with - in levels works + + Code + print(estimate_contrasts(model, "Species", backend = "marginaleffects"), + table_width = Inf) + Output + Conditional Contrasts + + Level1 | Level2 | Difference | SE | 95% CI | t(146) | p + ---------------------------------------------------------------------------- + versicolor | setosa | 1.46 | 0.11 | [1.24, 1.68] | 13.01 | < .001 + virginica | setosa | 1.95 | 0.10 | [1.75, 2.14] | 19.47 | < .001 + virginica | versicolor | 0.49 | 0.09 | [0.31, 0.67] | 5.41 | < .001 + + Variable predicted: Sepal.Length + Predictors contrasted: Species + Predictors held at: Sepal.Width (3.1) + p-values are uncorrected. + +--- + + Code + print(estimate_contrasts(m, c("time", "coffee"), backend = "marginaleffects"), + zap_small = TRUE, table_width = Inf) + Output + Conditional Contrasts + + Level1 | Level2 | Difference | SE | 95% CI | t(113) | p + --------------------------------------------------------------------------------------------- + morning, control | morning, coffee | -5.78 | 1.99 | [-9.73, -1.83] | -2.90 | 0.004 + noon, coffee | morning, coffee | -1.93 | 1.99 | [-5.88, 2.02] | -0.97 | 0.336 + noon, control | morning, coffee | 0.00 | 1.99 | [-3.95, 3.95] | 0.00 | > .999 + afternoon, coffee | morning, coffee | 1.93 | 1.99 | [-2.02, 5.88] | 0.97 | 0.336 + afternoon, control | morning, coffee | 0.00 | 1.99 | [-3.95, 3.95] | 0.00 | > .999 + noon, coffee | morning, control | 3.86 | 1.99 | [-0.09, 7.81] | 1.93 | 0.056 + noon, control | morning, control | 5.78 | 1.99 | [ 1.83, 9.73] | 2.90 | 0.004 + afternoon, coffee | morning, control | 7.71 | 1.99 | [ 3.76, 11.66] | 3.87 | < .001 + afternoon, control | morning, control | 5.78 | 1.99 | [ 1.83, 9.73] | 2.90 | 0.004 + noon, control | noon, coffee | 1.93 | 1.99 | [-2.02, 5.88] | 0.97 | 0.336 + afternoon, coffee | noon, coffee | 3.86 | 1.99 | [-0.09, 7.81] | 1.93 | 0.056 + afternoon, control | noon, coffee | 1.93 | 1.99 | [-2.02, 5.88] | 0.97 | 0.336 + afternoon, coffee | noon, control | 1.93 | 1.99 | [-2.02, 5.88] | 0.97 | 0.336 + afternoon, control | noon, control | 0.00 | 1.99 | [-3.95, 3.95] | 0.00 | > .999 + afternoon, control | afternoon, coffee | -1.93 | 1.99 | [-5.88, 2.02] | -0.97 | 0.336 + + Variable predicted: alertness + Predictors contrasted: time, coffee + Predictors averaged over (balanced grid): sex + p-values are uncorrected. + +--- + + Code + print(estimate_contrasts(m, contrast = "time", by = "coffee", backend = "marginaleffects"), + zap_small = TRUE, table_width = Inf) + Output + Conditional Contrasts + + Level1 | Level2 | coffee | Difference | SE | 95% CI | t(113) | p + ----------------------------------------------------------------------------------- + noon | morning | coffee | -1.93 | 1.99 | [-5.88, 2.02] | -0.97 | 0.336 + afternoon | morning | coffee | 1.93 | 1.99 | [-2.02, 5.88] | 0.97 | 0.336 + afternoon | noon | coffee | 3.86 | 1.99 | [-0.09, 7.81] | 1.93 | 0.056 + noon | morning | control | 5.78 | 1.99 | [ 1.83, 9.73] | 2.90 | 0.004 + afternoon | morning | control | 5.78 | 1.99 | [ 1.83, 9.73] | 2.90 | 0.004 + afternoon | noon | control | 0.00 | 1.99 | [-3.95, 3.95] | 0.00 | > .999 + + Variable predicted: alertness + Predictors contrasted: time + Predictors averaged over (balanced grid): sex + p-values are uncorrected. + +--- + + Code + print(estimate_contrasts(model, contrast = c("mined", "spp"), backend = "marginaleffects"), + zap_small = TRUE, table_width = Inf) + Output + Conditional Contrasts + + Level1 | Level2 | Difference | SE | 95% CI | z | p + ----------------------------------------------------------------------------- + yes, PR | yes, GP | 0.06 | 0.05 | [-0.04, 0.16] | 1.10 | 0.271 + yes, DM | yes, GP | 0.32 | 0.11 | [ 0.10, 0.54] | 2.89 | 0.004 + yes, EC-A | yes, GP | 0.04 | 0.05 | [-0.05, 0.13] | 0.80 | 0.421 + yes, EC-L | yes, GP | 0.17 | 0.08 | [ 0.02, 0.32] | 2.19 | 0.028 + yes, DES-L | yes, GP | 0.43 | 0.14 | [ 0.17, 0.70] | 3.19 | 0.001 + yes, DF | yes, GP | 0.43 | 0.14 | [ 0.17, 0.70] | 3.19 | 0.001 + no, GP | yes, GP | 2.59 | 0.55 | [ 1.50, 3.67] | 4.67 | < .001 + no, PR | yes, GP | 0.51 | 0.16 | [ 0.20, 0.82] | 3.21 | 0.001 + no, DM | yes, GP | 2.86 | 0.61 | [ 1.68, 4.05] | 4.73 | < .001 + no, EC-A | yes, GP | 1.10 | 0.27 | [ 0.57, 1.64] | 4.03 | < .001 + no, EC-L | yes, GP | 4.67 | 0.94 | [ 2.82, 6.52] | 4.95 | < .001 + no, DES-L | yes, GP | 4.62 | 0.93 | [ 2.79, 6.45] | 4.95 | < .001 + no, DF | yes, GP | 2.24 | 0.49 | [ 1.28, 3.20] | 4.58 | < .001 + yes, DM | yes, PR | 0.26 | 0.11 | [ 0.05, 0.48] | 2.43 | 0.015 + yes, EC-A | yes, PR | -0.02 | 0.06 | [-0.13, 0.09] | -0.33 | 0.740 + yes, EC-L | yes, PR | 0.11 | 0.08 | [-0.04, 0.27] | 1.43 | 0.154 + yes, DES-L | yes, PR | 0.38 | 0.13 | [ 0.12, 0.64] | 2.86 | 0.004 + yes, DF | yes, PR | 0.38 | 0.13 | [ 0.12, 0.64] | 2.86 | 0.004 + no, GP | yes, PR | 2.53 | 0.56 | [ 1.44, 3.62] | 4.54 | < .001 + no, PR | yes, PR | 0.45 | 0.16 | [ 0.13, 0.77] | 2.75 | 0.006 + no, DM | yes, PR | 2.80 | 0.61 | [ 1.61, 4.00] | 4.61 | < .001 + no, EC-A | yes, PR | 1.05 | 0.28 | [ 0.50, 1.59] | 3.76 | < .001 + no, EC-L | yes, PR | 4.61 | 0.95 | [ 2.76, 6.47] | 4.87 | < .001 + no, DES-L | yes, PR | 4.56 | 0.94 | [ 2.73, 6.40] | 4.87 | < .001 + no, DF | yes, PR | 2.18 | 0.49 | [ 1.22, 3.15] | 4.44 | < .001 + yes, EC-A | yes, DM | -0.28 | 0.11 | [-0.50, -0.07] | -2.59 | 0.010 + yes, EC-L | yes, DM | -0.15 | 0.11 | [-0.36, 0.06] | -1.39 | 0.164 + yes, DES-L | yes, DM | 0.11 | 0.13 | [-0.14, 0.36] | 0.89 | 0.375 + yes, DF | yes, DM | 0.11 | 0.13 | [-0.14, 0.36] | 0.89 | 0.375 + no, GP | yes, DM | 2.27 | 0.58 | [ 1.14, 3.40] | 3.93 | < .001 + no, PR | yes, DM | 0.19 | 0.20 | [-0.21, 0.58] | 0.93 | 0.352 + no, DM | yes, DM | 2.54 | 0.63 | [ 1.31, 3.77] | 4.04 | < .001 + no, EC-A | yes, DM | 0.78 | 0.31 | [ 0.18, 1.38] | 2.56 | 0.011 + no, EC-L | yes, DM | 4.35 | 0.96 | [ 2.46, 6.24] | 4.51 | < .001 + no, DES-L | yes, DM | 4.30 | 0.95 | [ 2.43, 6.17] | 4.51 | < .001 + no, DF | yes, DM | 1.92 | 0.51 | [ 0.91, 2.93] | 3.74 | < .001 + yes, EC-L | yes, EC-A | 0.13 | 0.08 | [-0.02, 0.29] | 1.68 | 0.093 + yes, DES-L | yes, EC-A | 0.40 | 0.13 | [ 0.14, 0.66] | 2.97 | 0.003 + yes, DF | yes, EC-A | 0.40 | 0.13 | [ 0.14, 0.66] | 2.97 | 0.003 + no, GP | yes, EC-A | 2.55 | 0.56 | [ 1.46, 3.64] | 4.58 | < .001 + no, PR | yes, EC-A | 0.47 | 0.16 | [ 0.15, 0.79] | 2.90 | 0.004 + no, DM | yes, EC-A | 2.82 | 0.61 | [ 1.63, 4.01] | 4.65 | < .001 + no, EC-A | yes, EC-A | 1.06 | 0.28 | [ 0.52, 1.61] | 3.85 | < .001 + no, EC-L | yes, EC-A | 4.63 | 0.95 | [ 2.78, 6.48] | 4.90 | < .001 + no, DES-L | yes, EC-A | 4.58 | 0.94 | [ 2.75, 6.42] | 4.90 | < .001 + no, DF | yes, EC-A | 2.20 | 0.49 | [ 1.24, 3.17] | 4.49 | < .001 + yes, DES-L | yes, EC-L | 0.26 | 0.13 | [ 0.02, 0.51] | 2.08 | 0.037 + yes, DF | yes, EC-L | 0.26 | 0.13 | [ 0.02, 0.51] | 2.08 | 0.037 + no, GP | yes, EC-L | 2.42 | 0.57 | [ 1.31, 3.53] | 4.28 | < .001 + no, PR | yes, EC-L | 0.34 | 0.18 | [-0.01, 0.69] | 1.89 | 0.058 + no, DM | yes, EC-L | 2.69 | 0.62 | [ 1.48, 3.90] | 4.37 | < .001 + no, EC-A | yes, EC-L | 0.93 | 0.29 | [ 0.37, 1.50] | 3.23 | 0.001 + no, EC-L | yes, EC-L | 4.50 | 0.95 | [ 2.63, 6.37] | 4.72 | < .001 + no, DES-L | yes, EC-L | 4.45 | 0.94 | [ 2.60, 6.30] | 4.71 | < .001 + no, DF | yes, EC-L | 2.07 | 0.50 | [ 1.09, 3.05] | 4.14 | < .001 + yes, DF | yes, DES-L | 0.00 | 0.13 | [-0.26, 0.26] | 0.00 | > .999 + no, GP | yes, DES-L | 2.15 | 0.59 | [ 1.00, 3.31] | 3.67 | < .001 + no, PR | yes, DES-L | 0.07 | 0.22 | [-0.36, 0.50] | 0.33 | 0.738 + no, DM | yes, DES-L | 2.43 | 0.64 | [ 1.18, 3.68] | 3.81 | < .001 + no, EC-A | yes, DES-L | 0.67 | 0.32 | [ 0.04, 1.29] | 2.09 | 0.037 + no, EC-L | yes, DES-L | 4.24 | 0.97 | [ 2.33, 6.14] | 4.36 | < .001 + no, DES-L | yes, DES-L | 4.19 | 0.96 | [ 2.30, 6.07] | 4.35 | < .001 + no, DF | yes, DES-L | 1.81 | 0.52 | [ 0.78, 2.83] | 3.45 | < .001 + no, GP | yes, DF | 2.15 | 0.59 | [ 1.00, 3.31] | 3.67 | < .001 + no, PR | yes, DF | 0.07 | 0.22 | [-0.36, 0.50] | 0.33 | 0.738 + no, DM | yes, DF | 2.43 | 0.64 | [ 1.18, 3.68] | 3.81 | < .001 + no, EC-A | yes, DF | 0.67 | 0.32 | [ 0.04, 1.29] | 2.09 | 0.037 + no, EC-L | yes, DF | 4.24 | 0.97 | [ 2.33, 6.14] | 4.36 | < .001 + no, DES-L | yes, DF | 4.19 | 0.96 | [ 2.30, 6.07] | 4.35 | < .001 + no, DF | yes, DF | 1.81 | 0.52 | [ 0.78, 2.83] | 3.45 | < .001 + no, PR | no, GP | -2.08 | 0.48 | [-3.02, -1.14] | -4.35 | < .001 + no, DM | no, GP | 0.27 | 0.37 | [-0.46, 1.00] | 0.73 | 0.466 + no, EC-A | no, GP | -1.49 | 0.41 | [-2.29, -0.68] | -3.61 | < .001 + no, EC-L | no, GP | 2.08 | 0.58 | [ 0.95, 3.21] | 3.61 | < .001 + no, DES-L | no, GP | 2.03 | 0.57 | [ 0.92, 3.15] | 3.57 | < .001 + no, DF | no, GP | -0.35 | 0.35 | [-1.04, 0.35] | -0.98 | 0.328 + no, DM | no, PR | 2.35 | 0.53 | [ 1.32, 3.39] | 4.47 | < .001 + no, EC-A | no, PR | 0.59 | 0.23 | [ 0.14, 1.05] | 2.56 | 0.011 + no, EC-L | no, PR | 4.16 | 0.86 | [ 2.49, 5.84] | 4.87 | < .001 + no, DES-L | no, PR | 4.11 | 0.85 | [ 2.45, 5.77] | 4.86 | < .001 + no, DF | no, PR | 1.73 | 0.42 | [ 0.92, 2.55] | 4.15 | < .001 + no, EC-A | no, DM | -1.76 | 0.46 | [-2.65, -0.87] | -3.86 | < .001 + no, EC-L | no, DM | 1.81 | 0.55 | [ 0.73, 2.89] | 3.29 | < .001 + no, DES-L | no, DM | 1.76 | 0.54 | [ 0.70, 2.82] | 3.24 | 0.001 + no, DF | no, DM | -0.62 | 0.38 | [-1.36, 0.12] | -1.65 | 0.100 + no, EC-L | no, EC-A | 3.57 | 0.77 | [ 2.07, 5.07] | 4.66 | < .001 + no, DES-L | no, EC-A | 3.52 | 0.76 | [ 2.03, 5.00] | 4.65 | < .001 + no, DF | no, EC-A | 1.14 | 0.36 | [ 0.43, 1.85] | 3.16 | 0.002 + no, DES-L | no, EC-L | -0.05 | 0.48 | [-0.99, 0.89] | -0.10 | 0.918 + no, DF | no, EC-L | -2.43 | 0.61 | [-3.63, -1.22] | -3.95 | < .001 + no, DF | no, DES-L | -2.38 | 0.61 | [-3.57, -1.19] | -3.92 | < .001 + + Variable predicted: count + Predictors contrasted: mined, spp + Predictors held at: cover (8.7e-11) + Random effects: Averaged over a balanced grid of cluster levels. + p-values are uncorrected. + Contrasts are on the response-scale. + +--- + + Code + print(estimate_contrasts(model, contrast = "mined", by = "spp", backend = "marginaleffects"), + zap_small = TRUE, table_width = Inf) + Output + Conditional Contrasts + + Level1 | Level2 | spp | Difference | SE | 95% CI | z | p + -------------------------------------------------------------------------- + no | yes | GP | 2.59 | 0.55 | [1.50, 3.67] | 4.67 | < .001 + no | yes | PR | 0.45 | 0.16 | [0.13, 0.77] | 2.75 | 0.006 + no | yes | DM | 2.54 | 0.63 | [1.31, 3.77] | 4.04 | < .001 + no | yes | EC-A | 1.06 | 0.28 | [0.52, 1.61] | 3.85 | < .001 + no | yes | EC-L | 4.50 | 0.95 | [2.63, 6.37] | 4.72 | < .001 + no | yes | DES-L | 4.19 | 0.96 | [2.30, 6.07] | 4.35 | < .001 + no | yes | DF | 1.81 | 0.52 | [0.78, 2.83] | 3.45 | < .001 + + Variable predicted: count + Predictors contrasted: mined + Predictors held at: cover (8.7e-11) + Random effects: Averaged over a balanced grid of cluster levels. + p-values are uncorrected. + Contrasts are on the response-scale. + +# estimate_contrasts - examples from docs work as intendec + + Code + print(estimate_contrasts(model, contrast = c("Species", "Petal.Width"), length = 2), + zap_small = TRUE, table_width = Inf) + Output + Conditional Contrasts + + Level1 | Level2 | Difference | SE | 95% CI | t(144) | p + ---------------------------------------------------------------------------------------- + setosa, 2.5 | setosa, 0.1 | 2.01 | 0.98 | [ 0.08, 3.94] | 2.06 | 0.041 + versicolor, 0.1 | setosa, 0.1 | -1.83 | 0.28 | [-2.38, -1.28] | -6.55 | < .001 + versicolor, 2.5 | setosa, 0.1 | 0.70 | 0.27 | [ 0.17, 1.23] | 2.61 | 0.010 + virginica, 0.1 | setosa, 0.1 | -1.55 | 0.31 | [-2.17, -0.93] | -4.95 | < .001 + virginica, 2.5 | setosa, 0.1 | -0.03 | 0.11 | [-0.25, 0.19] | -0.29 | 0.773 + versicolor, 0.1 | setosa, 2.5 | -3.84 | 0.96 | [-5.73, -1.95] | -4.01 | < .001 + versicolor, 2.5 | setosa, 2.5 | -1.31 | 0.95 | [-3.19, 0.58] | -1.37 | 0.172 + virginica, 0.1 | setosa, 2.5 | -3.56 | 0.97 | [-5.47, -1.65] | -3.68 | < .001 + virginica, 2.5 | setosa, 2.5 | -2.04 | 0.92 | [-3.86, -0.22] | -2.21 | 0.028 + versicolor, 2.5 | versicolor, 0.1 | 2.53 | 0.52 | [ 1.50, 3.56] | 4.86 | < .001 + virginica, 0.1 | versicolor, 0.1 | 0.28 | 0.41 | [-0.52, 1.08] | 0.69 | 0.492 + virginica, 2.5 | versicolor, 0.1 | 1.80 | 0.28 | [ 1.24, 2.35] | 6.35 | < .001 + virginica, 0.1 | versicolor, 2.5 | -2.25 | 0.40 | [-3.04, -1.46] | -5.64 | < .001 + virginica, 2.5 | versicolor, 2.5 | -0.73 | 0.27 | [-1.27, -0.20] | -2.70 | 0.008 + virginica, 2.5 | virginica, 0.1 | 1.52 | 0.37 | [ 0.77, 2.26] | 4.04 | < .001 + + Variable predicted: Sepal.Width + Predictors contrasted: Species, Petal.Width + p-values are uncorrected. + +--- + + Code + print(estimate_contrasts(model, contrast = c("Species", "Petal.Width=c(1, 2)")), + zap_small = TRUE, table_width = Inf) + Output + Conditional Contrasts + + Level1 | Level2 | Difference | SE | 95% CI | t(144) | p + ------------------------------------------------------------------------------------ + setosa, 2 | setosa, 1 | 0.84 | 0.41 | [ 0.03, 1.64] | 2.06 | 0.041 + versicolor, 1 | setosa, 1 | -1.63 | 0.32 | [-2.27, -1.00] | -5.09 | < .001 + versicolor, 2 | setosa, 1 | -0.58 | 0.35 | [-1.26, 0.10] | -1.68 | 0.096 + virginica, 1 | setosa, 1 | -1.73 | 0.35 | [-2.43, -1.04] | -4.93 | < .001 + virginica, 2 | setosa, 1 | -1.10 | 0.31 | [-1.72, -0.48] | -3.52 | < .001 + versicolor, 1 | setosa, 2 | -2.47 | 0.72 | [-3.89, -1.05] | -3.43 | < .001 + versicolor, 2 | setosa, 2 | -1.42 | 0.73 | [-2.86, 0.03] | -1.94 | 0.055 + virginica, 1 | setosa, 2 | -2.57 | 0.73 | [-4.02, -1.12] | -3.50 | < .001 + virginica, 2 | setosa, 2 | -1.94 | 0.72 | [-3.35, -0.52] | -2.71 | 0.008 + versicolor, 2 | versicolor, 1 | 1.05 | 0.22 | [ 0.62, 1.48] | 4.86 | < .001 + virginica, 1 | versicolor, 1 | -0.10 | 0.19 | [-0.47, 0.27] | -0.54 | 0.589 + virginica, 2 | versicolor, 1 | 0.53 | 0.09 | [ 0.35, 0.71] | 5.72 | < .001 + virginica, 1 | versicolor, 2 | -1.15 | 0.23 | [-1.60, -0.71] | -5.13 | < .001 + virginica, 2 | versicolor, 2 | -0.52 | 0.16 | [-0.84, -0.21] | -3.31 | 0.001 + virginica, 2 | virginica, 1 | 0.63 | 0.16 | [ 0.32, 0.94] | 4.04 | < .001 + + Variable predicted: Sepal.Width + Predictors contrasted: Species, Petal.Width=c(1, 2) + p-values are uncorrected. + +--- + + Code + print(estimate_contrasts(model, by = "Petal.Width", length = 4), zap_small = TRUE, + table_width = Inf) + Message + We selected `contrast=c("Species")`. + Output + Conditional Contrasts + + Level1 | Level2 | Petal.Width | Difference | SE | 95% CI | t(144) | p + -------------------------------------------------------------------------------------------- + versicolor | setosa | 0.10 | -1.83 | 0.28 | [-2.38, -1.28] | -6.55 | < .001 + virginica | setosa | 0.10 | -1.55 | 0.31 | [-2.17, -0.93] | -4.95 | < .001 + virginica | versicolor | 0.10 | 0.28 | 0.41 | [-0.52, 1.08] | 0.69 | 0.492 + versicolor | setosa | 0.90 | -1.65 | 0.29 | [-2.22, -1.08] | -5.74 | < .001 + virginica | setosa | 0.90 | -1.71 | 0.32 | [-2.35, -1.07] | -5.28 | < .001 + virginica | versicolor | 0.90 | -0.06 | 0.21 | [-0.47, 0.35] | -0.28 | 0.780 + versicolor | setosa | 1.70 | -1.48 | 0.60 | [-2.67, -0.29] | -2.47 | 0.015 + virginica | setosa | 1.70 | -1.88 | 0.60 | [-3.06, -0.70] | -3.14 | 0.002 + virginica | versicolor | 1.70 | -0.40 | 0.11 | [-0.62, -0.17] | -3.50 | < .001 + versicolor | setosa | 2.50 | -1.31 | 0.95 | [-3.19, 0.58] | -1.37 | 0.172 + virginica | setosa | 2.50 | -2.04 | 0.92 | [-3.86, -0.22] | -2.21 | 0.028 + virginica | versicolor | 2.50 | -0.73 | 0.27 | [-1.27, -0.20] | -2.70 | 0.008 + + Variable predicted: Sepal.Width + Predictors contrasted: Species + p-values are uncorrected. + +# estimate_contrasts - test all combinations of contrast and by, with filtering + + Code + print(estimate_contrasts(model2, c("grp", "time", "x")), zap_small = TRUE, + table_width = Inf) + Output + Conditional Contrasts + + Level1 | Level2 | Difference | SE | 95% CI | t(992) | p + -------------------------------------------------------------------------------------- + control, 1, b | control, 1, a | 0.15 | 0.13 | [-0.10, 0.40] | 1.20 | 0.231 + control, 2, a | control, 1, a | 0.03 | 0.13 | [-0.23, 0.28] | 0.19 | 0.847 + control, 2, b | control, 1, a | 0.09 | 0.13 | [-0.16, 0.34] | 0.73 | 0.465 + treatment, 1, a | control, 1, a | 0.19 | 0.13 | [-0.06, 0.45] | 1.49 | 0.137 + treatment, 1, b | control, 1, a | -0.03 | 0.13 | [-0.28, 0.22] | -0.22 | 0.824 + treatment, 2, a | control, 1, a | 0.02 | 0.13 | [-0.23, 0.27] | 0.19 | 0.850 + treatment, 2, b | control, 1, a | 0.05 | 0.12 | [-0.19, 0.28] | 0.37 | 0.712 + control, 2, a | control, 1, b | -0.12 | 0.13 | [-0.38, 0.13] | -0.97 | 0.332 + control, 2, b | control, 1, b | -0.06 | 0.12 | [-0.30, 0.19] | -0.46 | 0.648 + treatment, 1, a | control, 1, b | 0.04 | 0.13 | [-0.20, 0.29] | 0.34 | 0.730 + treatment, 1, b | control, 1, b | -0.18 | 0.12 | [-0.42, 0.06] | -1.45 | 0.147 + treatment, 2, a | control, 1, b | -0.13 | 0.12 | [-0.37, 0.12] | -1.02 | 0.307 + treatment, 2, b | control, 1, b | -0.10 | 0.12 | [-0.34, 0.13] | -0.89 | 0.376 + control, 2, b | control, 2, a | 0.07 | 0.13 | [-0.19, 0.32] | 0.52 | 0.604 + treatment, 1, a | control, 2, a | 0.17 | 0.13 | [-0.09, 0.43] | 1.26 | 0.207 + treatment, 1, b | control, 2, a | -0.05 | 0.13 | [-0.31, 0.20] | -0.41 | 0.680 + treatment, 2, a | control, 2, a | 0.00 | 0.13 | [-0.26, 0.25] | -0.01 | 0.991 + treatment, 2, b | control, 2, a | 0.02 | 0.13 | [-0.23, 0.27] | 0.16 | 0.876 + treatment, 1, a | control, 2, b | 0.10 | 0.13 | [-0.15, 0.35] | 0.78 | 0.437 + treatment, 1, b | control, 2, b | -0.12 | 0.13 | [-0.37, 0.12] | -0.97 | 0.333 + treatment, 2, a | control, 2, b | -0.07 | 0.13 | [-0.32, 0.18] | -0.55 | 0.582 + treatment, 2, b | control, 2, b | -0.05 | 0.12 | [-0.29, 0.19] | -0.40 | 0.691 + treatment, 1, b | treatment, 1, a | -0.22 | 0.13 | [-0.47, 0.03] | -1.73 | 0.083 + treatment, 2, a | treatment, 1, a | -0.17 | 0.13 | [-0.42, 0.08] | -1.32 | 0.187 + treatment, 2, b | treatment, 1, a | -0.15 | 0.12 | [-0.39, 0.09] | -1.20 | 0.230 + treatment, 2, a | treatment, 1, b | 0.05 | 0.12 | [-0.19, 0.30] | 0.42 | 0.676 + treatment, 2, b | treatment, 1, b | 0.07 | 0.12 | [-0.16, 0.31] | 0.61 | 0.541 + treatment, 2, b | treatment, 2, a | 0.02 | 0.12 | [-0.21, 0.26] | 0.18 | 0.861 + + Variable predicted: score + Predictors contrasted: grp, time, x + p-values are uncorrected. + +--- + + Code + print(estimate_contrasts(model2, c("grp", "time"), by = "x"), zap_small = TRUE, + table_width = Inf) + Output + Conditional Contrasts + + Level1 | Level2 | x | Difference | SE | 95% CI | t(992) | p + ------------------------------------------------------------------------------------ + control, 2 | control, 1 | a | 0.03 | 0.13 | [-0.23, 0.28] | 0.19 | 0.847 + treatment, 1 | control, 1 | a | 0.19 | 0.13 | [-0.06, 0.45] | 1.49 | 0.137 + treatment, 2 | control, 1 | a | 0.02 | 0.13 | [-0.23, 0.27] | 0.19 | 0.850 + treatment, 1 | control, 2 | a | 0.17 | 0.13 | [-0.09, 0.43] | 1.26 | 0.207 + treatment, 2 | control, 2 | a | 0.00 | 0.13 | [-0.26, 0.25] | -0.01 | 0.991 + treatment, 2 | treatment, 1 | a | -0.17 | 0.13 | [-0.42, 0.08] | -1.32 | 0.187 + control, 2 | control, 1 | b | -0.06 | 0.12 | [-0.30, 0.19] | -0.46 | 0.648 + treatment, 1 | control, 1 | b | -0.18 | 0.12 | [-0.42, 0.06] | -1.45 | 0.147 + treatment, 2 | control, 1 | b | -0.10 | 0.12 | [-0.34, 0.13] | -0.89 | 0.376 + treatment, 1 | control, 2 | b | -0.12 | 0.13 | [-0.37, 0.12] | -0.97 | 0.333 + treatment, 2 | control, 2 | b | -0.05 | 0.12 | [-0.29, 0.19] | -0.40 | 0.691 + treatment, 2 | treatment, 1 | b | 0.07 | 0.12 | [-0.16, 0.31] | 0.61 | 0.541 + + Variable predicted: score + Predictors contrasted: grp, time + p-values are uncorrected. + +--- + + Code + print(estimate_contrasts(model2, "grp", by = c("time", "x")), zap_small = TRUE, + table_width = Inf) + Output + Conditional Contrasts + + Level1 | Level2 | time | x | Difference | SE | 95% CI | t(992) | p + ----------------------------------------------------------------------------------- + treatment | control | 1 | a | 0.19 | 0.13 | [-0.06, 0.45] | 1.49 | 0.137 + treatment | control | 2 | a | 0.00 | 0.13 | [-0.26, 0.25] | -0.01 | 0.991 + treatment | control | 1 | b | -0.18 | 0.12 | [-0.42, 0.06] | -1.45 | 0.147 + treatment | control | 2 | b | -0.05 | 0.12 | [-0.29, 0.19] | -0.40 | 0.691 + + Variable predicted: score + Predictors contrasted: grp + p-values are uncorrected. + +--- + + Code + print(estimate_contrasts(model2, "grp", by = "time"), zap_small = TRUE, + table_width = Inf) + Output + Conditional Contrasts + + Level1 | Level2 | time | Difference | SE | 95% CI | t(992) | p + ------------------------------------------------------------------------------- + treatment | control | 1 | 0.01 | 0.09 | [-0.17, 0.18] | 0.09 | 0.931 + treatment | control | 2 | -0.02 | 0.09 | [-0.20, 0.15] | -0.28 | 0.780 + + Variable predicted: score + Predictors contrasted: grp + Predictors averaged over (balanced grid): x + p-values are uncorrected. + +--- + + Code + print(estimate_contrasts(model2, c("grp", "time", "x='a'")), zap_small = TRUE, + table_width = Inf) + Output + Conditional Contrasts + + Level1 | Level2 | Difference | SE | 95% CI | t(992) | p + -------------------------------------------------------------------------------- + control, 2 | control, 1 | 0.03 | 0.13 | [-0.23, 0.28] | 0.19 | 0.847 + treatment, 1 | control, 1 | 0.19 | 0.13 | [-0.06, 0.45] | 1.49 | 0.137 + treatment, 2 | control, 1 | 0.02 | 0.13 | [-0.23, 0.27] | 0.19 | 0.850 + treatment, 1 | control, 2 | 0.17 | 0.13 | [-0.09, 0.43] | 1.26 | 0.207 + treatment, 2 | control, 2 | 0.00 | 0.13 | [-0.26, 0.25] | -0.01 | 0.991 + treatment, 2 | treatment, 1 | -0.17 | 0.13 | [-0.42, 0.08] | -1.32 | 0.187 + + Variable predicted: score + Predictors contrasted: grp, time, x='a' + p-values are uncorrected. + +--- + + Code + print(estimate_contrasts(model2, c("grp", "time=1"), by = "x"), zap_small = TRUE, + table_width = Inf) + Output + Conditional Contrasts + + Level1 | Level2 | x | Difference | SE | 95% CI | t(992) | p + ---------------------------------------------------------------------------- + treatment | control | a | 0.19 | 0.13 | [-0.06, 0.45] | 1.49 | 0.137 + treatment | control | b | -0.18 | 0.12 | [-0.42, 0.06] | -1.45 | 0.147 + + Variable predicted: score + Predictors contrasted: grp, time=1 + p-values are uncorrected. + +--- + + Code + print(estimate_contrasts(model2, "grp", by = c("time", "x='a'")), zap_small = TRUE, + table_width = Inf) + Output + Conditional Contrasts + + Level1 | Level2 | time | x | Difference | SE | 95% CI | t(992) | p + ----------------------------------------------------------------------------------- + treatment | control | 1 | a | 0.19 | 0.13 | [-0.06, 0.45] | 1.49 | 0.137 + treatment | control | 2 | a | 0.00 | 0.13 | [-0.26, 0.25] | -0.01 | 0.991 + + Variable predicted: score + Predictors contrasted: grp + p-values are uncorrected. + +--- + + Code + print(estimate_contrasts(model2, "time=c(1,2)", by = "grp"), zap_small = TRUE, + table_width = Inf) + Output + Conditional Contrasts + + Level1 | Level2 | grp | Difference | SE | 95% CI | t(994) | p + -------------------------------------------------------------------------------- + 2 | 1 | control | 0.14 | 0.11 | [-0.08, 0.36] | 1.24 | 0.216 + 2 | 1 | treatment | -0.07 | 0.11 | [-0.28, 0.14] | -0.63 | 0.529 + + Variable predicted: score + Predictors contrasted: time=c(1,2) + p-values are uncorrected. + +--- + + Code + print(estimate_contrasts(model2, c("grp", "time=2")), zap_small = TRUE, + table_width = Inf) + Output + Conditional Contrasts + + Level1 | Level2 | Difference | SE | 95% CI | t(994) | p + ------------------------------------------------------------------------ + treatment | control | -0.15 | 0.11 | [-0.36, 0.05] | -1.47 | 0.143 + + Variable predicted: score + Predictors contrasted: grp, time=2 p-values are uncorrected. diff --git a/tests/testthat/_snaps/windows/estimate_contrasts_counterfactual.md b/tests/testthat/_snaps/windows/estimate_contrasts_counterfactual.md index e8c7718b7..9a2687b6e 100644 --- a/tests/testthat/_snaps/windows/estimate_contrasts_counterfactual.md +++ b/tests/testthat/_snaps/windows/estimate_contrasts_counterfactual.md @@ -3,19 +3,21 @@ Code print(out, table_width = Inf) Output - Counterfactual Contrasts Analysis (G-computation) + Marginal Contrasts (G-computation) Level1 | Level2 | treatment | Difference | SE | 95% CI | z | p --------------------------------------------------------------------------------- post | pre | control | 1.85 | 1.22 | [-0.53, 4.23] | 1.52 | 0.128 end | pre | control | 0.86 | 1.21 | [-1.51, 3.24] | 0.71 | 0.477 - end | post | control | -0.99 | 1.22 | [-3.37, 1.39] | -0.81 | 0.417 + end | post | control | -0.99 | 1.22 | [-3.37, 1.40] | -0.81 | 0.417 post | pre | tx | 6.57 | 1.57 | [ 3.50, 9.65] | 4.19 | < .001 end | pre | tx | 17.26 | 1.57 | [14.18, 20.34] | 10.99 | < .001 end | post | tx | 10.69 | 1.57 | [ 7.62, 13.76] | 6.82 | < .001 Variable predicted: QoL Predictors contrasted: time - Predictors averaged: education, hospital (0.95), age (0.22), phq4 (-0.076), ID + Predictors held at: hospital (0.95), age (0.22), phq4 (-0.076) + Predictors averaged over (sample): education + Random effects: Marginalized across clusters. p-values are uncorrected. diff --git a/tests/testthat/_snaps/windows/estimate_contrasts_effectsize.md b/tests/testthat/_snaps/windows/estimate_contrasts_effectsize.md index b46a9e4db..169160fda 100644 --- a/tests/testthat/_snaps/windows/estimate_contrasts_effectsize.md +++ b/tests/testthat/_snaps/windows/estimate_contrasts_effectsize.md @@ -6,7 +6,7 @@ No variable was specified for contrast estimation. Selecting `contrast = "Species"`. Output - Marginal Contrasts Analysis + Conditional Contrasts Level1 | Level2 | Difference | 95% CI | SE | t(147) | p ------------------------------------------------------------------------------ @@ -26,7 +26,7 @@ No variable was specified for contrast estimation. Selecting `contrast = "Species"`. Output - Marginal Contrasts Analysis + Conditional Contrasts Level1 | Level2 | Difference | 95% CI | SE | t(147) | p ------------------------------------------------------------------------------ @@ -46,7 +46,7 @@ No variable was specified for contrast estimation. Selecting `contrast = "Species"`. Output - Marginal Contrasts Analysis + Conditional Contrasts Level1 | Level2 | Difference | 95% CI | SE | t(147) | p ------------------------------------------------------------------------------ @@ -72,7 +72,7 @@ No variable was specified for contrast estimation. Selecting `contrast = "Species"`. Output - Marginal Contrasts Analysis + Conditional Contrasts Level1 | Level2 | Difference | 95% CI | SE | t(147) | p | marginal_d ------------------------------------------------------------------------------------------- @@ -92,7 +92,7 @@ No variable was specified for contrast estimation. Selecting `contrast = "Species"`. Output - Marginal Contrasts Analysis + Conditional Contrasts Level1 | Level2 | Difference | 95% CI | SE | t(147) | p ------------------------------------------------------------------------------ @@ -119,7 +119,7 @@ No variable was specified for contrast estimation. Selecting `contrast = "Species"`. Output - Marginal Contrasts Analysis + Conditional Contrasts Level1 | Level2 | Difference | 95% CI | SE | t(147) | p ------------------------------------------------------------------------------ @@ -145,7 +145,7 @@ No variable was specified for contrast estimation. Selecting `contrast = "Species"`. Output - Marginal Contrasts Analysis + Conditional Contrasts Level1 | Level2 | Difference | 95% CI | SE | t(147) | p ------------------------------------------------------------------------------ @@ -170,7 +170,7 @@ Message We selected `contrast=c("Species")`. Output - Marginal Contrasts Analysis + Conditional Contrasts Level1 | Level2 | Difference | SE | 95% CI | t(147) | p ------------------------------------------------------------------------------ @@ -189,7 +189,7 @@ Message We selected `contrast=c("Species")`. Output - Marginal Contrasts Analysis + Conditional Contrasts Level1 | Level2 | Difference | SE | 95% CI | t(147) | p ------------------------------------------------------------------------------ @@ -208,7 +208,7 @@ Message We selected `contrast=c("Species")`. Output - Marginal Contrasts Analysis + Conditional Contrasts Level1 | Level2 | Difference | SE | 95% CI | t(147) | p | marginal_d ------------------------------------------------------------------------------------------- diff --git a/tests/testthat/_snaps/windows/estimate_means_counterfactuals.md b/tests/testthat/_snaps/windows/estimate_means_counterfactuals.md index aad797d26..7a626d110 100644 --- a/tests/testthat/_snaps/windows/estimate_means_counterfactuals.md +++ b/tests/testthat/_snaps/windows/estimate_means_counterfactuals.md @@ -4,7 +4,7 @@ print(estimate_means(m, "spp", backend = "marginaleffects"), zap_small = TRUE, table_width = Inf) Output - Estimated Marginal Means + Conditional Predictions spp | Mean | SE | 95% CI | z ----------------------------------------- @@ -18,7 +18,8 @@ Variable predicted: count Predictors modulated: spp - Predictors averaged: mined, site + Predictors averaged over (balanced grid): mined + Random effects: Averaged over a balanced grid of cluster levels. Predictions are on the response-scale. --- @@ -27,7 +28,7 @@ print(estimate_means(m, "spp", backend = "marginaleffects", estimate = "population"), zap_small = TRUE, table_width = Inf) Output - Average Counterfactual Predictions + Marginal Predictions (G-computation) spp | Mean | SE | 95% CI | z ----------------------------------------- @@ -41,7 +42,8 @@ Variable predicted: count Predictors modulated: spp - Predictors averaged: mined, site + Predictors averaged over (sample): mined + Random effects: Marginalized across clusters. Predictions are on the response-scale. --- @@ -50,7 +52,7 @@ print(estimate_means(m, "spp", backend = "marginaleffects", predict = "inverse_link"), zap_small = TRUE, table_width = Inf) Output - Estimated Marginal Means + Conditional Predictions spp | Mean | SE | 95% CI | z ------------------------------------------ @@ -64,7 +66,8 @@ Variable predicted: count Predictors modulated: spp - Predictors averaged: mined, site + Predictors averaged over (balanced grid): mined + Random effects: Averaged over a balanced grid of cluster levels. Predictions are on the response-scale. --- @@ -73,7 +76,7 @@ print(estimate_means(m, "spp", backend = "marginaleffects", estimate = "population", predict = "inverse_link"), zap_small = TRUE, table_width = Inf) Output - Average Counterfactual Predictions + Marginal Predictions (G-computation) spp | Mean | SE | 95% CI | z ------------------------------------------ @@ -87,7 +90,8 @@ Variable predicted: count Predictors modulated: spp - Predictors averaged: mined, site + Predictors averaged over (sample): mined + Random effects: Marginalized across clusters. Predictions are on the response-scale. --- @@ -96,7 +100,7 @@ print(estimate_means(m, "Days", backend = "marginaleffects"), zap_small = TRUE, table_width = Inf) Output - Estimated Marginal Means + Conditional Predictions Days | Mean | SE | 95% CI | t(174) ------------------------------------------------- @@ -113,7 +117,7 @@ Variable predicted: Reaction Predictors modulated: Days - Predictors averaged: Subject + Random effects: Averaged over a balanced grid of cluster levels. --- @@ -121,7 +125,7 @@ print(estimate_means(m, "Days", backend = "marginaleffects", estimate = "population"), zap_small = TRUE, table_width = Inf) Output - Average Counterfactual Predictions + Marginal Predictions (G-computation) Days | Mean | SE | 95% CI | t(174) ------------------------------------------------- @@ -138,5 +142,5 @@ Variable predicted: Reaction Predictors modulated: Days - Predictors averaged: Subject + Random effects: Marginalized across clusters. diff --git a/tests/testthat/_snaps/windows/ordinal.md b/tests/testthat/_snaps/windows/ordinal.md index 2a48efebd..3c8d90cb3 100644 --- a/tests/testthat/_snaps/windows/ordinal.md +++ b/tests/testthat/_snaps/windows/ordinal.md @@ -3,7 +3,7 @@ Code print(out, zap_small = TRUE) Output - Model-based Predictions + Conditional Predictions Row | Response | Sepal.Width | Predicted | SE | 95% CI ---------------------------------------------------------------- @@ -47,7 +47,7 @@ Code print(out, zap_small = TRUE) Output - Estimated Marginal Means + Conditional Predictions Sepal.Width | Response | Median | 95% CI | pd | ROPE | % in ROPE ----------------------------------------------------------------------------------- @@ -91,7 +91,7 @@ Code print(out, zap_small = TRUE) Output - Model-based Predictions + Conditional Predictions Row | Response | Sepal.Width | Predicted | 95% CI --------------------------------------------------------- @@ -135,7 +135,7 @@ Code print(out, zap_small = TRUE) Output - Estimated Marginal Means + Conditional Predictions Sepal.Width | Response | Probability | SE | 95% CI | t(147) ---------------------------------------------------------------------- @@ -179,7 +179,7 @@ Code print(out, zap_small = TRUE) Output - Estimated Marginal Means + Conditional Predictions island | Response | Probability | SE | 95% CI | z ------------------------------------------------------------------ @@ -195,7 +195,7 @@ Variable predicted: species Predictors modulated: island - Predictors averaged: sex + Predictors averaged over (balanced grid): sex Predictions are on the probs-scale. --- @@ -203,7 +203,7 @@ Code print(out, zap_small = TRUE) Output - Estimated Marginal Means + Conditional Predictions island | Response | Probability | SE | 95% CI | t(325) -------------------------------------------------------------------- @@ -219,6 +219,6 @@ Variable predicted: species Predictors modulated: island - Predictors averaged: sex + Predictors averaged over (balanced grid): sex Predictions are on the probs-scale. diff --git a/tests/testthat/_snaps/plot/plot-4way-numeric-1.svg b/tests/testthat/_snaps/windows/plot/plot-4way-numeric-1.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-4way-numeric-1.svg rename to tests/testthat/_snaps/windows/plot/plot-4way-numeric-1.svg diff --git a/tests/testthat/_snaps/plot/plot-cat-num-predictor-1.svg b/tests/testthat/_snaps/windows/plot/plot-cat-num-predictor-1.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-cat-num-predictor-1.svg rename to tests/testthat/_snaps/windows/plot/plot-cat-num-predictor-1.svg diff --git a/tests/testthat/_snaps/plot/plot-cat-num-predictor-2.svg b/tests/testthat/_snaps/windows/plot/plot-cat-num-predictor-2.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-cat-num-predictor-2.svg rename to tests/testthat/_snaps/windows/plot/plot-cat-num-predictor-2.svg diff --git a/tests/testthat/_snaps/plot/plot-cat-num-predictor-3.svg b/tests/testthat/_snaps/windows/plot/plot-cat-num-predictor-3.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-cat-num-predictor-3.svg rename to tests/testthat/_snaps/windows/plot/plot-cat-num-predictor-3.svg diff --git a/tests/testthat/_snaps/plot/plot-cat-num-predictor-4.svg b/tests/testthat/_snaps/windows/plot/plot-cat-num-predictor-4.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-cat-num-predictor-4.svg rename to tests/testthat/_snaps/windows/plot/plot-cat-num-predictor-4.svg diff --git a/tests/testthat/_snaps/plot/plot-cat-num-predictor-5.svg b/tests/testthat/_snaps/windows/plot/plot-cat-num-predictor-5.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-cat-num-predictor-5.svg rename to tests/testthat/_snaps/windows/plot/plot-cat-num-predictor-5.svg diff --git a/tests/testthat/_snaps/plot/plot-cat-num-predictor-6.svg b/tests/testthat/_snaps/windows/plot/plot-cat-num-predictor-6.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-cat-num-predictor-6.svg rename to tests/testthat/_snaps/windows/plot/plot-cat-num-predictor-6.svg diff --git a/tests/testthat/_snaps/plot/plot-cat-num-predictor-7.svg b/tests/testthat/_snaps/windows/plot/plot-cat-num-predictor-7.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-cat-num-predictor-7.svg rename to tests/testthat/_snaps/windows/plot/plot-cat-num-predictor-7.svg diff --git a/tests/testthat/_snaps/plot/plot-expectation-fivenum.svg b/tests/testthat/_snaps/windows/plot/plot-expectation-fivenum.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-expectation-fivenum.svg rename to tests/testthat/_snaps/windows/plot/plot-expectation-fivenum.svg diff --git a/tests/testthat/_snaps/plot/plot-glm-logistic-1.svg b/tests/testthat/_snaps/windows/plot/plot-glm-logistic-1.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-glm-logistic-1.svg rename to tests/testthat/_snaps/windows/plot/plot-glm-logistic-1.svg diff --git a/tests/testthat/_snaps/plot/plot-glm-logistic-2.svg b/tests/testthat/_snaps/windows/plot/plot-glm-logistic-2.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-glm-logistic-2.svg rename to tests/testthat/_snaps/windows/plot/plot-glm-logistic-2.svg diff --git a/tests/testthat/_snaps/plot/plot-grouplevel-lme4-1.svg b/tests/testthat/_snaps/windows/plot/plot-grouplevel-lme4-1.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-grouplevel-lme4-1.svg rename to tests/testthat/_snaps/windows/plot/plot-grouplevel-lme4-1.svg diff --git a/tests/testthat/_snaps/plot/plot-grouplevel-lme4-2.svg b/tests/testthat/_snaps/windows/plot/plot-grouplevel-lme4-2.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-grouplevel-lme4-2.svg rename to tests/testthat/_snaps/windows/plot/plot-grouplevel-lme4-2.svg diff --git a/tests/testthat/_snaps/plot/plot-join-dots-1.svg b/tests/testthat/_snaps/windows/plot/plot-join-dots-1.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-join-dots-1.svg rename to tests/testthat/_snaps/windows/plot/plot-join-dots-1.svg diff --git a/tests/testthat/_snaps/plot/plot-join-dots-2.svg b/tests/testthat/_snaps/windows/plot/plot-join-dots-2.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-join-dots-2.svg rename to tests/testthat/_snaps/windows/plot/plot-join-dots-2.svg diff --git a/tests/testthat/_snaps/plot/plot-logistic-bounds-1.svg b/tests/testthat/_snaps/windows/plot/plot-logistic-bounds-1.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-logistic-bounds-1.svg rename to tests/testthat/_snaps/windows/plot/plot-logistic-bounds-1.svg diff --git a/tests/testthat/_snaps/plot/plot-me-means-1.svg b/tests/testthat/_snaps/windows/plot/plot-me-means-1.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-me-means-1.svg rename to tests/testthat/_snaps/windows/plot/plot-me-means-1.svg diff --git a/tests/testthat/_snaps/plot/plot-me-means-2.svg b/tests/testthat/_snaps/windows/plot/plot-me-means-2.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-me-means-2.svg rename to tests/testthat/_snaps/windows/plot/plot-me-means-2.svg diff --git a/tests/testthat/_snaps/plot/plot-me-means-3.svg b/tests/testthat/_snaps/windows/plot/plot-me-means-3.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-me-means-3.svg rename to tests/testthat/_snaps/windows/plot/plot-me-means-3.svg diff --git a/tests/testthat/_snaps/plot/plot-me-means-4.svg b/tests/testthat/_snaps/windows/plot/plot-me-means-4.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-me-means-4.svg rename to tests/testthat/_snaps/windows/plot/plot-me-means-4.svg diff --git a/tests/testthat/_snaps/plot/plot-me-means-showdata-1.svg b/tests/testthat/_snaps/windows/plot/plot-me-means-showdata-1.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-me-means-showdata-1.svg rename to tests/testthat/_snaps/windows/plot/plot-me-means-showdata-1.svg diff --git a/tests/testthat/_snaps/plot/plot-me-means-showdata-2.svg b/tests/testthat/_snaps/windows/plot/plot-me-means-showdata-2.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-me-means-showdata-2.svg rename to tests/testthat/_snaps/windows/plot/plot-me-means-showdata-2.svg diff --git a/tests/testthat/_snaps/plot/plot-me-means-showdata-3.svg b/tests/testthat/_snaps/windows/plot/plot-me-means-showdata-3.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-me-means-showdata-3.svg rename to tests/testthat/_snaps/windows/plot/plot-me-means-showdata-3.svg diff --git a/tests/testthat/_snaps/plot/plot-me-means-showdata-4.svg b/tests/testthat/_snaps/windows/plot/plot-me-means-showdata-4.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-me-means-showdata-4.svg rename to tests/testthat/_snaps/windows/plot/plot-me-means-showdata-4.svg diff --git a/tests/testthat/_snaps/plot/plot-means-1-lines.svg b/tests/testthat/_snaps/windows/plot/plot-means-1-lines.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-means-1-lines.svg rename to tests/testthat/_snaps/windows/plot/plot-means-1-lines.svg diff --git a/tests/testthat/_snaps/plot/plot-means-1.svg b/tests/testthat/_snaps/windows/plot/plot-means-1.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-means-1.svg rename to tests/testthat/_snaps/windows/plot/plot-means-1.svg diff --git a/tests/testthat/_snaps/plot/plot-means-2.svg b/tests/testthat/_snaps/windows/plot/plot-means-2.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-means-2.svg rename to tests/testthat/_snaps/windows/plot/plot-means-2.svg diff --git a/tests/testthat/_snaps/plot/plot-means-3.svg b/tests/testthat/_snaps/windows/plot/plot-means-3.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-means-3.svg rename to tests/testthat/_snaps/windows/plot/plot-means-3.svg diff --git a/tests/testthat/_snaps/plot/plot-means-4-lines.svg b/tests/testthat/_snaps/windows/plot/plot-means-4-lines.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-means-4-lines.svg rename to tests/testthat/_snaps/windows/plot/plot-means-4-lines.svg diff --git a/tests/testthat/_snaps/plot/plot-means-4.svg b/tests/testthat/_snaps/windows/plot/plot-means-4.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-means-4.svg rename to tests/testthat/_snaps/windows/plot/plot-means-4.svg diff --git a/tests/testthat/_snaps/plot/plot-means-poisson-1.svg b/tests/testthat/_snaps/windows/plot/plot-means-poisson-1.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-means-poisson-1.svg rename to tests/testthat/_snaps/windows/plot/plot-means-poisson-1.svg diff --git a/tests/testthat/_snaps/plot/plot-means-poisson-2.svg b/tests/testthat/_snaps/windows/plot/plot-means-poisson-2.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-means-poisson-2.svg rename to tests/testthat/_snaps/windows/plot/plot-means-poisson-2.svg diff --git a/tests/testthat/_snaps/plot/plot-means-predictor-order-1.svg b/tests/testthat/_snaps/windows/plot/plot-means-predictor-order-1.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-means-predictor-order-1.svg rename to tests/testthat/_snaps/windows/plot/plot-means-predictor-order-1.svg diff --git a/tests/testthat/_snaps/plot/plot-means-predictor-order-2.svg b/tests/testthat/_snaps/windows/plot/plot-means-predictor-order-2.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-means-predictor-order-2.svg rename to tests/testthat/_snaps/windows/plot/plot-means-predictor-order-2.svg diff --git a/tests/testthat/_snaps/plot/plot-means-predictor-order-3.svg b/tests/testthat/_snaps/windows/plot/plot-means-predictor-order-3.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-means-predictor-order-3.svg rename to tests/testthat/_snaps/windows/plot/plot-means-predictor-order-3.svg diff --git a/tests/testthat/_snaps/plot/plot-means-predictor-order-4.svg b/tests/testthat/_snaps/windows/plot/plot-means-predictor-order-4.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-means-predictor-order-4.svg rename to tests/testthat/_snaps/windows/plot/plot-means-predictor-order-4.svg diff --git a/tests/testthat/_snaps/plot/plot-means-showdata-1.svg b/tests/testthat/_snaps/windows/plot/plot-means-showdata-1.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-means-showdata-1.svg rename to tests/testthat/_snaps/windows/plot/plot-means-showdata-1.svg diff --git a/tests/testthat/_snaps/plot/plot-means-showdata-2.svg b/tests/testthat/_snaps/windows/plot/plot-means-showdata-2.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-means-showdata-2.svg rename to tests/testthat/_snaps/windows/plot/plot-means-showdata-2.svg diff --git a/tests/testthat/_snaps/plot/plot-means-showdata-3.svg b/tests/testthat/_snaps/windows/plot/plot-means-showdata-3.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-means-showdata-3.svg rename to tests/testthat/_snaps/windows/plot/plot-means-showdata-3.svg diff --git a/tests/testthat/_snaps/plot/plot-means-showdata-4.svg b/tests/testthat/_snaps/windows/plot/plot-means-showdata-4.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-means-showdata-4.svg rename to tests/testthat/_snaps/windows/plot/plot-means-showdata-4.svg diff --git a/tests/testthat/_snaps/plot/plot-relation-1.svg b/tests/testthat/_snaps/windows/plot/plot-relation-1.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-relation-1.svg rename to tests/testthat/_snaps/windows/plot/plot-relation-1.svg diff --git a/tests/testthat/_snaps/plot/plot-relation-2.svg b/tests/testthat/_snaps/windows/plot/plot-relation-2.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-relation-2.svg rename to tests/testthat/_snaps/windows/plot/plot-relation-2.svg diff --git a/tests/testthat/_snaps/plot/plot-relation-3.svg b/tests/testthat/_snaps/windows/plot/plot-relation-3.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-relation-3.svg rename to tests/testthat/_snaps/windows/plot/plot-relation-3.svg diff --git a/tests/testthat/_snaps/plot/plot-relation-4.svg b/tests/testthat/_snaps/windows/plot/plot-relation-4.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-relation-4.svg rename to tests/testthat/_snaps/windows/plot/plot-relation-4.svg diff --git a/tests/testthat/_snaps/plot/plot-relation-logistic-percentage-1.svg b/tests/testthat/_snaps/windows/plot/plot-relation-logistic-percentage-1.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-relation-logistic-percentage-1.svg rename to tests/testthat/_snaps/windows/plot/plot-relation-logistic-percentage-1.svg diff --git a/tests/testthat/_snaps/plot/plot-relation-multiple-ci-1.svg b/tests/testthat/_snaps/windows/plot/plot-relation-multiple-ci-1.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-relation-multiple-ci-1.svg rename to tests/testthat/_snaps/windows/plot/plot-relation-multiple-ci-1.svg diff --git a/tests/testthat/_snaps/plot/plot-relation-showdata-1.svg b/tests/testthat/_snaps/windows/plot/plot-relation-showdata-1.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-relation-showdata-1.svg rename to tests/testthat/_snaps/windows/plot/plot-relation-showdata-1.svg diff --git a/tests/testthat/_snaps/plot/plot-relation-showdata-2.svg b/tests/testthat/_snaps/windows/plot/plot-relation-showdata-2.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-relation-showdata-2.svg rename to tests/testthat/_snaps/windows/plot/plot-relation-showdata-2.svg diff --git a/tests/testthat/_snaps/plot/plot-relation-showdata-3.svg b/tests/testthat/_snaps/windows/plot/plot-relation-showdata-3.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-relation-showdata-3.svg rename to tests/testthat/_snaps/windows/plot/plot-relation-showdata-3.svg diff --git a/tests/testthat/_snaps/plot/plot-relation-showdata-4.svg b/tests/testthat/_snaps/windows/plot/plot-relation-showdata-4.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-relation-showdata-4.svg rename to tests/testthat/_snaps/windows/plot/plot-relation-showdata-4.svg diff --git a/tests/testthat/_snaps/plot/plot-slopes-1.svg b/tests/testthat/_snaps/windows/plot/plot-slopes-1.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-slopes-1.svg rename to tests/testthat/_snaps/windows/plot/plot-slopes-1.svg diff --git a/tests/testthat/_snaps/plot/plot-slopes-2.svg b/tests/testthat/_snaps/windows/plot/plot-slopes-2.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-slopes-2.svg rename to tests/testthat/_snaps/windows/plot/plot-slopes-2.svg diff --git a/tests/testthat/_snaps/plot/plot-slopes-3.svg b/tests/testthat/_snaps/windows/plot/plot-slopes-3.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-slopes-3.svg rename to tests/testthat/_snaps/windows/plot/plot-slopes-3.svg diff --git a/tests/testthat/_snaps/plot/plot-slopes-4.svg b/tests/testthat/_snaps/windows/plot/plot-slopes-4.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-slopes-4.svg rename to tests/testthat/_snaps/windows/plot/plot-slopes-4.svg diff --git a/tests/testthat/_snaps/plot/plot-slopes-5.svg b/tests/testthat/_snaps/windows/plot/plot-slopes-5.svg similarity index 100% rename from tests/testthat/_snaps/plot/plot-slopes-5.svg rename to tests/testthat/_snaps/windows/plot/plot-slopes-5.svg diff --git a/tests/testthat/_snaps/windows/print.md b/tests/testthat/_snaps/windows/print.md index 3a9ca085f..a0937d718 100644 --- a/tests/testthat/_snaps/windows/print.md +++ b/tests/testthat/_snaps/windows/print.md @@ -109,7 +109,7 @@ print(estimate_means(fit, c("c12hour", "c172code", "c161sex"), length = 4, backend = "marginaleffects"), table_width = Inf) Output - Estimated Marginal Means + Conditional Predictions c12hour | c172code | c161sex | Mean | SE | 95% CI | t(791) -------------------------------------------------------------------------------------------- @@ -140,7 +140,7 @@ Variable predicted: neg_c_7 Predictors modulated: c12hour, c172code, c161sex - Predictors averaged: barthtot (65) + Predictors held at: barthtot (65) --- @@ -148,7 +148,7 @@ print(estimate_means(fit, c("c12hour", "barthtot = [sd]", "c161sex", "c172code", "e16sex"), backend = "marginaleffects", length = 3), table_width = Inf) Output - Estimated Marginal Means + Conditional Predictions c12hour | barthtot | c161sex | c172code | e16sex | Mean | SE | 95% CI | t(766) ------------------------------------------------------------------------------------------------------------------- @@ -270,7 +270,7 @@ print(estimate_means(fit, c("c161sex", "c172code", "e16sex", "nur_pst"), backend = "marginaleffects"), table_width = Inf) Output - Estimated Marginal Means + Conditional Predictions c161sex | c172code | e16sex | nur_pst | Mean | SE | 95% CI | t(402) --------------------------------------------------------------------------------------------------------------- @@ -320,7 +320,7 @@ print(estimate_means(fit, c("c161sex", "c172code", "e16sex", "nur_pst"), backend = "marginaleffects"), full_labels = FALSE, table_width = Inf) Output - Estimated Marginal Means + Conditional Predictions c161sex | c172code | e16sex | nur_pst | Mean | SE | 95% CI | t(402) --------------------------------------------------------------------------------------------------------------- @@ -370,7 +370,7 @@ print(estimate_means(fit, c("c161sex", "c172code", "e16sex", "nur_pst", "negc7d"), backend = "marginaleffects"), table_width = Inf) Output - Estimated Marginal Means + Conditional Predictions c161sex | c172code | e16sex | nur_pst | negc7d | Mean | SE | 95% CI | t(370) ----------------------------------------------------------------------------------------------------------------------- @@ -406,7 +406,7 @@ Female | high level of education | male | Care Level 3/3+ | 0 | 11.00 | 2.28 | [ 6.51, 15.49] | 4.82 Male | low level of education | female | Care Level 3/3+ | 0 | 8.50 | 1.61 | [ 5.33, 11.67] | 5.27 Female | low level of education | female | Care Level 3/3+ | 0 | 8.67 | 1.32 | [ 6.08, 11.26] | 6.58 - Male | intermediate level of education | female | Care Level 3/3+ | 0 | 9.13 | 0.81 | [ 7.54, 10.71] | 11.31 + Male | intermediate level of education | female | Care Level 3/3+ | 0 | 9.12 | 0.81 | [ 7.54, 10.71] | 11.31 Female | intermediate level of education | female | Care Level 3/3+ | 0 | 9.78 | 0.76 | [ 8.28, 11.27] | 12.86 Male | high level of education | female | Care Level 3/3+ | 0 | 9.00 | 2.28 | [ 4.51, 13.49] | 3.94 Female | high level of education | female | Care Level 3/3+ | 0 | 9.00 | 1.32 | [ 6.41, 11.59] | 6.83 @@ -456,7 +456,7 @@ print(estimate_means(fit, c("c161sex", "c172code", "e16sex", "nur_pst", "negc7d"), backend = "marginaleffects"), full_labels = FALSE, table_width = Inf) Output - Estimated Marginal Means + Conditional Predictions c161sex | c172code | e16sex | nur_pst | negc7d | Mean | SE | 95% CI | t(370) ----------------------------------------------------------------------------------------------------------------------- @@ -492,7 +492,7 @@ Female | | | | | 11.00 | 2.28 | [ 6.51, 15.49] | 4.82 Male | low level of education | female | | | 8.50 | 1.61 | [ 5.33, 11.67] | 5.27 Female | | | | | 8.67 | 1.32 | [ 6.08, 11.26] | 6.58 - Male | intermediate level of education | | | | 9.13 | 0.81 | [ 7.54, 10.71] | 11.31 + Male | intermediate level of education | | | | 9.12 | 0.81 | [ 7.54, 10.71] | 11.31 Female | | | | | 9.78 | 0.76 | [ 8.28, 11.27] | 12.86 Male | high level of education | | | | 9.00 | 2.28 | [ 4.51, 13.49] | 3.94 Female | | | | | 9.00 | 1.32 | [ 6.41, 11.59] | 6.83 @@ -541,7 +541,7 @@ Code estimate_expectation(model, by = c("c160age=[fivenum]", "c161sex")) Output - Model-based Predictions + Conditional Predictions c160age | c161sex | Predicted | SE | 95% CI ----------------------------------------------------- @@ -556,14 +556,14 @@ Variable predicted: neg_c_7 Predictors modulated: c160age=[fivenum], c161sex - Predictors controlled: barthtot (65), e16sex (male) + Predictors held at: barthtot (65), e16sex (male) --- Code estimate_means(model, by = c("c160age=[fivenum]", "c161sex"), backend = "marginaleffects") Output - Estimated Marginal Means + Conditional Predictions c160age | c161sex | Mean | SE | 95% CI | t(865) ---------------------------------------------------------- @@ -580,5 +580,6 @@ Variable predicted: neg_c_7 Predictors modulated: c160age=[fivenum], c161sex - Predictors averaged: barthtot (65), e16sex + Predictors held at: barthtot (65) + Predictors averaged over (balanced grid): e16sex diff --git a/tests/testthat/test-brms.R b/tests/testthat/test-brms.R index 93fb1fec1..d1903693a 100644 --- a/tests/testthat/test-brms.R +++ b/tests/testthat/test-brms.R @@ -140,7 +140,7 @@ test_that("estimate_means - brms, Wiener", { expect_identical( capture.output(print(est)), c( - "Estimated Marginal Means", + "Conditional Predictions", "", "Median | 95% CI | pd | ROPE | % in ROPE", "--------------------------------------------------------", @@ -170,7 +170,7 @@ test_that("estimate_means - brms, Wiener, printing", { expect_identical( capture.output(print(est)), c( - "Estimated Marginal Means", + "Conditional Predictions", "", "x | Mu | 95% CI | pd | ROPE | % in ROPE", "----------------------------------------------------------", @@ -187,7 +187,7 @@ test_that("estimate_means - brms, Wiener, printing", { expect_identical( capture.output(print(cont)), c( - "Marginal Contrasts Analysis", + "Conditional Contrasts", "", "Level1 | Level2 | Median | 95% CI | pd | ROPE | % in ROPE", "--------------------------------------------------------------------------", diff --git a/tests/testthat/test-estimate_contrasts.R b/tests/testthat/test-estimate_contrasts.R index aec502ae1..6b5e09c58 100644 --- a/tests/testthat/test-estimate_contrasts.R +++ b/tests/testthat/test-estimate_contrasts.R @@ -1078,8 +1078,6 @@ test_that("estimate_contrasts - different options for comparison", { }) -skip_on_os(c("mac", "linux")) - test_that("estimate_contrasts - filtering works", { data(efc, package = "modelbased") @@ -1087,11 +1085,14 @@ test_that("estimate_contrasts - filtering works", { efc <- datawizard::to_factor(efc, c("c161sex", "c172code", "e16sex")) levels(efc$c172code) <- c("low", "mid", "high") fit <- lm(neg_c_7 ~ e16sex + c161sex + c172code, data = efc) - expect_snapshot(print( - estimate_contrasts(fit, "c172code", backend = "marginaleffects"), - table_width = Inf, - zap_small = TRUE - )) + expect_snapshot( + print( + estimate_contrasts(fit, "c172code", backend = "marginaleffects"), + table_width = Inf, + zap_small = TRUE + ), + variant = "windows" + ) fit <- lm(neg_c_7 ~ e16sex + c161sex * c172code, data = efc) expect_snapshot(print( @@ -1099,18 +1100,24 @@ test_that("estimate_contrasts - filtering works", { table_width = Inf, zap_small = TRUE )) - expect_snapshot(print( - estimate_contrasts(fit, "c161sex", "c172code", backend = "marginaleffects"), - table_width = Inf, - zap_small = TRUE - )) + expect_snapshot( + print( + estimate_contrasts(fit, "c161sex", "c172code", backend = "marginaleffects"), + table_width = Inf, + zap_small = TRUE + ), + variant = "windows" + ) fit <- lm(neg_c_7 ~ barthtot + c161sex + c172code, data = efc) - expect_snapshot(print( - estimate_slopes(fit, "barthtot", backend = "marginaleffects"), - table_width = Inf, - zap_small = TRUE - )) + expect_snapshot( + print( + estimate_slopes(fit, "barthtot", backend = "marginaleffects"), + table_width = Inf, + zap_small = TRUE + ), + variant = "windows" + ) # error expect_error( estimate_contrasts(fit, "barthtot", backend = "marginaleffects"), @@ -1118,27 +1125,36 @@ test_that("estimate_contrasts - filtering works", { ) fit <- lm(neg_c_7 ~ e16sex + barthtot * c172code, data = efc) - expect_snapshot(print( - estimate_slopes(fit, "barthtot", by = "c172code", backend = "marginaleffects"), - table_width = Inf, - zap_small = TRUE - )) - expect_snapshot(print( - estimate_contrasts(fit, "barthtot", "c172code", backend = "marginaleffects"), - table_width = Inf, - zap_small = TRUE - )) + expect_snapshot( + print( + estimate_slopes(fit, "barthtot", by = "c172code", backend = "marginaleffects"), + table_width = Inf, + zap_small = TRUE + ), + variant = "windows" + ) + expect_snapshot( + print( + estimate_contrasts(fit, "barthtot", "c172code", backend = "marginaleffects"), + table_width = Inf, + zap_small = TRUE + ), + variant = "windows" + ) fit <- lm(neg_c_7 ~ e16sex * barthtot * c172code, data = efc) - expect_snapshot(print( - estimate_contrasts( - fit, - "barthtot", - c("c172code", "e16sex"), - backend = "marginaleffects" + expect_snapshot( + print( + estimate_contrasts( + fit, + "barthtot", + c("c172code", "e16sex"), + backend = "marginaleffects" + ), + table_width = Inf, + zap_small = TRUE ), - table_width = Inf, - zap_small = TRUE - )) + variant = "windows" + ) # error expect_error( estimate_contrasts(fit, c("barthtot", "c172code"), backend = "marginaleffects"), @@ -1152,24 +1168,38 @@ test_that("estimate_contrasts - simple contrasts and with - in levels works", { data(iris) model <- lm(Sepal.Length ~ Species + Sepal.Width, data = iris) - expect_snapshot(print( - estimate_contrasts(model, "Species", backend = "marginaleffects"), - table_width = Inf - )) + expect_snapshot( + print( + estimate_contrasts(model, "Species", backend = "marginaleffects"), + table_width = Inf + ), + variant = "windows" + ) data(coffee_data, package = "modelbased") m <- lm(alertness ~ time * coffee + sex, data = coffee_data) - expect_snapshot(print( - estimate_contrasts(m, c("time", "coffee"), backend = "marginaleffects"), - zap_small = TRUE, - table_width = Inf - )) + expect_snapshot( + print( + estimate_contrasts(m, c("time", "coffee"), backend = "marginaleffects"), + zap_small = TRUE, + table_width = Inf + ), + variant = "windows" + ) - expect_snapshot(print( - estimate_contrasts(m, contrast = "time", by = "coffee", backend = "marginaleffects"), - zap_small = TRUE, - table_width = Inf - )) + expect_snapshot( + print( + estimate_contrasts( + m, + contrast = "time", + by = "coffee", + backend = "marginaleffects" + ), + zap_small = TRUE, + table_width = Inf + ), + variant = "windows" + ) data(Salamanders, package = "glmmTMB") model <- glmmTMB::glmmTMB( @@ -1177,21 +1207,31 @@ test_that("estimate_contrasts - simple contrasts and with - in levels works", { data = Salamanders, family = "poisson" ) - expect_snapshot(print( - estimate_contrasts(model, contrast = c("mined", "spp"), backend = "marginaleffects"), - zap_small = TRUE, - table_width = Inf - )) - expect_snapshot(print( - estimate_contrasts( - model, - contrast = "mined", - by = "spp", - backend = "marginaleffects" + expect_snapshot( + print( + estimate_contrasts( + model, + contrast = c("mined", "spp"), + backend = "marginaleffects" + ), + zap_small = TRUE, + table_width = Inf ), - zap_small = TRUE, - table_width = Inf - )) + variant = "windows" + ) + expect_snapshot( + print( + estimate_contrasts( + model, + contrast = "mined", + by = "spp", + backend = "marginaleffects" + ), + zap_small = TRUE, + table_width = Inf + ), + variant = "windows" + ) }) @@ -1388,21 +1428,30 @@ test_that("estimate_contrasts - examples from docs work as intendec", { zap_small = TRUE, table_width = Inf )) - expect_snapshot(print( - estimate_contrasts(model, contrast = c("Species", "Petal.Width"), length = 2), - zap_small = TRUE, - table_width = Inf - )) - expect_snapshot(print( - estimate_contrasts(model, contrast = c("Species", "Petal.Width=c(1, 2)")), - zap_small = TRUE, - table_width = Inf - )) - expect_snapshot(print( - estimate_contrasts(model, by = "Petal.Width", length = 4), - zap_small = TRUE, - table_width = Inf - )) + expect_snapshot( + print( + estimate_contrasts(model, contrast = c("Species", "Petal.Width"), length = 2), + zap_small = TRUE, + table_width = Inf + ), + variant = "windows" + ) + expect_snapshot( + print( + estimate_contrasts(model, contrast = c("Species", "Petal.Width=c(1, 2)")), + zap_small = TRUE, + table_width = Inf + ), + variant = "windows" + ) + expect_snapshot( + print( + estimate_contrasts(model, by = "Petal.Width", length = 4), + zap_small = TRUE, + table_width = Inf + ), + variant = "windows" + ) }) @@ -1418,41 +1467,62 @@ test_that("estimate_contrasts - test all combinations of contrast and by, with f ) model2 <- lm(score ~ grp * time * x, data = d) - expect_snapshot(print( - estimate_contrasts(model2, c("grp", "time", "x")), - zap_small = TRUE, - table_width = Inf - )) - expect_snapshot(print( - estimate_contrasts(model2, c("grp", "time"), by = "x"), - zap_small = TRUE, - table_width = Inf - )) - expect_snapshot(print( - estimate_contrasts(model2, "grp", by = c("time", "x")), - zap_small = TRUE, - table_width = Inf - )) - expect_snapshot(print( - estimate_contrasts(model2, "grp", by = "time"), - zap_small = TRUE, - table_width = Inf - )) - expect_snapshot(print( - estimate_contrasts(model2, c("grp", "time", "x='a'")), - zap_small = TRUE, - table_width = Inf - )) - expect_snapshot(print( - estimate_contrasts(model2, c("grp", "time=1"), by = "x"), - zap_small = TRUE, - table_width = Inf - )) - expect_snapshot(print( - estimate_contrasts(model2, "grp", by = c("time", "x='a'")), - zap_small = TRUE, - table_width = Inf - )) + expect_snapshot( + print( + estimate_contrasts(model2, c("grp", "time", "x")), + zap_small = TRUE, + table_width = Inf + ), + variant = "windows" + ) + expect_snapshot( + print( + estimate_contrasts(model2, c("grp", "time"), by = "x"), + zap_small = TRUE, + table_width = Inf + ), + variant = "windows" + ) + expect_snapshot( + print( + estimate_contrasts(model2, "grp", by = c("time", "x")), + zap_small = TRUE, + table_width = Inf + ), + variant = "windows" + ) + expect_snapshot( + print( + estimate_contrasts(model2, "grp", by = "time"), + zap_small = TRUE, + table_width = Inf + ), + variant = "windows" + ) + expect_snapshot( + print( + estimate_contrasts(model2, c("grp", "time", "x='a'")), + zap_small = TRUE, + table_width = Inf + ), + variant = "windows" + ) + expect_snapshot( + print( + estimate_contrasts(model2, c("grp", "time=1"), by = "x"), + zap_small = TRUE, + table_width = Inf + ), + variant = "windows" + ) + expect_snapshot( + print( + estimate_contrasts(model2, "grp", by = c("time", "x='a'")), + zap_small = TRUE, + table_width = Inf + ), + variant = "windows" + ) set.seed(123) n <- 1000 @@ -1463,16 +1533,22 @@ test_that("estimate_contrasts - test all combinations of contrast and by, with f ) model2 <- lm(score ~ grp * time, data = d) - expect_snapshot(print( - estimate_contrasts(model2, "time=c(1,2)", by = "grp"), - zap_small = TRUE, - table_width = Inf - )) - expect_snapshot(print( - estimate_contrasts(model2, c("grp", "time=2")), - zap_small = TRUE, - table_width = Inf - )) + expect_snapshot( + print( + estimate_contrasts(model2, "time=c(1,2)", by = "grp"), + zap_small = TRUE, + table_width = Inf + ), + variant = "windows" + ) + expect_snapshot( + print( + estimate_contrasts(model2, c("grp", "time=2")), + zap_small = TRUE, + table_width = Inf + ), + variant = "windows" + ) }) diff --git a/tests/testthat/test-estimate_contrasts_context.R b/tests/testthat/test-estimate_contrasts_context.R index 5929f03af..d96345420 100644 --- a/tests/testthat/test-estimate_contrasts_context.R +++ b/tests/testthat/test-estimate_contrasts_context.R @@ -76,7 +76,7 @@ test_that("estimate_contrast, context effects, linear", { expect_identical( capture.output(out), c( - "Marginal Contrasts Analysis", + "Conditional Contrasts", "", "sex | year | Difference | SE | 95% CI | z | p", "-------------------------------------------------------------------", @@ -100,7 +100,7 @@ test_that("estimate_contrast, context effects, linear", { expect_identical( capture.output(out), c( - "Marginal Contrasts Analysis", + "Conditional Contrasts", "", "Level1 | Level2 | year | Difference | SE | 95% CI | z | p", "--------------------------------------------------------------------------", diff --git a/tests/testthat/test-estimate_contrasts_counterfactual.R b/tests/testthat/test-estimate_contrasts_counterfactual.R index fb73e27f3..f645eba53 100644 --- a/tests/testthat/test-estimate_contrasts_counterfactual.R +++ b/tests/testthat/test-estimate_contrasts_counterfactual.R @@ -35,7 +35,7 @@ test_that("estimate_contrast, counterfactual", { ) expect_identical( attributes(out2)$table_title, - c("Counterfactual Contrasts Analysis (G-computation)", "blue") + c("Marginal Contrasts (G-computation)", "blue") ) out1 <- marginaleffects::avg_comparisons( @@ -167,7 +167,7 @@ test_that("estimate_contrast, counterfactual, custom hypothesis", { expect_equal(out$Difference, -4.591834, tolerance = 1e-3) expect_identical( attributes(out)$table_footer[1], - "\nVariable predicted: QoL\nPredictors contrasted: treatment\nPredictors averaged: education, hospital (0.95), age (0.22), phq4 (-0.076), ID\np-values are uncorrected.\nParameters:\nb3 = treatment [0], time [2]\nb1 = treatment [0], time [1]\nb4 = treatment [1], time [2]\nb2 = treatment [1], time [1]\n" + "\nVariable predicted: QoL\nPredictors contrasted: treatment\nPredictors held at: hospital (0.95), age (0.22), phq4 (-0.076)\nPredictors averaged over (sample): education\nRandom effects: Marginalized across clusters.\np-values are uncorrected.\nParameters:\nb3 = treatment [0], time [2]\nb1 = treatment [0], time [1]\nb4 = treatment [1], time [2]\nb2 = treatment [1], time [1]\n" ) }) diff --git a/tests/testthat/test-estimate_contrasts_inequality.R b/tests/testthat/test-estimate_contrasts_inequality.R index c7e51df78..4befb983f 100644 --- a/tests/testthat/test-estimate_contrasts_inequality.R +++ b/tests/testthat/test-estimate_contrasts_inequality.R @@ -18,12 +18,15 @@ test_that("estimate_contrast, marginal effects inequalities", { # inequality works with "average" estimate out <- estimate_contrasts(m, "species", comparison = "inequality", estimate = "average") expect_equal(out$Mean_Difference, 0.6380998, tolerance = 1e-4) - expect_identical(attributes(out)$table_title, c("Averaged Inequality Analysis", "blue")) + expect_identical(attributes(out)$table_title, c("Marginal Inequality Analysis", "blue")) # inequality works without default estimate out <- estimate_contrasts(m, "species", comparison = "inequality") expect_equal(out$Mean_Difference, 0.5580707, tolerance = 1e-4) - expect_identical(attributes(out)$table_title, c("Marginal Inequality Analysis", "blue")) + expect_identical( + attributes(out)$table_title, + c("Conditional Inequality Analysis", "blue") + ) # pairwise inequality requires `by` expect_error( diff --git a/tests/testthat/test-estimate_means_counterfactuals.R b/tests/testthat/test-estimate_means_counterfactuals.R index b5584e464..03b664c00 100644 --- a/tests/testthat/test-estimate_means_counterfactuals.R +++ b/tests/testthat/test-estimate_means_counterfactuals.R @@ -11,11 +11,45 @@ test_that("estimate_means() - counterfactuals", { family = poisson(), data = Salamanders ) - expect_snapshot(print(estimate_means(m, "spp", backend = "marginaleffects"), zap_small = TRUE, table_width = Inf), variant = "windows") # nolint - expect_snapshot(print(estimate_means(m, "spp", backend = "marginaleffects", estimate = "population"), zap_small = TRUE, table_width = Inf), variant = "windows") # nolint + expect_snapshot( + print( + estimate_means(m, "spp", backend = "marginaleffects"), + zap_small = TRUE, + table_width = Inf + ), + variant = "windows" + ) # nolint + expect_snapshot( + print( + estimate_means(m, "spp", backend = "marginaleffects", estimate = "population"), + zap_small = TRUE, + table_width = Inf + ), + variant = "windows" + ) # nolint - expect_snapshot(print(estimate_means(m, "spp", backend = "marginaleffects", predict = "inverse_link"), zap_small = TRUE, table_width = Inf), variant = "windows") # nolint - expect_snapshot(print(estimate_means(m, "spp", backend = "marginaleffects", estimate = "population", predict = "inverse_link"), zap_small = TRUE, table_width = Inf), variant = "windows") # nolint + expect_snapshot( + print( + estimate_means(m, "spp", backend = "marginaleffects", predict = "inverse_link"), + zap_small = TRUE, + table_width = Inf + ), + variant = "windows" + ) # nolint + expect_snapshot( + print( + estimate_means( + m, + "spp", + backend = "marginaleffects", + estimate = "population", + predict = "inverse_link" + ), + zap_small = TRUE, + table_width = Inf + ), + variant = "windows" + ) # nolint out1 <- estimate_means(m, "spp", backend = "marginaleffects", predict = "inverse_link") out2 <- estimate_means(m, "spp", backend = "emmeans") @@ -26,6 +60,20 @@ test_that("estimate_means() - counterfactuals", { set.seed(123) strapped <- sleepstudy[sample.int(nrow(sleepstudy), nrow(sleepstudy), replace = TRUE), ] m <- lme4::lmer(Reaction ~ Days + (1 + Days | Subject), data = strapped) - expect_snapshot(print(estimate_means(m, "Days", backend = "marginaleffects"), zap_small = TRUE, table_width = Inf), variant = "windows") # nolint - expect_snapshot(print(estimate_means(m, "Days", backend = "marginaleffects", estimate = "population"), zap_small = TRUE, table_width = Inf), variant = "windows") # nolint + expect_snapshot( + print( + estimate_means(m, "Days", backend = "marginaleffects"), + zap_small = TRUE, + table_width = Inf + ), + variant = "windows" + ) # nolint + expect_snapshot( + print( + estimate_means(m, "Days", backend = "marginaleffects", estimate = "population"), + zap_small = TRUE, + table_width = Inf + ), + variant = "windows" + ) # nolint }) diff --git a/tests/testthat/test-estimate_means_mixed.R b/tests/testthat/test-estimate_means_mixed.R index 14e8fd05c..a57995ee9 100644 --- a/tests/testthat/test-estimate_means_mixed.R +++ b/tests/testthat/test-estimate_means_mixed.R @@ -98,14 +98,14 @@ test_that("estimate_means() - mixed models", { c(0.20293, 0.08627, 0.07612, 0.04984), tolerance = 1e-3 ) - expect_equal(estim2$CI_low, c(0.13928, 0.04915, 0.04159, 0.02229), tolerance = 1e-3) + expect_equal(estim2$CI_low, c(0.13899, 0.04888, 0.04133, 0.02207), tolerance = 1e-3) expect_true(all(estim2$CI_low >= 0 & estim2$CI_low <= 1)) expect_true(all(estim2$CI_high >= 0 & estim2$CI_high <= 1)) estim3 <- estimate_means(gm1, backend = "marginaleffects", verbose = FALSE) expect_identical(dim(estim3), c(4L, 6L)) expect_equal(estim3$Probability, c(0.21521, 0.0954, 0.08453, 0.05599), tolerance = 1e-3) - expect_equal(estim3$CI_low, c(0.14233, 0.04475, 0.03608, 0.01266), tolerance = 1e-3) + expect_equal(estim3$CI_low, c(0.14194, 0.04428, 0.03559, 0.01215), tolerance = 1e-3) }) diff --git a/tests/testthat/test-estimate_means_print_footer.R b/tests/testthat/test-estimate_means_print_footer.R new file mode 100644 index 000000000..8f964ab8a --- /dev/null +++ b/tests/testthat/test-estimate_means_print_footer.R @@ -0,0 +1,40 @@ +skip_on_cran() + +test_that("estimate_means - print footer for estimate types and re.form", { + skip_if_not_installed("lme4") + skip_if_not_installed("marginaleffects") + skip_if(getRversion() < "4.5.0") + + data(penguins) + set.seed(123) + d <- penguins + d$weights <- abs(rnorm(nrow(d), 1, 0.2)) + model <- lm(body_mass ~ species + sex + bill_len, data = d, weights = weights) + + expect_snapshot(print(estimate_means(model, "sex", estimate = "specific"))) + expect_snapshot(print(estimate_means(model, "sex", estimate = "typical"))) + expect_snapshot(print(estimate_means(model, "sex", estimate = "average"))) + expect_snapshot(print(estimate_means(model, "sex", estimate = "population"))) + + data(cbpp, package = "lme4") + m <- lme4::glmer( + cbind(incidence, size - incidence) ~ period + (1 | herd), + data = cbpp, + family = binomial + ) + + expect_snapshot(print(estimate_means(m, by = "period", estimate = "typical"))) + expect_snapshot(print(estimate_means( + m, + by = "period", + estimate = "typical", + re.form = NA + ))) + expect_snapshot(print(estimate_means(m, by = "period", estimate = "average"))) + expect_snapshot(print(estimate_means( + m, + by = "period", + estimate = "average", + re.form = NA + ))) +}) diff --git a/tests/testthat/test-g_computation.R b/tests/testthat/test-g_computation.R index 75d6d7b27..493edaa23 100644 --- a/tests/testthat/test-g_computation.R +++ b/tests/testthat/test-g_computation.R @@ -5,6 +5,8 @@ skip_on_os("mac") test_that("estimate_contrasts - ATT and ATU", { skip_if_not_installed("Rdatasets") + skip_on_os("linux") + dat <- marginaleffects::get_dataset("lottery") dat <- subset(dat, win_big == 1 | win == 0) dat$win_big <- as.factor(dat$win_big) diff --git a/tests/testthat/test-joint_test.R b/tests/testthat/test-joint_test.R index 21f4f3b1f..d7760af79 100644 --- a/tests/testthat/test-joint_test.R +++ b/tests/testthat/test-joint_test.R @@ -39,6 +39,31 @@ test_that("estimate_contrasts - joint test, 2-way", { expect_equal(out$`F`, 2.352941, tolerance = 1e-3) expect_equal(out$p, 0.07586666, tolerance = 1e-3) expect_equal(attributes(out)$null, mean(predict(m)), tolerance = 1e-3) + expect_identical( + capture.output(out), + c( + "Conditional Omnibus Test", + "", + "df1 | df2 | F | p", + "------------------------", + "3 | 114 | 2.35 | 0.076", + "", + "Predictors averaged over (balanced grid): coffee", + "p-values are uncorrected.", + "Null-hypothesis: Group means equal 16.20" + ) + ) + + # omnibus test, marginal + out <- estimate_contrasts( + m, + contrast = "time", + comparison = "omnibus", + estimate = "average" + ) + expect_equal(out$`F`, 2.352941, tolerance = 1e-3) + expect_equal(out$p, 0.07586666, tolerance = 1e-3) + expect_equal(attributes(out)$null, mean(predict(m)), tolerance = 1e-3) expect_identical( capture.output(out), c( @@ -48,7 +73,7 @@ test_that("estimate_contrasts - joint test, 2-way", { "------------------------", "3 | 114 | 2.35 | 0.076", "", - "Predictors averaged: coffee", + "Predictors averaged over (sample): coffee", "p-values are uncorrected.", "Null-hypothesis: Group means equal 16.20" ) diff --git a/tests/testthat/test-plot.R b/tests/testthat/test-plot.R index a3403fdad..585f86a65 100644 --- a/tests/testthat/test-plot.R +++ b/tests/testthat/test-plot.R @@ -13,30 +13,36 @@ test_that("plots emmeans", { x <- estimate_means(model, by = "Species", backend = "emmeans") vdiffr::expect_doppelganger( "plot-means-1", - plot(modelbased::visualisation_recipe(x, show_data = FALSE)) + plot(modelbased::visualisation_recipe(x, show_data = FALSE)), + variant = "windows" ) vdiffr::expect_doppelganger( "plot-means-1-lines", - plot(modelbased::visualisation_recipe(x, show_data = FALSE, join_dots = TRUE)) + plot(modelbased::visualisation_recipe(x, show_data = FALSE, join_dots = TRUE)), + variant = "windows" ) x <- estimate_means(model, by = "Sepal.Width", backend = "emmeans") vdiffr::expect_doppelganger( "plot-means-2", - plot(modelbased::visualisation_recipe(x, show_data = FALSE)) + plot(modelbased::visualisation_recipe(x, show_data = FALSE)), + variant = "windows" ) x <- estimate_means(model, by = c("Sepal.Width", "Species"), backend = "emmeans") vdiffr::expect_doppelganger( "plot-means-3", - plot(modelbased::visualisation_recipe(x, show_data = FALSE)) + plot(modelbased::visualisation_recipe(x, show_data = FALSE)), + variant = "windows" ) x <- estimate_means(model, by = c("Species", "Sepal.Width"), backend = "emmeans") vdiffr::expect_doppelganger( "plot-means-4", - plot(modelbased::visualisation_recipe(x, show_data = FALSE)) + plot(modelbased::visualisation_recipe(x, show_data = FALSE)), + variant = "windows" ) vdiffr::expect_doppelganger( "plot-means-4-lines", - plot(modelbased::visualisation_recipe(x, show_data = FALSE, join_dots = TRUE)) + plot(modelbased::visualisation_recipe(x, show_data = FALSE, join_dots = TRUE)), + variant = "windows" ) }) @@ -49,25 +55,29 @@ test_that("plots, show_data", { set.seed(123) vdiffr::expect_doppelganger( "plot-means-showdata-1", - plot(modelbased::visualisation_recipe(x, show_data = TRUE)) + plot(modelbased::visualisation_recipe(x, show_data = TRUE)), + variant = "windows" ) x <- estimate_means(model, by = "Sepal.Width") set.seed(123) vdiffr::expect_doppelganger( "plot-means-showdata-2", - plot(modelbased::visualisation_recipe(x, show_data = TRUE)) + plot(modelbased::visualisation_recipe(x, show_data = TRUE)), + variant = "windows" ) x <- estimate_means(model, by = c("Sepal.Width", "Species")) set.seed(123) vdiffr::expect_doppelganger( "plot-means-showdata-3", - plot(modelbased::visualisation_recipe(x, show_data = TRUE)) + plot(modelbased::visualisation_recipe(x, show_data = TRUE)), + variant = "windows" ) x <- estimate_means(model, by = c("Species", "Sepal.Width")) set.seed(123) vdiffr::expect_doppelganger( "plot-means-showdata-4", - plot(modelbased::visualisation_recipe(x, show_data = TRUE)) + plot(modelbased::visualisation_recipe(x, show_data = TRUE)), + variant = "windows" ) }) @@ -79,12 +89,14 @@ test_that("plots marginalmeans", { x <- estimate_means(model, by = "Species", backend = "marginaleffects") vdiffr::expect_doppelganger( "plot-me-means-1", - plot(modelbased::visualisation_recipe(x, show_data = FALSE)) + plot(modelbased::visualisation_recipe(x, show_data = FALSE)), + variant = "windows" ) x <- estimate_means(model, by = "Sepal.Width", backend = "marginaleffects") vdiffr::expect_doppelganger( "plot-me-means-2", - plot(modelbased::visualisation_recipe(x, show_data = FALSE)) + plot(modelbased::visualisation_recipe(x, show_data = FALSE)), + variant = "windows" ) x <- estimate_means( model, @@ -93,7 +105,8 @@ test_that("plots marginalmeans", { ) vdiffr::expect_doppelganger( "plot-me-means-3", - plot(modelbased::visualisation_recipe(x, show_data = FALSE)) + plot(modelbased::visualisation_recipe(x, show_data = FALSE)), + variant = "windows" ) x <- estimate_means( model, @@ -102,7 +115,8 @@ test_that("plots marginalmeans", { ) vdiffr::expect_doppelganger( "plot-me-means-4", - plot(modelbased::visualisation_recipe(x, show_data = FALSE)) + plot(modelbased::visualisation_recipe(x, show_data = FALSE)), + variant = "windows" ) }) @@ -115,13 +129,15 @@ test_that("plots marginalmeans, show_data", { set.seed(123) vdiffr::expect_doppelganger( "plot-me-means-showdata-1", - plot(modelbased::visualisation_recipe(x, show_data = TRUE)) + plot(modelbased::visualisation_recipe(x, show_data = TRUE)), + variant = "windows" ) x <- estimate_means(model, by = "Sepal.Width", backend = "marginaleffects") set.seed(123) vdiffr::expect_doppelganger( "plot-me-means-showdata-2", - plot(modelbased::visualisation_recipe(x, show_data = TRUE)) + plot(modelbased::visualisation_recipe(x, show_data = TRUE)), + variant = "windows" ) x <- estimate_means( model, @@ -131,7 +147,8 @@ test_that("plots marginalmeans, show_data", { set.seed(123) vdiffr::expect_doppelganger( "plot-me-means-showdata-3", - plot(modelbased::visualisation_recipe(x, show_data = TRUE)) + plot(modelbased::visualisation_recipe(x, show_data = TRUE)), + variant = "windows" ) x <- estimate_means( model, @@ -141,7 +158,8 @@ test_that("plots marginalmeans, show_data", { set.seed(123) vdiffr::expect_doppelganger( "plot-me-means-showdata-4", - plot(modelbased::visualisation_recipe(x, show_data = TRUE)) + plot(modelbased::visualisation_recipe(x, show_data = TRUE)), + variant = "windows" ) }) @@ -153,22 +171,26 @@ test_that("plots relation", { x <- estimate_relation(model, by = "Species") vdiffr::expect_doppelganger( "plot-relation-1", - plot(modelbased::visualisation_recipe(x, show_data = FALSE)) + plot(modelbased::visualisation_recipe(x, show_data = FALSE)), + variant = "windows" ) x <- estimate_relation(model, by = "Sepal.Width") vdiffr::expect_doppelganger( "plot-relation-2", - plot(modelbased::visualisation_recipe(x, show_data = FALSE)) + plot(modelbased::visualisation_recipe(x, show_data = FALSE)), + variant = "windows" ) x <- estimate_relation(model, by = c("Sepal.Width", "Species")) vdiffr::expect_doppelganger( "plot-relation-3", - plot(modelbased::visualisation_recipe(x, show_data = FALSE)) + plot(modelbased::visualisation_recipe(x, show_data = FALSE)), + variant = "windows" ) x <- estimate_relation(model, by = c("Species", "Sepal.Width")) vdiffr::expect_doppelganger( "plot-relation-4", - plot(modelbased::visualisation_recipe(x, show_data = FALSE)) + plot(modelbased::visualisation_recipe(x, show_data = FALSE)), + variant = "windows" ) }) @@ -181,25 +203,29 @@ test_that("plots, relation show_data", { set.seed(123) vdiffr::expect_doppelganger( "plot-relation-showdata-1", - plot(modelbased::visualisation_recipe(x, show_data = TRUE)) + plot(modelbased::visualisation_recipe(x, show_data = TRUE)), + variant = "windows" ) x <- estimate_relation(model, by = "Sepal.Width") set.seed(123) vdiffr::expect_doppelganger( "plot-relation-showdata-2", - plot(modelbased::visualisation_recipe(x, show_data = TRUE)) + plot(modelbased::visualisation_recipe(x, show_data = TRUE)), + variant = "windows" ) x <- estimate_relation(model, by = c("Sepal.Width", "Species")) set.seed(123) vdiffr::expect_doppelganger( "plot-relation-showdata-3", - plot(modelbased::visualisation_recipe(x, show_data = TRUE)) + plot(modelbased::visualisation_recipe(x, show_data = TRUE)), + variant = "windows" ) x <- estimate_relation(model, by = c("Species", "Sepal.Width")) set.seed(123) vdiffr::expect_doppelganger( "plot-relation-showdata-4", - plot(modelbased::visualisation_recipe(x, show_data = TRUE)) + plot(modelbased::visualisation_recipe(x, show_data = TRUE)), + variant = "windows" ) }) @@ -218,7 +244,8 @@ test_that("plots, relation, percentage for logistic", { set.seed(123) vdiffr::expect_doppelganger( "plot-relation-logistic-percentage-1", - plot(modelbased::visualisation_recipe(out)) + plot(modelbased::visualisation_recipe(out)), + variant = "windows" ) }) @@ -229,11 +256,15 @@ test_that("plots, grouplevel lme4", { d$Newfactor <- rep(c("A", "B", "C", "D")) model <- lme4::lmer(Reaction ~ Days + (1 + Days | Subject) + (1 | Newfactor), data = d) set.seed(123) - vdiffr::expect_doppelganger("plot-grouplevel-lme4-1", plot(estimate_grouplevel(model))) + vdiffr::expect_doppelganger( + "plot-grouplevel-lme4-1", + plot(estimate_grouplevel(model)), + variant = "windows" + ) out <- estimate_grouplevel(model) vr <- visualisation_recipe(out, pointrange = list(color = "black")) set.seed(123) - vdiffr::expect_doppelganger("plot-grouplevel-lme4-2", plot(vr)) + vdiffr::expect_doppelganger("plot-grouplevel-lme4-2", plot(vr), variant = "windows") }) @@ -242,7 +273,11 @@ test_that("plots, relation, multiple CI", { m <- lm(mpg ~ qsec, data = mtcars) em <- estimate_relation(m, ci = c(0.5, 0.8, 0.9)) set.seed(123) - vdiffr::expect_doppelganger("plot-relation-multiple-ci-1", plot(em, show_data = TRUE)) + vdiffr::expect_doppelganger( + "plot-relation-multiple-ci-1", + plot(em, show_data = TRUE), + variant = "windows" + ) }) @@ -252,7 +287,11 @@ test_that("plots, estimate_means works with Poisson", { dat_glm <- glm(y ~ fa, data = dat, family = poisson(link = "log")) x <- estimate_means(dat_glm, "fa", backend = "emmeans") set.seed(123) - vdiffr::expect_doppelganger("plot-means-poisson-1", plot(x, show_data = TRUE)) + vdiffr::expect_doppelganger( + "plot-means-poisson-1", + plot(x, show_data = TRUE), + variant = "windows" + ) set.seed(123) vdiffr::expect_doppelganger( "plot-means-poisson-1-lines", @@ -260,7 +299,11 @@ test_that("plots, estimate_means works with Poisson", { ) x <- estimate_means(dat_glm, "fa", backend = "marginaleffects") set.seed(123) - vdiffr::expect_doppelganger("plot-means-poisson-2", plot(x, show_data = TRUE)) + vdiffr::expect_doppelganger( + "plot-means-poisson-2", + plot(x, show_data = TRUE), + variant = "windows" + ) }) @@ -269,24 +312,40 @@ test_that("plots, estimate_means, order of predictors", { model <- lm(Petal.Length ~ Sepal.Width * Species, data = iris) pr <- estimate_means(model, by = c("Species", "Sepal.Width"), backend = "emmeans") set.seed(123) - vdiffr::expect_doppelganger("plot-means-predictor-order-1", plot(pr, show_data = FALSE)) + vdiffr::expect_doppelganger( + "plot-means-predictor-order-1", + plot(pr, show_data = FALSE), + variant = "windows" + ) pr <- estimate_means(model, by = c("Sepal.Width", "Species"), backend = "emmeans") set.seed(123) - vdiffr::expect_doppelganger("plot-means-predictor-order-2", plot(pr, show_data = FALSE)) + vdiffr::expect_doppelganger( + "plot-means-predictor-order-2", + plot(pr, show_data = FALSE), + variant = "windows" + ) pr <- estimate_means( model, by = c("Species", "Sepal.Width"), backend = "marginaleffects" ) set.seed(123) - vdiffr::expect_doppelganger("plot-means-predictor-order-3", plot(pr, show_data = FALSE)) + vdiffr::expect_doppelganger( + "plot-means-predictor-order-3", + plot(pr, show_data = FALSE), + variant = "windows" + ) pr <- estimate_means( model, by = c("Sepal.Width", "Species"), backend = "marginaleffects" ) set.seed(123) - vdiffr::expect_doppelganger("plot-means-predictor-order-4", plot(pr, show_data = FALSE)) + vdiffr::expect_doppelganger( + "plot-means-predictor-order-4", + plot(pr, show_data = FALSE), + variant = "windows" + ) }) @@ -297,29 +356,57 @@ test_that("plots, numeric or categorical predictors are detected", { m_cat <- lm(mpg ~ cyl, data = dat) pr <- estimate_expectation(m_cat, by = "cyl") set.seed(123) - vdiffr::expect_doppelganger("plot-cat-num-predictor-1", plot(pr, show_data = FALSE)) + vdiffr::expect_doppelganger( + "plot-cat-num-predictor-1", + plot(pr, show_data = FALSE), + variant = "windows" + ) pr <- estimate_means(m_cat, by = "cyl", backend = "marginaleffects") set.seed(123) - vdiffr::expect_doppelganger("plot-cat-num-predictor-2", plot(pr, show_data = FALSE)) + vdiffr::expect_doppelganger( + "plot-cat-num-predictor-2", + plot(pr, show_data = FALSE), + variant = "windows" + ) m_cat <- lm(mpg ~ cyl, data = mtcars) pr <- estimate_expectation(m_cat, by = "cyl") set.seed(123) - vdiffr::expect_doppelganger("plot-cat-num-predictor-3", plot(pr, show_data = FALSE)) + vdiffr::expect_doppelganger( + "plot-cat-num-predictor-3", + plot(pr, show_data = FALSE), + variant = "windows" + ) pr <- estimate_means(m_cat, by = "cyl", backend = "marginaleffects") set.seed(123) - vdiffr::expect_doppelganger("plot-cat-num-predictor-4", plot(pr, show_data = FALSE)) + vdiffr::expect_doppelganger( + "plot-cat-num-predictor-4", + plot(pr, show_data = FALSE), + variant = "windows" + ) pr <- estimate_expectation(m_cat, by = "cyl", range = "grid") set.seed(123) - vdiffr::expect_doppelganger("plot-cat-num-predictor-5", plot(pr, show_data = FALSE)) + vdiffr::expect_doppelganger( + "plot-cat-num-predictor-5", + plot(pr, show_data = FALSE), + variant = "windows" + ) data(efc, package = "modelbased") m <- lm(neg_c_7 ~ barthtot, data = efc) pr <- estimate_means(m, by = "barthtot", backend = "marginaleffects") set.seed(123) - vdiffr::expect_doppelganger("plot-cat-num-predictor-6", plot(pr, show_data = FALSE)) + vdiffr::expect_doppelganger( + "plot-cat-num-predictor-6", + plot(pr, show_data = FALSE), + variant = "windows" + ) pr <- estimate_means(m, by = "barthtot", range = "grid", backend = "marginaleffects") set.seed(123) - vdiffr::expect_doppelganger("plot-cat-num-predictor-7", plot(pr, show_data = FALSE)) + vdiffr::expect_doppelganger( + "plot-cat-num-predictor-7", + plot(pr, show_data = FALSE), + variant = "windows" + ) }) @@ -332,7 +419,11 @@ test_that("plots, at special values", { preserve_range = FALSE ) set.seed(123) - vdiffr::expect_doppelganger("plot-expectation-fivenum", plot(pr, show_data = FALSE)) + vdiffr::expect_doppelganger( + "plot-expectation-fivenum", + plot(pr, show_data = FALSE), + variant = "windows" + ) set.seed(123) vdiffr::expect_doppelganger( "plot-expectation-fivenum.2", @@ -353,7 +444,7 @@ test_that("plots, estimate_slope", { backend = "emmeans" ) set.seed(123) - vdiffr::expect_doppelganger("plot-slopes-1", plot(slopes)) + vdiffr::expect_doppelganger("plot-slopes-1", plot(slopes), variant = "windows") model <- lm(Sepal.Width ~ Petal.Width * Petal.Length, data = iris) slopes <- estimate_slopes( @@ -363,7 +454,7 @@ test_that("plots, estimate_slope", { backend = "emmeans" ) set.seed(123) - vdiffr::expect_doppelganger("plot-slopes-2", plot(slopes)) + vdiffr::expect_doppelganger("plot-slopes-2", plot(slopes), variant = "windows") model <- lm(Sepal.Width ~ Species * Petal.Length, data = iris) slopes <- estimate_slopes( @@ -373,7 +464,7 @@ test_that("plots, estimate_slope", { backend = "marginaleffects" ) set.seed(123) - vdiffr::expect_doppelganger("plot-slopes-3", plot(slopes)) + vdiffr::expect_doppelganger("plot-slopes-3", plot(slopes), variant = "windows") model <- lm(Sepal.Width ~ Petal.Width * Petal.Length, data = iris) slopes <- estimate_slopes( @@ -384,7 +475,7 @@ test_that("plots, estimate_slope", { backend = "marginaleffects" ) set.seed(123) - vdiffr::expect_doppelganger("plot-slopes-4", plot(slopes)) + vdiffr::expect_doppelganger("plot-slopes-4", plot(slopes), variant = "windows") data(iris) x <- iris @@ -398,7 +489,7 @@ test_that("plots, estimate_slope", { backend = "marginaleffects" ) set.seed(123) - vdiffr::expect_doppelganger("plot-slopes-5", plot(slopes)) + vdiffr::expect_doppelganger("plot-slopes-5", plot(slopes), variant = "windows") }) @@ -407,10 +498,18 @@ test_that("plots, automatically join dots", { m <- lm(Sepal.Width ~ Petal.Length + Species * Petal.Width, data = iris) out <- estimate_expectation(m, by = c("Species", "Petal.Width")) set.seed(123) - vdiffr::expect_doppelganger("plot-join-dots-1", plot(out, show_data = TRUE)) + vdiffr::expect_doppelganger( + "plot-join-dots-1", + plot(out, show_data = TRUE), + variant = "windows" + ) out <- estimate_expectation(m, by = c("Species", "Petal.Width"), preserve_range = FALSE) set.seed(123) - vdiffr::expect_doppelganger("plot-join-dots-2", plot(out, show_data = TRUE)) + vdiffr::expect_doppelganger( + "plot-join-dots-2", + plot(out, show_data = TRUE), + variant = "windows" + ) }) @@ -419,7 +518,11 @@ test_that("plots, logistic regression", { model <- glm(vs ~ wt, data = mtcars, family = "binomial") out <- estimate_means(model, "wt", length = 100, backend = "marginaleffects") set.seed(123) - vdiffr::expect_doppelganger("plot-glm-logistic-1", plot(out, show_data = TRUE)) + vdiffr::expect_doppelganger( + "plot-glm-logistic-1", + plot(out, show_data = TRUE), + variant = "windows" + ) out <- estimate_means( model, "wt", @@ -428,7 +531,11 @@ test_that("plots, logistic regression", { backend = "marginaleffects" ) set.seed(123) - vdiffr::expect_doppelganger("plot-glm-logistic-2", plot(out, show_data = TRUE)) + vdiffr::expect_doppelganger( + "plot-glm-logistic-2", + plot(out, show_data = TRUE), + variant = "windows" + ) }) @@ -441,7 +548,11 @@ test_that("plots, 4-way with numeric", { by <- c("c12hour", "c161sex", "c172code", "barthtot = [fivenum]") estim <- estimate_means(m, by = by, backend = "marginaleffects") set.seed(123) - vdiffr::expect_doppelganger("plot-4way-numeric-1", plot(estim, show_data = FALSE)) + vdiffr::expect_doppelganger( + "plot-4way-numeric-1", + plot(estim, show_data = FALSE), + variant = "windows" + ) }) @@ -455,7 +566,11 @@ test_that("plots, glm logistic inside bound", { m <- glm(outcome ~ var1 * var2, data = data, family = binomial(link = "logit")) out1 <- estimate_means(m, c("var2 = [sd]", "var1"), backend = "marginaleffects") set.seed(123) - vdiffr::expect_doppelganger("plot-logistic-bounds-1", plot(out1, show_data = FALSE)) + vdiffr::expect_doppelganger( + "plot-logistic-bounds-1", + plot(out1, show_data = FALSE), + variant = "windows" + ) set.seed(123) vdiffr::expect_doppelganger( "plot-logistic-bounds-2", diff --git a/tests/testthat/test-table_footer.R b/tests/testthat/test-table_footer.R index 0ab4d775e..bef172532 100644 --- a/tests/testthat/test-table_footer.R +++ b/tests/testthat/test-table_footer.R @@ -5,18 +5,30 @@ test_that("table_footer", { data(efc, package = "modelbased") efc <- datawizard::to_factor(efc, c("c161sex", "c172code", "e16sex", "e42dep")) m <- lm(neg_c_7 ~ c12hour + barthtot + c161sex + e42dep + c172code, data = efc) - out <- utils::capture.output(estimate_means(m, "c172code", estimate = "specific", verbose = FALSE)) - expect_identical( - out[11], - "Predictors controlled: c12hour (42), barthtot (65), c161sex (Male), e42dep (independent)" - ) - out <- utils::capture.output(estimate_means(m, "c172code", estimate = "typical", verbose = FALSE)) + out <- utils::capture.output(estimate_means( + m, + "c172code", + estimate = "specific", + verbose = FALSE + )) expect_identical( out[11], - "Predictors averaged: c12hour (42), barthtot (65), c161sex, e42dep" + "Predictors held at: c12hour (42), barthtot (65), c161sex (Male), e42dep (independent)" ) - out <- utils::capture.output(estimate_means(m, "c172code", estimate = "average", verbose = FALSE)) - expect_length(out, 10) + out <- utils::capture.output(estimate_means( + m, + "c172code", + estimate = "typical", + verbose = FALSE + )) + expect_identical(out[11], "Predictors held at: c12hour (42), barthtot (65)") + out <- utils::capture.output(estimate_means( + m, + "c172code", + estimate = "average", + verbose = FALSE + )) + expect_length(out, 12) }) @@ -103,9 +115,13 @@ test_that("table_footer, link-scale and transform", { transform = exp ))) expect_true("Contrasts are on the transformed link-scale." %in% out) - out <- utils::capture.output( - estimate_contrasts(g, "wt", by = "cyl", predict = "link", transform = exp) - ) + out <- utils::capture.output(estimate_contrasts( + g, + "wt", + by = "cyl", + predict = "link", + transform = exp + )) expect_true("Contrasts are on the transformed link-scale." %in% out) }) @@ -119,6 +135,10 @@ test_that("table_footer, no prediction intervals if insight falls back", { "predict" ) skip_if(identical(predict_type, "prediction")) - out <- utils::capture.output(suppressWarnings(estimate_prediction(m, data = "grid", length = 3))) + out <- utils::capture.output(suppressWarnings(estimate_prediction( + m, + data = "grid", + length = 3 + ))) expect_false("Intervals are prediction intervals." %in% out) }) diff --git a/vignettes/mixed_models.Rmd b/vignettes/mixed_models.Rmd index 3230ee7ad..a29d32496 100644 --- a/vignettes/mixed_models.Rmd +++ b/vignettes/mixed_models.Rmd @@ -126,7 +126,7 @@ estimate_means(model, "sex", estimate = "average") estimate_means(model, "sex", estimate = "average", re.form = NA) ``` -### Excourse: Technical Details +### Excursus: Technical Details ::: custom_note To better understand how these predictions are computed under the hood, let's break down the underlying workflow. The code below illustrates the manual step-by-step procedures for grid-based versus sample-averaged predictions. diff --git a/vignettes/post_estimation_framework.Rmd b/vignettes/post_estimation_framework.Rmd index 603874c00..cfccabb35 100644 --- a/vignettes/post_estimation_framework.Rmd +++ b/vignettes/post_estimation_framework.Rmd @@ -81,7 +81,7 @@ knitr::include_graphics("../man/figures/from-model-to-meaning-final.png") ## Defining the Estimands: Five Questions, One Model -Before setting up any statistical model, researchers must explicitly spell out their theoretical estimands in precise terms. An estimand is the specific target quantity (and unit) that directly answers the research question [@lundberg_what_2021]. Instead of passively interpreting whatever coefficients the software returns, we must actively decide whether our question requires us to estimate *predictions*, *slopes*, or *comparisons* (*quantity*),and determine to which target population we want to generalize our results (*unit*) [@rohrer_models_2026; @rohrer_these_2023]. +Before setting up any statistical model, researchers must explicitly spell out their theoretical estimands in precise terms. An estimand is the specific target quantity (and unit) that directly answers the research question [@lundberg_what_2021]. Instead of passively interpreting whatever coefficients the software returns, we must actively decide whether our question requires us to estimate *predictions*, *slopes*, or *comparisons* (*quantity*), and determine to which target population we want to generalize our results (*unit*) [@rohrer_models_2026; @rohrer_these_2023]. --- @@ -102,7 +102,7 @@ In this vignette, we will use a single model to target five distinct estimands: Once these target quantities are clearly defined, we can proceed to construct the mathematical model that will allow us to estimate them. ::: custom_note -**The estimand - quantity and unit of interests** +**The estimand - quantity and unit of interest** Defining your *estimand* requires specifying both the *quantity* and the *unit* of interest. Thus, determining your target population (*unit*) - whether that is a specific individual, an average across individuals, or a broader population - is just as crucial as choosing between predictions, contrasts or slopes (*quantity*) [@lundberg_what_2021; @rohrer_models_2026]. @@ -209,7 +209,7 @@ model <- glmmTMB( ## Interpreting the output -When looking at the standard regression table, it is crucial to interpret these coefficients as *descriptive comparisons*. Specifically, coefficients generally represent *conditional effects*, meaning they describe an association while *strictly holding all other covariates constant* (@gelman_regression_2020; Chapter 6.3), i.e., comparing individuals who are identical regarding these characteristics. +When looking at the standard regression table, it is crucial to interpret these coefficients as *descriptive comparisons*. Specifically, coefficients generally represent *conditional effects*, meaning they describe an association while *strictly holding all other covariates constant* (@gelman_regression_2020; Chapter 6.3), i.e., comparing individuals who are **identical** regarding these characteristics. ```{r, } result <- model_parameters(model, effects = "fixed") @@ -221,11 +221,15 @@ display( ### The Interpretation Trap -The "interpretation trap" occurs when researchers forget that regression coefficients must be interpreted conditionally - meaning they only compare individuals who share the exact same characteristics across all other variables. +The "interpretation trap" occurs when researchers forget that regression coefficients must be interpreted conditionally - meaning they only compare individuals who share **the exact same** characteristics across all other variables. -- **Categorical Predictors:** Estimates are interpreted relative to a baseline reference category. For instance, the coefficient for `symptoms_unreal ((strongly) disagree)` is `r round(result$Coefficient[result$Parameter == "symptoms_unreal(strongly) disagree"], 2)`. This indicates that, holding `time`, `sex`, `age`, and all other covariates constant, patients who disagree that their symptoms are "unreal" score `r abs(round(result$Coefficient[result$Parameter == "symptoms_unreal(strongly) disagree"], 2))` points lower on the PHQ-15 than those in the implicit reference category (who agree). +- **Categorical Predictors:** Estimates are interpreted relative to a baseline reference category. For instance, the coefficient for `symptoms_unreal ((strongly) disagree)` is `r if (isTRUE(knitr::opts_chunk$get("eval"))) round(result$Coefficient[result$Parameter == "symptoms_unreal(strongly) disagree"], 2) else -1.36`. This indicates that, holding `time`, `sex`, `age`, and all other covariates constant, patients who disagree that their symptoms are "unreal" score `r if (isTRUE(knitr::opts_chunk$get("eval"))) abs(round(result$Coefficient[result$Parameter == "symptoms_unreal(strongly) disagree"], 2)) else 1.36` points lower on the PHQ-15 than those in the implicit reference category (who agree). -- **Continuous Predictors:** Estimates reflect the expected change associated with a one-unit increase in the predictor. The `time` coefficient of `r round(result$Coefficient[result$Parameter == "time"], 2)` suggests a `r abs(round(result$Coefficient[result$Parameter == "time"], 2))`-point decrease in PHQ-15 scores for every single unit of time passed, again, assuming *all other variables are held constant*. +- **Continuous Predictors:** Estimates reflect the expected change associated with a one-unit increase in the predictor. The `time` coefficient of `r if (isTRUE(knitr::opts_chunk$get("eval"))) round(result$Coefficient[result$Parameter == "time"], 2) else -0.69` suggests a `r if (isTRUE(knitr::opts_chunk$get("eval"))) abs(round(result$Coefficient[result$Parameter == "time"], 2)) else 0.69`-point decrease in PHQ-15 scores for every single unit of time passed, again, assuming *all other variables are held constant*. + +::: custom_note +Conditioning on covariates means we *might* end up comparing individuals who do not exist in our sample - such as an unmarried, highly educated 67-year-old man and woman. While this *can* be a meaningful comparison, it often is not, which is why regression coefficients rarely answer our research questions directly. After all, do we want to compare 67-year-old, highly educated, unmarried women and men - or women and men in general? See the callout-box above, "The estimand - quantity and unit of interest". +::: --- diff --git a/vignettes/practical_intersectionality.Rmd b/vignettes/practical_intersectionality.Rmd index d6ecd8174..c21a80eff 100644 --- a/vignettes/practical_intersectionality.Rmd +++ b/vignettes/practical_intersectionality.Rmd @@ -68,7 +68,7 @@ The steps we are showing here are: 1. Defining the intersectional strata. -2. Fitting a *simple intersectional* model to see whether intersectional strata contribute to between-stratum variance (which can be considered as "inequalities", whether social or health related - also known as _discriminatory accucarcy_). +2. Fitting a *simple intersectional* model to see whether intersectional strata contribute to between-stratum variance (which can be considered as "inequalities", whether social or health related - also known as _discriminatory accuracy_). 3. Fitting *partially-adjusted intersectional* models and calculating proportional change in the between-stratum variance (PCVs) to quantify to what degree the different intersectional dimensions contribute to the between-stratum variance (inequalities) @@ -138,7 +138,7 @@ m_null <- glmmTMB(qol ~ 1 + (1 | gender:employed:age), data = efc) # m_null <- glmmTMB(qol ~ 1 + (1 | strata), data = efc) ``` -The purpose of this model - which is sometimes also called *null model* or *base model* - is to quantify the "discriminatory accuracy", which is achieved by calculating the ICC (see [`performance::icc()`](https://easystats.github.io/performance/reference/icc.html)) of this model (sometimes also calles the _VPC_, the variance partition coefficient). The higher the ICC, the greater the degree of similarity _within the strata_ (regarding quality of life) and the greater the difference in quality of life _between the intersectional strata_. I.e., the higher the ICC, the better the model is at discriminating individuals with higher or lower quality of life score, as opposed to models with lower ICC. +The purpose of this model - which is sometimes also called *null model* or *base model* - is to quantify the "discriminatory accuracy", which is achieved by calculating the ICC (see [`performance::icc()`](https://easystats.github.io/performance/reference/icc.html)) of this model (sometimes also called the _VPC_, the variance partition coefficient). The higher the ICC, the greater the degree of similarity _within the strata_ (regarding quality of life) and the greater the difference in quality of life _between the intersectional strata_. I.e., the higher the ICC, the better the model is at discriminating individuals with higher or lower quality of life score, as opposed to models with lower ICC. We now look at the model parameters and the ICC of our simple intersectional model. @@ -319,7 +319,7 @@ As expected (because the PCV is 1, indicating we found no multiplicative effects Compared to a MAIHDA analysis using *linear* regression models, there are two important aspects to consider when using *binary logistic* regression models. -### 7.1 Additive and multiplicatice effects +### 7.1 Additive and multiplicative effects When applying this framework to dichotomous outcomes using logistic multilevel models, two important distinctions must be considered. First, the within-strata (level 1) variance is not estimated, as the variance of the binomial distribution is already known (and fixed, see [`?insight::get_variance`](https://easystats.github.io/insight/reference/get_variance.html) for Bernoulli models). Second, logistic models operate on a multiplicative scale rather than an additive one. According to Evans et al. (2018), it is inappropriate to use logistic models to examine strata-level residuals for additive interaction effects, since the inclusion of main effects may already account for some of these interactions. However, logistic models remain fully appropriate if the primary goal is to estimate strata-level effects to explore the overall patterning of inequalities across strata-groups [@evans_multilevel_2018].