diff --git a/DESCRIPTION b/DESCRIPTION index 2701c55e7..0e165dd55 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: parameters Title: Processing of Model Parameters -Version: 0.28.0.4 +Version: 0.28.0.6 Authors@R: c(person(given = "Daniel", family = "Lüdecke", @@ -231,4 +231,4 @@ Config/testthat/parallel: true Config/Needs/website: easystats/easystatstemplate Config/Needs/check: stan-dev/cmdstanr Config/rcmdcheck/ignore-inconsequential-notes: true -Remotes: easystats/insight +Remotes: easystats/insight, easystats/bayestestR, vincentarelbundock/marginaleffects diff --git a/NAMESPACE b/NAMESPACE index 475b2ab89..5933be9ac 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -277,7 +277,6 @@ S3method(model_parameters,lqm) S3method(model_parameters,lqmm) S3method(model_parameters,maov) S3method(model_parameters,marginaleffects) -S3method(model_parameters,marginalmeans) S3method(model_parameters,margins) S3method(model_parameters,maxLik) S3method(model_parameters,maxim) diff --git a/R/methods_marginaleffects.R b/R/methods_marginaleffects.R index 3361b5f5d..60b66e545 100644 --- a/R/methods_marginaleffects.R +++ b/R/methods_marginaleffects.R @@ -48,9 +48,7 @@ model_parameters.marginaleffects <- function(model, # do not print or report these columns out <- out[, !colnames(out) %in% c("predicted_lo", "predicted_hi"), drop = FALSE] - if (inherits(model, "marginalmeans")) { - attr(out, "coefficient_name") <- "Marginal Means" - } else if (inherits(model, "comparisons")) { + if (inherits(model, "comparisons")) { attr(out, "coefficient_name") <- "Estimate" attr(out, "title") <- "Contrasts between Adjusted Predictions" if ("Type" %in% colnames(out)) { @@ -88,10 +86,6 @@ model_parameters.marginaleffects <- function(model, model_parameters.comparisons <- model_parameters.marginaleffects -#' @export -model_parameters.marginalmeans <- model_parameters.marginaleffects - - #' @export model_parameters.hypotheses <- model_parameters.marginaleffects @@ -109,9 +103,9 @@ model_parameters.predictions <- function(model, insight::check_if_installed("marginaleffects") # Bayesian models have posterior draws as attribute - is_bayes <- !is.null(suppressWarnings(marginaleffects::get_draws(model, "PxD"))) + is_bayesian <- !is.null(suppressWarnings(marginaleffects::get_draws(model, "PxD"))) - if (is_bayes) { + if (is_bayesian) { # Bayesian out <- suppressWarnings(bayestestR::describe_posterior( model, @@ -137,10 +131,11 @@ model_parameters.predictions <- function(model, out$rowid <- out$Type <- out$rowid_dedup <- NULL # find at-variables - at_variables <- attributes(model)$newdata_at - if (is.null(at_variables)) { - at_variables <- attributes(model)$by - } + at_variables <- c( + marginaleffects::components(model, "variable_names_datagrid"), + marginaleffects::components(model, "variable_names_by"), + marginaleffects::components(model, "variable_names_by_hypothesis") + ) # find cofficient name - differs for Bayesian models coef_name <- intersect(c("Predicted", "Coefficient"), colnames(out))[1] @@ -153,7 +148,7 @@ model_parameters.predictions <- function(model, } # extract response, remove from data frame - reg_model <- attributes(model)$model + reg_model <- marginaleffects::components(model, "model") if (!is.null(reg_model) && insight::is_model(reg_model)) { resp <- insight::find_response(reg_model) # check if response could be extracted diff --git a/tests/testthat/_snaps/brms.md b/tests/testthat/_snaps/brms.md index 03df7fca3..b79172f3b 100644 --- a/tests/testthat/_snaps/brms.md +++ b/tests/testthat/_snaps/brms.md @@ -5,13 +5,13 @@ Output # Fixed Effects - Parameter | Median | 95% CI | pd | Rhat | ESS - ---------------------------------------------------------------------- - (Intercept) | -0.25 | [-1.28, 0.75] | 68.62% | 0.999 | 3459.00 - var_binom1 | -0.64 | [-2.09, 0.64] | 83.20% | 1.000 | 2820.00 - groupsb | -0.22 | [-1.35, 0.87] | 64.75% | 1.000 | 3332.00 - var_cont | -0.06 | [-0.14, 0.00] | 96.65% | 1.000 | 3528.00 - var_binom1:groupsb | 0.53 | [-1.70, 2.69] | 69.25% | 1.000 | 2699.00 + Parameter | Median | 95% CI | pd | Rhat | ESS + ------------------------------------------------------------------- + (Intercept) | -0.25 | [-1.28, 0.75] | 68.62% | 0.999 | 3459 + var_binom1 | -0.64 | [-2.09, 0.64] | 83.20% | 1.000 | 2820 + groupsb | -0.22 | [-1.35, 0.87] | 64.75% | 1.000 | 3332 + var_cont | -0.06 | [-0.14, 0.00] | 96.65% | 1.000 | 3528 + var_binom1:groupsb | 0.53 | [-1.70, 2.69] | 69.25% | 1.000 | 2699 Message Uncertainty intervals (equal-tailed) computed using a MCMC distribution @@ -27,13 +27,13 @@ Output # Fixed Effects - Parameter | Median | 95% CI | pd | Rhat | ESS - ---------------------------------------------------------------------- - (Intercept) | 0.78 | [0.28, 2.11] | 68.62% | 0.999 | 3459.00 - var_binom1 | 0.53 | [0.12, 1.90] | 83.20% | 1.000 | 2820.00 - groupsb | 0.80 | [0.26, 2.38] | 64.75% | 1.000 | 3332.00 - var_cont | 0.94 | [0.87, 1.00] | 96.65% | 1.000 | 3528.00 - var_binom1:groupsb | 1.69 | [0.18, 14.80] | 69.25% | 1.000 | 2699.00 + Parameter | Median | 95% CI | pd | Rhat | ESS + ------------------------------------------------------------------- + (Intercept) | 0.78 | [0.28, 2.11] | 68.62% | 0.999 | 3459 + var_binom1 | 0.53 | [0.12, 1.90] | 83.20% | 1.000 | 2820 + groupsb | 0.80 | [0.26, 2.38] | 64.75% | 1.000 | 3332 + var_cont | 0.94 | [0.87, 1.00] | 96.65% | 1.000 | 3528 + var_binom1:groupsb | 1.69 | [0.18, 14.80] | 69.25% | 1.000 | 2699 Message Uncertainty intervals (equal-tailed) computed using a MCMC distribution diff --git a/tests/testthat/_snaps/printing-stan.md b/tests/testthat/_snaps/printing-stan.md index 077a20ed6..d2ec8563a 100644 --- a/tests/testthat/_snaps/printing-stan.md +++ b/tests/testthat/_snaps/printing-stan.md @@ -5,17 +5,17 @@ Output # Fixed Effects - Parameter | Mean | 95% CI | pd | Rhat | ESS - --------------------------------------------------------------- - (Intercept) | 39.68 | [36.12, 43.27] | 100% | 1.000 | 5242.00 - wt | -3.21 | [-4.79, -1.65] | 99.95% | 1.000 | 2071.00 - cyl | -1.50 | [-2.36, -0.64] | 99.95% | 1.000 | 1951.00 + Parameter | Mean | 95% CI | pd | Rhat | ESS + ------------------------------------------------------------ + (Intercept) | 39.68 | [36.12, 43.27] | 100% | 1.000 | 5242 + wt | -3.21 | [-4.79, -1.65] | 99.95% | 1.000 | 2071 + cyl | -1.50 | [-2.36, -0.64] | 99.95% | 1.000 | 1951 # Sigma - Parameter | Mean | 95% CI | pd | Rhat | ESS - -------------------------------------------------------- - sigma | 2.67 | [2.06, 3.51] | 100% | 1.000 | 2390.00 + Parameter | Mean | 95% CI | pd | Rhat | ESS + ----------------------------------------------------- + sigma | 2.67 | [2.06, 3.51] | 100% | 1.000 | 2390 Message Uncertainty intervals (equal-tailed) computed using a MCMC distribution @@ -28,25 +28,25 @@ Output # Fixed Effects - Parameter | Mean | 95% CI | pd | Rhat | ESS - ----------------------------------------------------------- - (Intercept) | 33.55 | [24.17, 40.87] | 100% | 1.091 | 24.00 - wt | -4.49 | [-6.95, -1.68] | 100% | 1.192 | 10.00 + Parameter | Mean | 95% CI | pd | Rhat | ESS + --------------------------------------------------------- + (Intercept) | 33.55 | [24.17, 40.87] | 100% | 1.091 | 24 + wt | -4.49 | [-6.95, -1.68] | 100% | 1.192 | 10 # Sigma - Parameter | Mean | 95% CI | pd | Rhat | ESS - ------------------------------------------------------- - sigma | 2.56 | [1.95, 3.48] | 100% | 1.015 | 454.00 + Parameter | Mean | 95% CI | pd | Rhat | ESS + ---------------------------------------------------- + sigma | 2.56 | [1.95, 3.48] | 100% | 1.015 | 454 # Random Effects Variances - Parameter | Mean | 95% CI | pd | Rhat | ESS - --------------------------------------------------------------------------- - SD (Intercept: cyl) | 3.00 | [ 0.39, 9.19] | 100% | 1.080 | 32.00 - SD (Intercept: gear) | 3.88 | [ 0.21, 10.30] | 100% | 1.010 | 424.00 - SD (wt: gear) | 1.96 | [ 0.06, 5.06] | 100% | 1.385 | 9.00 - Cor (Intercept~wt: gear) | -0.25 | [-0.99, 0.83] | 62.48% | 1.106 | 36.00 + Parameter | Mean | 95% CI | pd | Rhat | ESS + ------------------------------------------------------------------------ + SD (Intercept: cyl) | 3.00 | [ 0.39, 9.19] | 100% | 1.080 | 32 + SD (Intercept: gear) | 3.88 | [ 0.21, 10.30] | 100% | 1.010 | 424 + SD (wt: gear) | 1.96 | [ 0.06, 5.06] | 100% | 1.385 | 9 + Cor (Intercept~wt: gear) | -0.25 | [-0.99, 0.83] | 62.48% | 1.106 | 36 Message Uncertainty intervals (equal-tailed) computed using a MCMC distribution @@ -59,24 +59,24 @@ Output # Fixed Effects - Parameter | Mean | 95% CI | pd | Rhat | ESS - ---------------------------------------------------------------- - (Intercept) | 251.32 | [237.00, 265.98] | 100% | 1.001 | 1621.00 - Days | 10.44 | [ 6.84, 13.91] | 100% | 1.004 | 1161.00 + Parameter | Mean | 95% CI | pd | Rhat | ESS + ------------------------------------------------------------- + (Intercept) | 251.32 | [237.00, 265.98] | 100% | 1.001 | 1621 + Days | 10.44 | [ 6.84, 13.91] | 100% | 1.004 | 1161 # Sigma - Parameter | Mean | 95% CI | pd | Rhat | ESS - ----------------------------------------------------------- - sigma | 25.94 | [23.05, 29.38] | 100% | 1.000 | 3672.00 + Parameter | Mean | 95% CI | pd | Rhat | ESS + -------------------------------------------------------- + sigma | 25.94 | [23.05, 29.38] | 100% | 1.000 | 3672 # Random Effects Variances - Parameter | Mean | 95% CI | pd | Rhat | ESS - --------------------------------------------------------------------------------- - SD (Intercept: Subject) | 26.63 | [15.46, 42.36] | 100% | 1.002 | 1823.00 - SD (Days: Subject) | 6.58 | [ 4.12, 10.16] | 100% | 1.000 | 1228.00 - Cor (Intercept~Days: Subject) | 0.09 | [-0.47, 0.67] | 60.42% | 1.003 | 899.00 + Parameter | Mean | 95% CI | pd | Rhat | ESS + ------------------------------------------------------------------------------ + SD (Intercept: Subject) | 26.63 | [15.46, 42.36] | 100% | 1.002 | 1823 + SD (Days: Subject) | 6.58 | [ 4.12, 10.16] | 100% | 1.000 | 1228 + Cor (Intercept~Days: Subject) | 0.09 | [-0.47, 0.67] | 60.42% | 1.003 | 899 Message Uncertainty intervals (equal-tailed) computed using a MCMC distribution @@ -89,24 +89,24 @@ Output # Fixed Effects - Parameter | Mean | 95% CI | pd | Rhat | ESS - ---------------------------------------------------------------- - (Intercept) | 250.84 | [228.76, 272.54] | 100% | 1.003 | 786.00 - Days | 10.37 | [ 8.77, 11.96] | 100% | 0.999 | 6026.00 + Parameter | Mean | 95% CI | pd | Rhat | ESS + ------------------------------------------------------------- + (Intercept) | 250.84 | [228.76, 272.54] | 100% | 1.003 | 786 + Days | 10.37 | [ 8.77, 11.96] | 100% | 0.999 | 6026 # Sigma - Parameter | Mean | 95% CI | pd | Rhat | ESS - ----------------------------------------------------------- - sigma | 30.03 | [26.27, 34.03] | 100% | 0.999 | 2102.00 + Parameter | Mean | 95% CI | pd | Rhat | ESS + -------------------------------------------------------- + sigma | 30.03 | [26.27, 34.03] | 100% | 0.999 | 2102 # Random Effects Variances - Parameter | Mean | 95% CI | pd | Rhat | ESS - ---------------------------------------------------------------------------- - SD (Intercept: grp) | 8.22 | [ 0.44, 25.69] | 100% | 1.000 | 1604.00 - SD (Intercept: grp:subgrp) | 7.41 | [ 0.44, 16.87] | 100% | 1.003 | 770.00 - SD (Intercept: Subject) | 38.51 | [26.89, 55.98] | 100% | 1.003 | 1254.00 + Parameter | Mean | 95% CI | pd | Rhat | ESS + ------------------------------------------------------------------------- + SD (Intercept: grp) | 8.22 | [ 0.44, 25.69] | 100% | 1.000 | 1604 + SD (Intercept: grp:subgrp) | 7.41 | [ 0.44, 16.87] | 100% | 1.003 | 770 + SD (Intercept: Subject) | 38.51 | [26.89, 55.98] | 100% | 1.003 | 1254 Message Uncertainty intervals (equal-tailed) computed using a MCMC distribution @@ -119,22 +119,22 @@ Output # Fixed Effects - Parameter | Mean | 95% CI | pd | Rhat | ESS - ------------------------------------------------------------ - (Intercept) | 2.57 | [0.70, 4.84] | 99.42% | 1.012 | 292.00 - Petal.Width | 1.05 | [0.73, 1.37] | 100% | 1.002 | 2150.00 + Parameter | Mean | 95% CI | pd | Rhat | ESS + --------------------------------------------------------- + (Intercept) | 2.57 | [0.70, 4.84] | 99.42% | 1.012 | 292 + Petal.Width | 1.05 | [0.73, 1.37] | 100% | 1.002 | 2150 # Sigma - Parameter | Mean | 95% CI | pd | Rhat | ESS - -------------------------------------------------------- - sigma | 0.38 | [0.34, 0.43] | 100% | 1.001 | 2642.00 + Parameter | Mean | 95% CI | pd | Rhat | ESS + ----------------------------------------------------- + sigma | 0.38 | [0.34, 0.43] | 100% | 1.001 | 2642 # Random Effects Variances - Parameter | Mean | 95% CI | pd | Rhat | ESS - --------------------------------------------------------------------- - SD (Intercept: Species) | 1.68 | [0.64, 3.64] | 100% | 1.003 | 796.00 + Parameter | Mean | 95% CI | pd | Rhat | ESS + ------------------------------------------------------------------ + SD (Intercept: Species) | 1.68 | [0.64, 3.64] | 100% | 1.003 | 796 Message Uncertainty intervals (equal-tailed) computed using a MCMC distribution @@ -147,25 +147,25 @@ Output # Fixed Effects - Parameter | Mean | 95% CI | pd | Rhat | ESS - -------------------------------------------------------------- - (Intercept) | 33.06 | [24.70, 40.47] | 100% | 1.006 | 744.00 - wt | -4.39 | [-6.94, -1.76] | 99.72% | 1.025 | 83.00 + Parameter | Mean | 95% CI | pd | Rhat | ESS + ----------------------------------------------------------- + (Intercept) | 33.06 | [24.70, 40.47] | 100% | 1.006 | 744 + wt | -4.39 | [-6.94, -1.76] | 99.72% | 1.025 | 83 # Sigma - Parameter | Mean | 95% CI | pd | Rhat | ESS - ------------------------------------------------------- - sigma | 2.59 | [1.96, 3.48] | 100% | 1.010 | 608.00 + Parameter | Mean | 95% CI | pd | Rhat | ESS + ---------------------------------------------------- + sigma | 2.59 | [1.96, 3.48] | 100% | 1.010 | 608 # Random Effects Variances - Parameter | Mean | 95% CI | pd | Rhat | ESS - --------------------------------------------------------------------------- - SD (Intercept: cyl) | 3.19 | [ 0.49, 9.00] | 100% | 1.001 | 651.00 - SD (Intercept: gear) | 3.76 | [ 0.14, 10.13] | 100% | 1.015 | 643.00 - SD (wt: gear) | 1.47 | [ 0.06, 3.96] | 100% | 1.039 | 94.00 - Cor (Intercept~wt: gear) | -0.38 | [-0.99, 0.82] | 76.85% | 1.003 | 854.00 + Parameter | Mean | 95% CI | pd | Rhat | ESS + ------------------------------------------------------------------------ + SD (Intercept: cyl) | 3.19 | [ 0.49, 9.00] | 100% | 1.001 | 651 + SD (Intercept: gear) | 3.76 | [ 0.14, 10.13] | 100% | 1.015 | 643 + SD (wt: gear) | 1.47 | [ 0.06, 3.96] | 100% | 1.039 | 94 + Cor (Intercept~wt: gear) | -0.38 | [-0.99, 0.82] | 76.85% | 1.003 | 854 Message Uncertainty intervals (equal-tailed) computed using a MCMC distribution @@ -178,31 +178,31 @@ Output # Fixed Effects - Parameter | Mean | 95% CI | pd | Rhat | ESS - ------------------------------------------------------------- - (Intercept) | -1.07 | [-1.42, -0.73] | 100% | 1.000 | 3259.00 - persons | 0.90 | [ 0.81, 0.99] | 100% | 1.000 | 3305.00 - child | -1.17 | [-1.37, -0.99] | 100% | 1.000 | 3224.00 - camper | 0.74 | [ 0.56, 0.94] | 100% | 1.000 | 4166.00 + Parameter | Mean | 95% CI | pd | Rhat | ESS + ---------------------------------------------------------- + (Intercept) | -1.07 | [-1.42, -0.73] | 100% | 1.000 | 3259 + persons | 0.90 | [ 0.81, 0.99] | 100% | 1.000 | 3305 + child | -1.17 | [-1.37, -0.99] | 100% | 1.000 | 3224 + camper | 0.74 | [ 0.56, 0.94] | 100% | 1.000 | 4166 # Zero-Inflation - Parameter | Mean | 95% CI | pd | Rhat | ESS - -------------------------------------------------------------- - (Intercept) | -0.58 | [-1.27, 0.08] | 95.97% | 1.000 | 4494.00 - child | 1.24 | [ 0.71, 1.82] | 100% | 1.000 | 4195.00 - camper | -0.62 | [-1.38, 0.11] | 94.73% | 1.000 | 4427.00 + Parameter | Mean | 95% CI | pd | Rhat | ESS + ----------------------------------------------------------- + (Intercept) | -0.58 | [-1.27, 0.08] | 95.97% | 1.000 | 4494 + child | 1.24 | [ 0.71, 1.82] | 100% | 1.000 | 4195 + camper | -0.62 | [-1.38, 0.11] | 94.73% | 1.000 | 4427 --- Code mp9 Output - Parameter | Mean | 95% CI | pd | Rhat | ESS - ----------------------------------------------------------------- - Intercept[1] | -38.42 | [-67.76, -19.66] | 100% | 1.002 | 992.00 - Intercept[2] | -33.26 | [-59.09, -16.53] | 100% | 1.001 | 1039.00 - mpg | -1.80 | [ -3.20, -0.90] | 100% | 1.002 | 1021.00 + Parameter | Mean | 95% CI | pd | Rhat | ESS + -------------------------------------------------------------- + Intercept[1] | -38.42 | [-67.76, -19.66] | 100% | 1.002 | 992 + Intercept[2] | -33.26 | [-59.09, -16.53] | 100% | 1.001 | 1039 + mpg | -1.80 | [ -3.20, -0.90] | 100% | 1.002 | 1021 Message Uncertainty intervals (equal-tailed) computed using a MCMC distribution @@ -215,17 +215,17 @@ Output # Fixed Effects - Parameter | Median | 95% CI | pd | Rhat | ESS - ---------------------------------------------------------------- - (Intercept) | 39.68 | [36.12, 43.27] | 100% | 1.000 | 5242.00 - wt | -3.20 | [-4.79, -1.65] | 99.95% | 1.000 | 2071.00 - cyl | -1.49 | [-2.36, -0.64] | 99.95% | 1.000 | 1951.00 + Parameter | Median | 95% CI | pd | Rhat | ESS + ------------------------------------------------------------- + (Intercept) | 39.68 | [36.12, 43.27] | 100% | 1.000 | 5242 + wt | -3.20 | [-4.79, -1.65] | 99.95% | 1.000 | 2071 + cyl | -1.49 | [-2.36, -0.64] | 99.95% | 1.000 | 1951 # Sigma - Parameter | Median | 95% CI | pd | Rhat | ESS - ---------------------------------------------------------- - sigma | 2.63 | [2.06, 3.51] | 100% | 1.000 | 2390.00 + Parameter | Median | 95% CI | pd | Rhat | ESS + ------------------------------------------------------- + sigma | 2.63 | [2.06, 3.51] | 100% | 1.000 | 2390 Message Uncertainty intervals (equal-tailed) computed using a MCMC distribution @@ -238,17 +238,17 @@ Output # Fixed Effects - Parameter | Median | 95% CI | pd | Rhat | ESS - ---------------------------------------------------------------- - (Intercept) | 39.68 | [36.27, 43.34] | 100% | 1.000 | 5242.00 - wt | -3.20 | [-4.70, -1.57] | 99.95% | 1.000 | 2071.00 - cyl | -1.49 | [-2.38, -0.68] | 99.95% | 1.000 | 1951.00 + Parameter | Median | 95% CI | pd | Rhat | ESS + ------------------------------------------------------------- + (Intercept) | 39.68 | [36.27, 43.34] | 100% | 1.000 | 5242 + wt | -3.20 | [-4.70, -1.57] | 99.95% | 1.000 | 2071 + cyl | -1.49 | [-2.38, -0.68] | 99.95% | 1.000 | 1951 # Sigma - Parameter | Median | 95% CI | pd | Rhat | ESS - ---------------------------------------------------------- - sigma | 2.63 | [1.99, 3.39] | 100% | 1.000 | 2390.00 + Parameter | Median | 95% CI | pd | Rhat | ESS + ------------------------------------------------------- + sigma | 2.63 | [1.99, 3.39] | 100% | 1.000 | 2390 Message Uncertainty intervals (highest-density) computed using a MCMC diff --git a/tests/testthat/_snaps/wrs2.md b/tests/testthat/_snaps/wrs2.md index 6fb102ebc..c57bd2a96 100644 --- a/tests/testthat/_snaps/wrs2.md +++ b/tests/testthat/_snaps/wrs2.md @@ -5,7 +5,7 @@ Output Group1 | Group2 | Psihat | 95% CI | p ------------------------------------------------- - placebo | low | -1.00 | [-5.32, 3.32] | 0.435 - placebo | high | -3.00 | [-7.32, 1.32] | 0.181 - low | high | -2.00 | [-6.32, 2.32] | 0.317 + placebo | low | -1 | [-5.32, 3.32] | 0.435 + placebo | high | -3 | [-7.32, 1.32] | 0.181 + low | high | -2 | [-6.32, 2.32] | 0.317 diff --git a/tests/testthat/test-marginaleffects.R b/tests/testthat/test-marginaleffects.R index 45c6f38b5..750204bea 100644 --- a/tests/testthat/test-marginaleffects.R +++ b/tests/testthat/test-marginaleffects.R @@ -165,8 +165,18 @@ test_that("predictions, bmrs with special response formula", { expect_identical(dim(out), c(1L, 10L)) }) - -## TODO: run check manually every now and then +## TODO: check this test locally + +# Following test may fail on CI, probably due to scoping issues? +# ── Error (test-marginaleffects.R:179:3): predictions, using bayestestR #1063 ─── +# Error in ``[.data.frame`(data, random_factors)`: undefined columns selected +# Backtrace: +# ▆ +# 1. ├─insight::get_datagrid(m, by = "Days", include_random = TRUE) at test-marginaleffects.R:179:3 +# 2. └─insight:::get_datagrid.default(m, by = "Days", include_random = TRUE) +# 3. ├─base::lapply(data[random_factors], as.factor) +# 4. ├─data[random_factors] +# 5. └─base::`[.data.frame`(data, random_factors) test_that("predictions, using bayestestR #1063", { skip_on_ci() @@ -180,13 +190,13 @@ test_that("predictions, using bayestestR #1063", { skip_if(is.null(m)) d <- insight::get_datagrid(m, by = "Days", include_random = TRUE) - x <- marginaleffects::avg_predictions(m, newdata = d, by = "Days") + x <- marginaleffects::avg_predictions(m, newdata = d, by = "Days", allow_new_levels = TRUE) out <- model_parameters(x) expect_named( out, c( "Median", "CI", "CI_low", "CI_high", "pd", "ROPE_CI", "ROPE_low", - "ROPE_high", "ROPE_Percentage", "Days", "subgrp", "grp", "Subject" + "ROPE_high", "ROPE_Percentage", "Days" ) ) })