diff --git a/DESCRIPTION b/DESCRIPTION index c8a9b7ab6..33793897c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: parameters Title: Processing of Model Parameters -Version: 0.30.0.10 +Version: 0.30.0.11 Authors@R: c(person(given = "Daniel", family = "Lüdecke", @@ -241,4 +241,4 @@ Config/testthat/parallel: false Config/Needs/website: easystats/easystatstemplate Config/Needs/check: stan-dev/cmdstanr Config/rcmdcheck/ignore-inconsequential-notes: true -Config/roxygen2/version: 8.1.0 +Config/roxygen2/version: 8.1.1 diff --git a/NAMESPACE b/NAMESPACE index 643eba238..bb8f68eb7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -59,6 +59,7 @@ S3method(ci,list) S3method(ci,lm) S3method(ci,lm_robust) S3method(ci,lme) +S3method(ci,lmerMod) S3method(ci,lmodel2) S3method(ci,logistf) S3method(ci,logitmfx) @@ -289,6 +290,7 @@ S3method(model_parameters,lcmm) S3method(model_parameters,list) S3method(model_parameters,lm_robust) S3method(model_parameters,lme) +S3method(model_parameters,lmerMod) S3method(model_parameters,lmodel2) S3method(model_parameters,logistf) S3method(model_parameters,logitmfx) @@ -501,6 +503,7 @@ S3method(p_value,list) S3method(p_value,lm) S3method(p_value,lm_robust) S3method(p_value,lme) +S3method(p_value,lmerMod) S3method(p_value,lmodel2) S3method(p_value,logistf) S3method(p_value,logitmfx) @@ -852,6 +855,7 @@ S3method(standard_error,lcmm) S3method(standard_error,list) S3method(standard_error,lm_robust) S3method(standard_error,lme) +S3method(standard_error,lmerMod) S3method(standard_error,lmodel2) S3method(standard_error,logistf) S3method(standard_error,logitmfx) diff --git a/NEWS.md b/NEWS.md index 5f719ab10..1d1e70b90 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,14 @@ # parameters (devel) +## Breaking Changes + +* `compare_parameters()`'s `ci_method` now defaults to `NULL`, so the value is + potentially set by the models' unique methods. + +* `model_parameters()`, `ci()`, `standard_error()`, and `p_value()` now default + to the Satterthwaite approximation for `lmerModLmerTest` models and suggest + doing so for `lmerMod` models (#989). + ## Changes * `model_parameters()` for models from *blavaan* with `standardize` no longer diff --git a/R/1_model_parameters.R b/R/1_model_parameters.R index de4647524..9cf51270d 100644 --- a/R/1_model_parameters.R +++ b/R/1_model_parameters.R @@ -196,6 +196,9 @@ #' - Applies to *linear mixed models*. CIs computed using the #' Wald method (SE and a *t-distribution with Satterthwaite df*); p-values #' computed using the Wald method with a *t-distribution with Satterthwaite df*. +#' This is the default for `lmerModLmerTest` models when the corresponding +#' method argument (`ci_method` or `method`) is `NULL` (and +#' `bootstrap = FALSE`). #' #' `"kenward"` #' - Applies to *linear mixed models*. CIs computed using the Wald diff --git a/R/ci_generic.R b/R/ci_generic.R index cc94de6ea..20fe18509 100644 --- a/R/ci_generic.R +++ b/R/ci_generic.R @@ -41,7 +41,7 @@ } else if (method == "betwithin") { return(ci_betwithin(model, ci = ci)) } else if (method == "satterthwaite") { - return(ci_satterthwaite(model, ci = ci)) + return(ci_satterthwaite(model, ci = ci, vcov = vcov, vcov_args = vcov_args, ...)) } else if (method %in% c("kenward", "kr")) { return(ci_kenward(model, ci = ci)) } diff --git a/R/compare_parameters.R b/R/compare_parameters.R index ec8793de9..3971db4e2 100644 --- a/R/compare_parameters.R +++ b/R/compare_parameters.R @@ -69,23 +69,25 @@ #' compare_parameters(list("linear model" = m1, "logistic reg." = m2)) #' } #' @export -compare_parameters <- function(..., - ci = 0.95, - effects = "fixed", - component = "conditional", - standardize = NULL, - exponentiate = FALSE, - ci_method = "wald", - p_adjust = NULL, - select = NULL, - column_names = NULL, - pretty_names = TRUE, - coefficient_names = NULL, - keep = NULL, - drop = NULL, - include_reference = FALSE, - groups = NULL, - verbose = TRUE) { +compare_parameters <- function( + ..., + ci = 0.95, + effects = "fixed", + component = "conditional", + standardize = NULL, + exponentiate = FALSE, + ci_method = NULL, + p_adjust = NULL, + select = NULL, + column_names = NULL, + pretty_names = TRUE, + coefficient_names = NULL, + keep = NULL, + drop = NULL, + include_reference = FALSE, + groups = NULL, + verbose = TRUE +) { models <- list(...) if (length(models) == 1) { @@ -117,14 +119,23 @@ compare_parameters <- function(..., } } - supported_models <- vapply(models, function(i) { - insight::is_model_supported(i) || inherits(i, "lavaan") || inherits(i, "parameters_model") - }, TRUE) + supported_models <- vapply( + models, + function(i) { + insight::is_model_supported(i) || + inherits(i, "lavaan") || + inherits(i, "parameters_model") + }, + TRUE + ) if (!all(supported_models)) { if (verbose) { insight::format_alert( - sprintf("Following objects are not supported: %s", toString(model_names[!supported_models])), + sprintf( + "Following objects are not supported: %s", + toString(model_names[!supported_models]) + ), "Dropping unsupported models now." ) } @@ -169,7 +180,15 @@ compare_parameters <- function(..., dat <- model } else { # set default-ci_type for Bayesian models - if (insight::is_bayesian_model(model, exclude = c("bmerMod", "bayesx", "blmerMod", "bglmerMod")) && !ci_method %in% c("hdi", "quantile", "ci", "eti", "si", "bci", "bcai")) { # nolint + if ( + insight::is_bayesian_model( + model, + exclude = c("bmerMod", "bayesx", "blmerMod", "bglmerMod") + ) && + (is.null(ci_method) || + !ci_method %in% c("hdi", "quantile", "ci", "eti", "si", "bci", "bcai")) + ) { + # nolint ci_method_tmp <- "eti" } else { ci_method_tmp <- ci_method @@ -217,7 +236,10 @@ compare_parameters <- function(..., # add zi-suffix to parameter names if (any(dat$Component == "zero_inflated")) { - dat$Parameter[dat$Component == "zero_inflated"] <- paste0(dat$Parameter[dat$Component == "zero_inflated"], " (zi)") + dat$Parameter[dat$Component == "zero_inflated"] <- paste0( + dat$Parameter[dat$Component == "zero_inflated"], + " (zi)" + ) } # add suffix @@ -235,15 +257,28 @@ compare_parameters <- function(..., names(object_attributes) <- model_names # merge all data frames - all_models <- suppressWarnings(Reduce(function(x, y) { - merge(x, y, all = TRUE, sort = FALSE, by = c("Parameter", "Component", "Effects", "Group")) - }, m)) + all_models <- suppressWarnings(Reduce( + function(x, y) { + merge( + x, + y, + all = TRUE, + sort = FALSE, + by = c("Parameter", "Component", "Effects", "Group") + ) + }, + m + )) # find columns with model numbers and create new variable "params_order", # which is pasted together of all model-column indices. Take lowest index of # all model-column indices, which then indicates order of parameters/rows. model_cols <- which(startsWith(colnames(all_models), "model")) - params_order <- as.numeric(substr(gsub("NA", "", do.call(paste0, all_models[model_cols]), fixed = TRUE), 0, 1)) + params_order <- as.numeric(substr( + gsub("NA", "", do.call(paste0, all_models[model_cols]), fixed = TRUE), + 0, + 1 + )) all_models <- all_models[order(params_order), ] all_models[model_cols] <- NULL @@ -253,11 +288,20 @@ compare_parameters <- function(..., all_models$Group <- NULL } - attr(all_models, "model_names") <- gsub("\"", "", unlist(lapply(model_names, insight::safe_deparse)), fixed = TRUE) + attr(all_models, "model_names") <- gsub( + "\"", + "", + unlist(lapply(model_names, insight::safe_deparse)), + fixed = TRUE + ) attr(all_models, "output_style") <- select attr(all_models, "all_attributes") <- object_attributes attr(all_models, "parameter_groups") <- groups - class(all_models) <- c("compare_parameters", "see_compare_parameters", unique(class(all_models))) + class(all_models) <- c( + "compare_parameters", + "see_compare_parameters", + unique(class(all_models)) + ) all_models } @@ -270,11 +314,12 @@ compare_models <- compare_parameters # helper ---------------------------- - .set_pretty_names <- function(x, pretty_names) { # check if pretty names should be replaced by value labels # (if we have labelled data) - if (isTRUE(getOption("parameters_labels", FALSE)) || identical(pretty_names, "labels")) { + if ( + isTRUE(getOption("parameters_labels", FALSE)) || identical(pretty_names, "labels") + ) { attr(x, "pretty_names") <- attr(x, "pretty_labels", exact = TRUE) pretty_names <- TRUE } @@ -288,7 +333,9 @@ compare_models <- compare_parameters match_pretty_names <- match(names(att$pretty_names), x$Parameter) match_pretty_names <- match_pretty_names[!is.na(match_pretty_names)] if (length(match_pretty_names)) { - x$Parameter[match_pretty_names] <- att$pretty_names[x$Parameter[match_pretty_names]] + x$Parameter[match_pretty_names] <- att$pretty_names[x$Parameter[ + match_pretty_names + ]] } } else { match_pretty_names <- att$pretty_names[x$Parameter] @@ -296,7 +343,9 @@ compare_models <- compare_parameters match_pretty_names <- match(names(att$pretty_names), x$Parameter) match_pretty_names <- match_pretty_names[!is.na(match_pretty_names)] if (length(match_pretty_names)) { - x$Parameter[match_pretty_names] <- att$pretty_names[x$Parameter[match_pretty_names]] + x$Parameter[match_pretty_names] <- att$pretty_names[x$Parameter[ + match_pretty_names + ]] } } else { x$Parameter <- att$pretty_names[x$Parameter] diff --git a/R/extract_parameters.R b/R/extract_parameters.R index be3edd767..aa9c68ce4 100644 --- a/R/extract_parameters.R +++ b/R/extract_parameters.R @@ -522,7 +522,8 @@ ci = ci, vcov = vcov, vcov_args = vcov_args, - verbose = verbose + verbose = verbose, + method = ci_method ) fun_args <- c(fun_args, dots) ci_df <- suppressMessages(do.call("ci", fun_args)) @@ -567,7 +568,13 @@ # p value if (!is.null(vcov)) { - fun_args <- list(model, vcov = vcov, vcov_args = vcov_args, verbose = verbose) + fun_args <- list( + model, + vcov = vcov, + vcov_args = vcov_args, + verbose = verbose, + method = ci_method + ) fun_args <- c(fun_args, dots) parameters <- merge( parameters, @@ -588,7 +595,7 @@ } else { parameters <- merge( parameters, - p_value(model, dof = dof, effects = "fixed"), + p_value(model, dof = dof, method = ci_method, effects = "fixed"), by = "Parameter", sort = FALSE ) diff --git a/R/format.R b/R/format.R index b64f0f2d7..d14c2df23 100644 --- a/R/format.R +++ b/R/format.R @@ -869,7 +869,8 @@ format.parameters_sem <- function( show_re_msg <- (identical(model_class, "glmmTMB") && (!string_method %in% c("Wald z-", "Wald normal") || !ci_method %in% c("wald", "normal"))) || - ((identical(model_class, "lmerMod") || identical(model_class, "glmerMod")) && + (length(model_class) == 1L && + model_class %in% c("lmerMod", "lmerModLmerTest", "glmerMod") && !ci_method %in% c("wald", "normal", "profile", "boot")) if ( diff --git a/R/methods_cplm.R b/R/methods_cplm.R index 5e950a724..505334e35 100644 --- a/R/methods_cplm.R +++ b/R/methods_cplm.R @@ -1,9 +1,7 @@ # classes: .cpglm, .bcpglm, .zcpglm, .cpglmm - ########## .zcpglm --------------- - #' @title Parameters from Zero-Inflated Models #' @name model_parameters.zcpglm #' @@ -68,23 +66,31 @@ #' model_parameters(model) #' @return A data frame of indices related to the model's parameters. #' @export -model_parameters.zcpglm <- function(model, - ci = 0.95, - bootstrap = FALSE, - iterations = 1000, - component = "all", - standardize = NULL, - exponentiate = FALSE, - p_adjust = NULL, - include_info = getOption("parameters_info", FALSE), - keep = NULL, - drop = NULL, - verbose = TRUE, - ...) { - component <- insight::validate_argument(component, c("all", "conditional", "zi", "zero_inflated")) +model_parameters.zcpglm <- function( + model, + ci = 0.95, + bootstrap = FALSE, + iterations = 1000, + component = "all", + standardize = NULL, + exponentiate = FALSE, + p_adjust = NULL, + include_info = getOption("parameters_info", FALSE), + keep = NULL, + drop = NULL, + verbose = TRUE, + ... +) { + component <- insight::validate_argument( + component, + c("all", "conditional", "zi", "zero_inflated") + ) # fix argument, if model has no zi-part - if (!insight::model_info(model, verbose = FALSE)$is_zero_inflated && component != "conditional") { + if ( + !insight::model_info(model, verbose = FALSE)$is_zero_inflated && + component != "conditional" + ) { component <- "conditional" } @@ -200,10 +206,7 @@ p_value.cpglm <- function(model, ...) { junk <- utils::capture.output(stats <- cplm::summary(model)$coefficients) # nolint params <- insight::get_parameters(model) - .data_frame( - Parameter = params$Parameter, - p = as.vector(stats[, "Pr(>|t|)"]) - ) + .data_frame(Parameter = params$Parameter, p = as.vector(stats[, "Pr(>|t|)"])) } @@ -214,32 +217,31 @@ standard_error.cpglm <- function(model, ...) { junk <- utils::capture.output(stats <- cplm::summary(model)$coefficients) # nolint params <- insight::get_parameters(model) - .data_frame( - Parameter = params$Parameter, - SE = as.vector(stats[, "Std. Error"]) - ) + .data_frame(Parameter = params$Parameter, SE = as.vector(stats[, "Std. Error"])) } ########## .cpglmm --------------- #' @export -model_parameters.cpglmm <- function(model, - ci = 0.95, - ci_method = NULL, - ci_random = NULL, - bootstrap = FALSE, - iterations = 1000, - standardize = NULL, - effects = "all", - group_level = FALSE, - exponentiate = FALSE, - p_adjust = NULL, - include_sigma = FALSE, - keep = NULL, - drop = NULL, - verbose = TRUE, - ...) { +model_parameters.cpglmm <- function( + model, + ci = 0.95, + ci_method = NULL, + ci_random = NULL, + bootstrap = FALSE, + iterations = 1000, + standardize = NULL, + effects = "all", + group_level = FALSE, + exponentiate = FALSE, + p_adjust = NULL, + include_sigma = FALSE, + keep = NULL, + drop = NULL, + verbose = TRUE, + ... +) { # p-values, CI and se might be based on different df-methods ci_method <- .check_df_method(ci_method) effects <- insight::validate_argument(effects, c("fixed", "random", "all")) @@ -247,7 +249,9 @@ model_parameters.cpglmm <- function(model, # standardize only works for fixed effects... if (!is.null(standardize) && standardize != "refit") { if (!missing(effects) && effects != "fixed" && verbose) { - insight::format_alert("Standardizing coefficients only works for fixed effects of the mixed model.") + insight::format_alert( + "Standardizing coefficients only works for fixed effects of the mixed model." + ) } effects <- "fixed" } @@ -292,10 +296,7 @@ standard_error.cpglmm <- function(model, ...) { stats <- cplm::summary(model)$coefs params <- insight::get_parameters(model) - .data_frame( - Parameter = params$Parameter, - SE = as.vector(stats[, "Std. Error"]) - ) + .data_frame(Parameter = params$Parameter, SE = as.vector(stats[, "Std. Error"])) } @@ -305,15 +306,14 @@ standard_error.cpglmm <- function(model, ...) { if (!is.null(df_method)) { df_method <- tolower(df_method) if (df_method %in% c("satterthwaite", "kenward", "kr")) { - insight::format_alert("Satterthwaite or Kenward-Rogers approximation of degrees of freedom is only available for linear mixed models.") + insight::format_alert( + "Satterthwaite or Kenward-Rogers approximation of degrees of freedom is only available for linear mixed models." + ) df_method <- "wald" } df_method <- insight::validate_argument( df_method, - c( - "wald", "normal", "residual", "ml1", "betwithin", "profile", - "boot", "uniroot" - ) + c("wald", "normal", "residual", "ml1", "betwithin", "profile", "boot", "uniroot") ) } df_method diff --git a/R/methods_lme4.R b/R/methods_lme4.R index 354dda08d..c311968fb 100644 --- a/R/methods_lme4.R +++ b/R/methods_lme4.R @@ -1,56 +1,8 @@ -############# .merMod ----------------- +# merMod ----------------------------------------------------------------- #' @export model_parameters.merMod <- model_parameters.coxme -# helper ---------------------------------------------------------------------- - -.add_random_effects_lme4 <- function( - model, - params, - ci, - ci_method, - ci_random, - effects, - group_level, - verbose = TRUE, - ... -) { - params_random <- params_variance <- NULL - - # only proceed if random effects are requested - if (effects %in% c("random", "all")) { - # group level estimates (BLUPs) or random effects variances? - if (isTRUE(group_level)) { - params_random <- .extract_random_parameters(model, ci = ci, effects = effects) - } else { - params_variance <- .extract_random_variances( - model, - ci = ci, - effects = effects, - ci_method = ci_method, - ci_random = ci_random, - verbose = verbose - ) - } - - # merge random and fixed effects, if necessary - if (!is.null(params) && (!is.null(params_random) || !is.null(params_variance))) { - params$Level <- NA - params$Group <- "" - - if (is.null(params_random)) { - params <- params[match(colnames(params_variance), colnames(params))] - } else { - params <- params[match(colnames(params_random), colnames(params))] - } - } - } - - rbind(params, params_random, params_variance) -} - - #' @export ci.merMod <- function(x, ci = 0.95, dof = NULL, method = "wald", iterations = 500, ...) { method <- tolower(method) @@ -135,9 +87,166 @@ standard_error.merMod <- function( out } +#' @export +p_value.merMod <- p_value.cpglmm + + +# lmerMod (and lmerModLmerTest) ----------------------------------------------------------------- + +#' @export +model_parameters.lmerMod <- function( + model, + ci = 0.95, + ci_method = NULL, + ci_random = NULL, + bootstrap = FALSE, + iterations = 1000, + standardize = NULL, + effects = "all", + group_level = FALSE, + exponentiate = FALSE, + p_adjust = NULL, + vcov = NULL, + vcov_args = NULL, + wb_component = FALSE, + include_info = getOption("parameters_mixed_info", FALSE), + include_sigma = FALSE, + keep = NULL, + drop = NULL, + verbose = TRUE, + ... +) { + cl <- match.call() + cl[[1]] <- model_parameters.merMod + cl$ci_method <- .check_ci_method( + model, + method = ci_method, + effects = effects, + bootstrap = bootstrap, + verbose = verbose, + fallback = NULL # this is the default for merMod + ) + eval.parent(cl) +} + +#' @export +ci.lmerMod <- function( + x, + ci = 0.95, + dof = NULL, + method = NULL, + iterations = 500, + effects = "all", + vcov = NULL, + vcov_args = NULL, + verbose = TRUE, + ... +) { + cl <- match.call() + cl[[1]] <- ci.merMod + cl$method <- .check_ci_method( + x, + method = method, + effects = effects, + verbose = verbose, + fallback = "wald" # this is the default for merMod + ) + eval.parent(cl) +} + +#' @export +standard_error.lmerMod <- function( + model, + effects = "fixed", + method = NULL, + vcov = NULL, + vcov_args = NULL, + verbose = TRUE, + ... +) { + cl <- match.call() + cl[[1]] <- standard_error.merMod + cl$method <- .check_ci_method( + model, + method = method, + effects = effects, + verbose = verbose, + fallback = NULL # this is the default for merMod + ) + eval.parent(cl) +} + +#' @export +p_value.lmerMod <- function( + model, + dof = NULL, + method = NULL, + effects = "all", + vcov = NULL, + vcov_args = NULL, + verbose = TRUE, + ... +) { + cl <- match.call() + cl[[1]] <- p_value.merMod + cl$method <- .check_ci_method( + model, + method = method, + effects = effects, + verbose = verbose, + fallback = "wald" # this is the default for merMod + ) + eval.parent(cl) +} + # helpers -------------- +.add_random_effects_lme4 <- function( + model, + params, + ci, + ci_method, + ci_random, + effects, + group_level, + verbose = TRUE, + ... +) { + params_random <- params_variance <- NULL + + # only proceed if random effects are requested + if (effects %in% c("random", "all")) { + # group level estimates (BLUPs) or random effects variances? + if (isTRUE(group_level)) { + params_random <- .extract_random_parameters(model, ci = ci, effects = effects) + } else { + params_variance <- .extract_random_variances( + model, + ci = ci, + effects = effects, + ci_method = ci_method, + ci_random = ci_random, + verbose = verbose + ) + } + + # merge random and fixed effects, if necessary + if (!is.null(params) && (!is.null(params_random) || !is.null(params_variance))) { + params$Level <- NA + params$Group <- "" + + if (is.null(params_random)) { + params <- params[match(colnames(params_variance), colnames(params))] + } else { + params <- params[match(colnames(params_random), colnames(params))] + } + } + } + + rbind(params, params_random, params_variance) +} + .standard_errors_random <- function(model) { insight::check_if_installed("lme4") @@ -172,6 +281,34 @@ se_mixed_default <- function(model) { .data_frame(Parameter = params, SE = .get_se_from_summary(model)) } +.check_ci_method <- function( + model, + method, + effects = "all", + bootstrap = FALSE, + verbose = TRUE, + fallback = NULL +) { + if (!is.null(method) || isTRUE(bootstrap) || identical(effects, "random")) { + return(method) + } -#' @export -p_value.merMod <- p_value.cpglmm + mod_class <- class(model) + if (setequal(mod_class, "lmerModLmerTest")) { + return("satterthwaite") + } + + if ( + isTRUE(verbose) && + isTRUE(getOption(".suggest_satterthwaite_for_lmerMod", default = TRUE)) && + setequal(mod_class, "lmerMod") + ) { + insight::format_alert( + 'Consider setting `ci_method = "satterthwaite"` for better coverage and type-1 error control.', + "This message will only show once per session." + ) + options(.suggest_satterthwaite_for_lmerMod = FALSE) + } + + return(fallback) +} diff --git a/man/ci.default.Rd b/man/ci.default.Rd index 4c4b64b90..6a5f24642 100644 --- a/man/ci.default.Rd +++ b/man/ci.default.Rd @@ -141,6 +141,9 @@ CIs and p-values instead. \item Applies to \emph{linear mixed models}. CIs computed using the Wald method (SE and a \emph{t-distribution with Satterthwaite df}); p-values computed using the Wald method with a \emph{t-distribution with Satterthwaite df}. +This is the default for \code{lmerModLmerTest} models when the corresponding +method argument (\code{ci_method} or \code{method}) is \code{NULL} (and +\code{bootstrap = FALSE}). } \code{"kenward"} diff --git a/man/compare_parameters.Rd b/man/compare_parameters.Rd index 11534dd13..e7c815eb8 100644 --- a/man/compare_parameters.Rd +++ b/man/compare_parameters.Rd @@ -12,7 +12,7 @@ compare_parameters( component = "conditional", standardize = NULL, exponentiate = FALSE, - ci_method = "wald", + ci_method = NULL, p_adjust = NULL, select = NULL, column_names = NULL, @@ -32,7 +32,7 @@ compare_models( component = "conditional", standardize = NULL, exponentiate = FALSE, - ci_method = "wald", + ci_method = NULL, p_adjust = NULL, select = NULL, column_names = NULL, diff --git a/man/model_parameters.Rd b/man/model_parameters.Rd index 504a4fb8d..2b85090e4 100644 --- a/man/model_parameters.Rd +++ b/man/model_parameters.Rd @@ -221,6 +221,9 @@ CIs and p-values instead. \item Applies to \emph{linear mixed models}. CIs computed using the Wald method (SE and a \emph{t-distribution with Satterthwaite df}); p-values computed using the Wald method with a \emph{t-distribution with Satterthwaite df}. +This is the default for \code{lmerModLmerTest} models when the corresponding +method argument (\code{ci_method} or \code{method}) is \code{NULL} (and +\code{bootstrap = FALSE}). } \code{"kenward"} diff --git a/man/model_parameters.brmsfit.Rd b/man/model_parameters.brmsfit.Rd index 04c9c4445..0830d4bda 100644 --- a/man/model_parameters.brmsfit.Rd +++ b/man/model_parameters.brmsfit.Rd @@ -308,6 +308,9 @@ CIs and p-values instead. \item Applies to \emph{linear mixed models}. CIs computed using the Wald method (SE and a \emph{t-distribution with Satterthwaite df}); p-values computed using the Wald method with a \emph{t-distribution with Satterthwaite df}. +This is the default for \code{lmerModLmerTest} models when the corresponding +method argument (\code{ci_method} or \code{method}) is \code{NULL} (and +\code{bootstrap = FALSE}). } \code{"kenward"} diff --git a/man/model_parameters.default.Rd b/man/model_parameters.default.Rd index 6151d76fb..fe075ffbb 100644 --- a/man/model_parameters.default.Rd +++ b/man/model_parameters.default.Rd @@ -234,6 +234,9 @@ CIs and p-values instead. \item Applies to \emph{linear mixed models}. CIs computed using the Wald method (SE and a \emph{t-distribution with Satterthwaite df}); p-values computed using the Wald method with a \emph{t-distribution with Satterthwaite df}. +This is the default for \code{lmerModLmerTest} models when the corresponding +method argument (\code{ci_method} or \code{method}) is \code{NULL} (and +\code{bootstrap = FALSE}). } \code{"kenward"} diff --git a/man/model_parameters.glmmTMB.Rd b/man/model_parameters.glmmTMB.Rd index ec60d4f7d..f9ad0810a 100644 --- a/man/model_parameters.glmmTMB.Rd +++ b/man/model_parameters.glmmTMB.Rd @@ -410,6 +410,9 @@ CIs and p-values instead. \item Applies to \emph{linear mixed models}. CIs computed using the Wald method (SE and a \emph{t-distribution with Satterthwaite df}); p-values computed using the Wald method with a \emph{t-distribution with Satterthwaite df}. +This is the default for \code{lmerModLmerTest} models when the corresponding +method argument (\code{ci_method} or \code{method}) is \code{NULL} (and +\code{bootstrap = FALSE}). } \code{"kenward"} diff --git a/man/p_value.Rd b/man/p_value.Rd index e85c7e623..987c1791d 100644 --- a/man/p_value.Rd +++ b/man/p_value.Rd @@ -159,6 +159,9 @@ CIs and p-values instead. \item Applies to \emph{linear mixed models}. CIs computed using the Wald method (SE and a \emph{t-distribution with Satterthwaite df}); p-values computed using the Wald method with a \emph{t-distribution with Satterthwaite df}. +This is the default for \code{lmerModLmerTest} models when the corresponding +method argument (\code{ci_method} or \code{method}) is \code{NULL} (and +\code{bootstrap = FALSE}). } \code{"kenward"} diff --git a/tests/testthat/_snaps/compare_parameters.md b/tests/testthat/_snaps/compare_parameters.md index 6c357c58d..1a58fa541 100644 --- a/tests/testthat/_snaps/compare_parameters.md +++ b/tests/testthat/_snaps/compare_parameters.md @@ -20,7 +20,7 @@ Parameter | m0 | m1 | m2 -------------------------------------------------------------------------------- (Intercept) | 0.91 ( 0.75, 1.07) | 0.68 (-0.54, 1.91) | 1.41 ( 1.06, 1.75) - child | -1.23 (-1.39, -1.08) | -1.67 (-1.84, -1.51) | -0.53 (-0.77, -0.29) + child | -1.23 (-1.40, -1.08) | -1.67 (-1.84, -1.51) | -0.53 (-0.77, -0.29) camper [1] | 1.05 ( 0.88, 1.23) | 0.94 ( 0.77, 1.12) | 0.58 ( 0.39, 0.78) zg | | | 0.13 ( 0.05, 0.21) diff --git a/tests/testthat/_snaps/glmer.md b/tests/testthat/_snaps/glmer.md index 91d43a084..6f1fb2c74 100644 --- a/tests/testthat/_snaps/glmer.md +++ b/tests/testthat/_snaps/glmer.md @@ -94,3 +94,28 @@ random effect variances computed using a Wald z-distribution approximation. +--- + + Code + print(out, table_width = Inf) + Output + # Fixed Effects + + Parameter | Coefficient | SE | 95% CI | t(174) | p + --------------------------------------------------------------------- + (Intercept) | 251.41 | 6.48 | [238.61, 264.20] | 38.77 | < .001 + Days | 10.47 | 1.49 | [ 7.52, 13.42] | 7.01 | < .001 + + # Random Effects + + Parameter | Coefficient | SE | 95% CI + ------------------------------------------------------------------- + SD (Intercept: Subject) | 24.74 | 5.84 | [15.58, 39.28] + SD (Days: Subject) | 5.92 | 1.25 | [ 3.92, 8.95] + Cor (Intercept~Days: Subject) | 0.07 | 0.32 | [-0.51, 0.60] + SD (Residual) | 25.59 | 1.51 | [22.80, 28.72] + Message + + Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed + using a Wald t-distribution approximation. + diff --git a/tests/testthat/test-ci.R b/tests/testthat/test-ci.R index 8203f8be5..2743277c3 100644 --- a/tests/testthat/test-ci.R +++ b/tests/testthat/test-ci.R @@ -3,13 +3,17 @@ test_that("ci", { model <- lm(mpg ~ wt, data = mtcars) expect_equal(suppressMessages(ci(model))[1, 3], 33.4505, tolerance = 0.01) - expect_equal(suppressMessages(ci(model, ci = c(0.7, 0.8)))[1, 3], 35.30486, tolerance = 0.01) + expect_equal( + suppressMessages(ci(model, ci = c(0.7, 0.8)))[1, 3], + 35.30486, + tolerance = 0.01 + ) model <- glm(vs ~ wt, family = "binomial", data = mtcars) expect_equal(suppressMessages(ci(model))[1, 3], 1.934013, tolerance = 0.01) model <- lme4::lmer(wt ~ cyl + (1 | gear), data = mtcars) - expect_equal(suppressMessages(ci(model, method = "normal"))[1, 3], -0.335063, tolerance = 0.01) + expect_equal(suppressMessages(ci(model))[1, 3], -0.3795646, tolerance = 0.01) model <- lme4::lmer(wt ~ cyl + (1 | gear), data = mtcars) expect_equal(ci(model)[1, 3], -0.3795646, tolerance = 0.01) @@ -42,7 +46,8 @@ test_that("vs. sandwich & lmtest", { expect_equal(unknown[["CI_low"]], known[, "2.5 %"], ignore_attr = TRUE) expect_equal(unknown[["CI_high"]], known[, "97.5 %"], ignore_attr = TRUE) - suppressMessages( - expect_message(ci(model, vcov = sandwich::vcovHC), regexp = "vcov.*are not available with.*profile") - ) + suppressMessages(expect_message( + ci(model, vcov = sandwich::vcovHC), + regexp = "vcov.*are not available with.*profile" + )) }) diff --git a/tests/testthat/test-compare_parameters.R b/tests/testthat/test-compare_parameters.R index 5ebe45e90..af951a9bd 100644 --- a/tests/testthat/test-compare_parameters.R +++ b/tests/testthat/test-compare_parameters.R @@ -1,268 +1,337 @@ skip_if_not_installed("withr") # make sure we have the correct interaction mark for tests -withr::with_options( - list(parameters_interaction = "*", easystats_table_width = Inf), - { - data(iris) - m1 <- lm(Sepal.Length ~ Species, data = iris) - m2 <- lm(Sepal.Length ~ Species * Petal.Length, data = iris) - counts <- c(18, 17, 15, 20, 10, 20, 25, 13, 12) - outcome <- gl(3, 1, 9) - treatment <- gl(3, 3) - m3 <- glm(counts ~ outcome + treatment, family = poisson()) - - x <- compare_parameters(m1, m2, m3) - test_that("compare_parameters, default", { - expect_identical( - colnames(x), - c( - "Parameter", "Component", "Effects", "Coefficient.m1", "SE.m1", "CI.m1", - "CI_low.m1", "CI_high.m1", "t.m1", "df_error.m1", "p.m1", "Coefficient.m2", - "SE.m2", "CI.m2", "CI_low.m2", "CI_high.m2", "t.m2", "df_error.m2", - "p.m2", "Log-Mean.m3", "SE.m3", "CI.m3", "CI_low.m3", "CI_high.m3", - "z.m3", "df_error.m3", "p.m3" - ) - ) - out <- capture.output(x) - expect_length(out, 14) - out <- format(x, select = "ci") - expect_identical(colnames(out), c("Parameter", "m1", "m2", "m3")) - expect_identical( - out$Parameter, - c( - "(Intercept)", "Species [versicolor]", "Species [virginica]", - "Petal Length", "Species [versicolor] * Petal Length", - "Species [virginica] * Petal Length", "outcome [2]", "outcome [3]", - "treatment [2]", "treatment [3]", NA, "Observations" - ) - ) - }) - - - x <- compare_parameters(m1, m2, m3, select = "se_p2") - test_that("compare_parameters, se_p2", { - expect_identical( - colnames(x), - c( - "Parameter", "Component", "Effects", "Coefficient.m1", "SE.m1", "CI.m1", - "CI_low.m1", "CI_high.m1", "t.m1", "df_error.m1", "p.m1", "Coefficient.m2", - "SE.m2", "CI.m2", "CI_low.m2", "CI_high.m2", "t.m2", "df_error.m2", - "p.m2", "Log-Mean.m3", "SE.m3", "CI.m3", "CI_low.m3", "CI_high.m3", - "z.m3", "df_error.m3", "p.m3" - ) +withr::with_options(list(parameters_interaction = "*", easystats_table_width = Inf), { + data(iris) + m1 <- lm(Sepal.Length ~ Species, data = iris) + m2 <- lm(Sepal.Length ~ Species * Petal.Length, data = iris) + counts <- c(18, 17, 15, 20, 10, 20, 25, 13, 12) + outcome <- gl(3, 1, 9) + treatment <- gl(3, 3) + m3 <- glm(counts ~ outcome + treatment, family = poisson()) + + x <- compare_parameters(m1, m2, m3) + test_that("compare_parameters, default", { + expect_identical( + colnames(x), + c( + "Parameter", + "Component", + "Effects", + "Coefficient.m1", + "SE.m1", + "CI.m1", + "CI_low.m1", + "CI_high.m1", + "t.m1", + "df_error.m1", + "p.m1", + "Coefficient.m2", + "SE.m2", + "CI.m2", + "CI_low.m2", + "CI_high.m2", + "t.m2", + "df_error.m2", + "p.m2", + "Log-Mean.m3", + "SE.m3", + "CI.m3", + "CI_low.m3", + "CI_high.m3", + "z.m3", + "df_error.m3", + "p.m3" ) - out <- capture.output(x) - expect_length(out, 14) - out <- format(x, select = "se_p2") - expect_identical( - colnames(out), - c( - "Parameter", "Coefficient (SE) (m1)", "p (m1)", "Coefficient (SE) (m2)", - "p (m2)", "Log-Mean (SE) (m3)", "p (m3)" - ) + ) + out <- capture.output(x) + expect_length(out, 14) + out <- format(x, select = "ci") + expect_identical(colnames(out), c("Parameter", "m1", "m2", "m3")) + expect_identical( + out$Parameter, + c( + "(Intercept)", + "Species [versicolor]", + "Species [virginica]", + "Petal Length", + "Species [versicolor] * Petal Length", + "Species [virginica] * Petal Length", + "outcome [2]", + "outcome [3]", + "treatment [2]", + "treatment [3]", + NA, + "Observations" ) - expect_identical( - out$Parameter, - c( - "(Intercept)", "Species [versicolor]", "Species [virginica]", - "Petal Length", "Species [versicolor] * Petal Length", - "Species [virginica] * Petal Length", "outcome [2]", "outcome [3]", - "treatment [2]", "treatment [3]", NA, "Observations" - ) + ) + }) + + x <- compare_parameters(m1, m2, m3, select = "se_p2") + test_that("compare_parameters, se_p2", { + expect_identical( + colnames(x), + c( + "Parameter", + "Component", + "Effects", + "Coefficient.m1", + "SE.m1", + "CI.m1", + "CI_low.m1", + "CI_high.m1", + "t.m1", + "df_error.m1", + "p.m1", + "Coefficient.m2", + "SE.m2", + "CI.m2", + "CI_low.m2", + "CI_high.m2", + "t.m2", + "df_error.m2", + "p.m2", + "Log-Mean.m3", + "SE.m3", + "CI.m3", + "CI_low.m3", + "CI_high.m3", + "z.m3", + "df_error.m3", + "p.m3" ) - }) - - - data(mtcars) - m1 <- lm(mpg ~ wt, data = mtcars) - m2 <- glm(vs ~ wt + cyl, data = mtcars, family = "binomial") - - test_that("compare_parameters, column name with escaping regex characters", { - out <- utils::capture.output(compare_parameters(m1, m2, column_names = c("linear model (m1)", "logistic reg. (m2)"))) - expect_identical(out[1], "Parameter | linear model (m1) | logistic reg. (m2)") - }) - - - data(mtcars) - m1 <- lm(mpg ~ hp, mtcars) - m2 <- lm(mpg ~ hp, mtcars) - test_that("compare_parameters, proper printing for CI=NULL #820", { - expect_snapshot(compare_parameters(m1, m2, ci = NULL)) - }) - - - skip_on_cran() - - - test_that("compare_parameters, correct random effects", { - suppressWarnings(skip_if_not_installed("glmmTMB")) - skip_if_not(getRversion() >= "4.0.0") - - data("fish") - m0 <- glm(count ~ child + camper, data = fish, family = poisson()) - - m1 <- glmmTMB::glmmTMB( - count ~ child + camper + (1 | persons) + (1 | ID), - data = fish, - family = poisson() + ) + out <- capture.output(x) + expect_length(out, 14) + out <- format(x, select = "se_p2") + expect_identical( + colnames(out), + c( + "Parameter", + "Coefficient (SE) (m1)", + "p (m1)", + "Coefficient (SE) (m2)", + "p (m2)", + "Log-Mean (SE) (m3)", + "p (m3)" ) - - m2 <- glmmTMB::glmmTMB( - count ~ child + camper + zg + (1 | ID), - ziformula = ~ child + (1 | persons), - data = fish, - family = glmmTMB::truncated_poisson() + ) + expect_identical( + out$Parameter, + c( + "(Intercept)", + "Species [versicolor]", + "Species [virginica]", + "Petal Length", + "Species [versicolor] * Petal Length", + "Species [virginica] * Petal Length", + "outcome [2]", + "outcome [3]", + "treatment [2]", + "treatment [3]", + NA, + "Observations" ) - - cp <- compare_parameters(m0, m1, m2, effects = "all", component = "all") - expect_snapshot(cp) - }) - - - test_that("compare_parameters, print_md-1", { - skip_if_not_installed("lme4") - skip_if_not_installed("knitr") - skip_if_not_installed("tinytable") - - data(sleepstudy, package = "lme4") - set.seed(1234) - sleepstudy$grp <- as.factor(sample.int(3, nrow(sleepstudy), replace = TRUE)) - lm1 <- lme4::lmer(Reaction ~ Days + grp + (1 | Subject), data = sleepstudy) - lm2 <- lme4::lmer(Reaction ~ Days * grp + (1 | Subject), data = sleepstudy) - - cp <- compare_parameters(lm1, lm2, select = "{estimate} ({ci})|{p}", drop = "^\\(Intercept") - out <- print_md(cp, groups = list( - Groups = c(2, 3), - Interactions = c(4, 5), - Controls = 1 - )) - expect_snapshot(print(out)) - }) - - test_that("compare_parameters, print_md-2", { - skip_if_not_installed("lme4") - skip_if_not_installed("knitr") - skip_if_not_installed("tinytable") - - data(sleepstudy, package = "lme4") - set.seed(1234) - sleepstudy$grp <- as.factor(sample.int(3, nrow(sleepstudy), replace = TRUE)) - lm1 <- lme4::lmer(Reaction ~ Days + grp + (1 | Subject), data = sleepstudy) - lm2 <- lme4::lmer(Reaction ~ Days * grp + (1 | Subject), data = sleepstudy) - - cp <- compare_parameters(lm1, lm2, select = "{estimate} ({ci})|{p}", drop = "^\\(Intercept") - out <- display(cp, groups = list( - Groups = c(2, 3), - Interactions = c(4, 5), - Controls = 1 - ), - format = "tt" - ) - expect_snapshot(print(out)) - }) - - test_that("compare_parameters, print_md-3", { - skip_if_not_installed("lme4") - skip_if_not_installed("knitr") - skip_if_not_installed("tinytable") - - data(sleepstudy, package = "lme4") - set.seed(1234) - sleepstudy$grp <- as.factor(sample.int(3, nrow(sleepstudy), replace = TRUE)) - lm1 <- lme4::lmer(Reaction ~ Days + grp + (1 | Subject), data = sleepstudy) - lm2 <- lme4::lmer(Reaction ~ Days * grp + (1 | Subject), data = sleepstudy) - - cp <- compare_parameters(lm1, lm2, select = "{estimate} ({ci})|{p}", drop = "^\\(Intercept", effects = "all") - expect_snapshot(print_md(cp)) - expect_snapshot(display(cp, format = "tt")) - }) - - test_that("compare_parameters, print_md-4", { - skip_if_not_installed("lme4") - skip_if_not_installed("knitr") - skip_if_not_installed("tinytable") - - data(sleepstudy, package = "lme4") - set.seed(1234) - sleepstudy$grp <- as.factor(sample.int(3, nrow(sleepstudy), replace = TRUE)) - lm1 <- lme4::lmer(Reaction ~ Days + grp + (1 | Subject), data = sleepstudy) - lm2 <- lme4::lmer(Reaction ~ Days * grp + (1 | Subject), data = sleepstudy) - - - # with reference level - cp <- compare_parameters(lm1, lm2, select = "{estimate} ({ci})|{p}", drop = "^\\(Intercept", include_reference = TRUE) - out <- print_md(cp, groups = list( - Groups = 2:4, - Interactions = 5:6, - Controls = 1 - )) - expect_snapshot(print(out)) - - }) - - test_that("compare_parameters, print_md-5", { - skip_if_not_installed("lme4") - skip_if_not_installed("knitr") - skip_if_not_installed("tinytable") - - data(sleepstudy, package = "lme4") - set.seed(1234) - sleepstudy$grp <- as.factor(sample.int(3, nrow(sleepstudy), replace = TRUE)) - lm1 <- lme4::lmer(Reaction ~ Days + grp + (1 | Subject), data = sleepstudy) - lm2 <- lme4::lmer(Reaction ~ Days * grp + (1 | Subject), data = sleepstudy) - - # with reference level - cp <- compare_parameters(lm1, lm2, drop = "^\\(Intercept", include_reference = TRUE) - out <- print_md(cp, groups = list( - Groups = 2:4, - Interactions = 5:6, - Controls = 1 - )) - expect_snapshot(print(out)) - - # error - cp <- compare_parameters(lm1, lm2, select = "{estimate} ({ci})|{p}", drop = "^\\(Intercept") - expect_error( - print_md(cp, groups = list( - Groups = c(2, 3), - Interactions = c(4, 5), - Controls = "XDays" - )), - regex = "Some group indices" - ) - expect_error( - print_md(cp, groups = list( - Groups = 1:2, - Interactions = 4:5, - Controls = 10 - )), - regex = "Some group indices" - ) - - # output identical for both calls - cp1 <- compare_parameters(lm1, lm2, select = "{estimate} ({ci})|{p}", drop = "^\\(Intercept") - out1 <- capture.output(print_md(cp1, groups = list( - Groups = 2:3, - Interactions = 4:5, - Controls = 1 - ))) - cp2 <- compare_parameters( - lm1, - lm2, - select = "{estimate} ({ci})|{p}", - drop = "^\\(Intercept", - groups = list( - Groups = c(2, 3), - Interactions = c(4, 5), - Controls = 1 - ) - ) - out2 <- capture.output(print_md(cp2)) - expect_identical(out1, out2) - }) - } -) + ) + }) + + data(mtcars) + m1 <- lm(mpg ~ wt, data = mtcars) + m2 <- glm(vs ~ wt + cyl, data = mtcars, family = "binomial") + + test_that("compare_parameters, column name with escaping regex characters", { + out <- utils::capture.output(compare_parameters( + m1, + m2, + column_names = c("linear model (m1)", "logistic reg. (m2)") + )) + expect_identical(out[1], "Parameter | linear model (m1) | logistic reg. (m2)") + }) + + data(mtcars) + m1 <- lm(mpg ~ hp, mtcars) + m2 <- lm(mpg ~ hp, mtcars) + test_that("compare_parameters, proper printing for CI=NULL #820", { + expect_snapshot(compare_parameters(m1, m2, ci = NULL)) + }) + + skip_on_cran() + + test_that("compare_parameters, correct random effects", { + suppressWarnings(skip_if_not_installed("glmmTMB")) + skip_if_not(getRversion() >= "4.0.0") + + data("fish") + m0 <- glm(count ~ child + camper, data = fish, family = poisson()) + + m1 <- glmmTMB::glmmTMB( + count ~ child + camper + (1 | persons) + (1 | ID), + data = fish, + family = poisson() + ) + + m2 <- glmmTMB::glmmTMB( + count ~ child + camper + zg + (1 | ID), + ziformula = ~ child + (1 | persons), + data = fish, + family = glmmTMB::truncated_poisson() + ) + + cp <- compare_parameters(m0, m1, m2, effects = "all", component = "all") + expect_snapshot(cp) + }) + + test_that("compare_parameters, print_md-1", { + skip_if_not_installed("lme4") + skip_if_not_installed("knitr") + skip_if_not_installed("tinytable") + + data(sleepstudy, package = "lme4") + set.seed(1234) + sleepstudy$grp <- as.factor(sample.int(3, nrow(sleepstudy), replace = TRUE)) + lm1 <- lme4::lmer(Reaction ~ Days + grp + (1 | Subject), data = sleepstudy) + lm2 <- lme4::lmer(Reaction ~ Days * grp + (1 | Subject), data = sleepstudy) + + cp <- compare_parameters( + lm1, + lm2, + select = "{estimate} ({ci})|{p}", + drop = "^\\(Intercept" + ) + out <- print_md( + cp, + groups = list(Groups = c(2, 3), Interactions = c(4, 5), Controls = 1) + ) + expect_snapshot(print(out)) + }) + + test_that("compare_parameters, print_md-2", { + skip_if_not_installed("lme4") + skip_if_not_installed("knitr") + skip_if_not_installed("tinytable") + + data(sleepstudy, package = "lme4") + set.seed(1234) + sleepstudy$grp <- as.factor(sample.int(3, nrow(sleepstudy), replace = TRUE)) + lm1 <- lme4::lmer(Reaction ~ Days + grp + (1 | Subject), data = sleepstudy) + lm2 <- lme4::lmer(Reaction ~ Days * grp + (1 | Subject), data = sleepstudy) + + cp <- compare_parameters( + lm1, + lm2, + select = "{estimate} ({ci})|{p}", + drop = "^\\(Intercept" + ) + out <- display( + cp, + groups = list(Groups = c(2, 3), Interactions = c(4, 5), Controls = 1), + format = "tt" + ) + expect_snapshot(print(out)) + }) + + test_that("compare_parameters, print_md-3", { + skip_if_not_installed("lme4") + skip_if_not_installed("knitr") + skip_if_not_installed("tinytable") + + data(sleepstudy, package = "lme4") + set.seed(1234) + sleepstudy$grp <- as.factor(sample.int(3, nrow(sleepstudy), replace = TRUE)) + lm1 <- lme4::lmer(Reaction ~ Days + grp + (1 | Subject), data = sleepstudy) + lm2 <- lme4::lmer(Reaction ~ Days * grp + (1 | Subject), data = sleepstudy) + + cp <- compare_parameters( + lm1, + lm2, + select = "{estimate} ({ci})|{p}", + drop = "^\\(Intercept", + effects = "all" + ) + expect_snapshot(print_md(cp)) + expect_snapshot(display(cp, format = "tt")) + }) + + test_that("compare_parameters, print_md-4", { + skip_if_not_installed("lme4") + skip_if_not_installed("knitr") + skip_if_not_installed("tinytable") + + data(sleepstudy, package = "lme4") + set.seed(1234) + sleepstudy$grp <- as.factor(sample.int(3, nrow(sleepstudy), replace = TRUE)) + lm1 <- lme4::lmer(Reaction ~ Days + grp + (1 | Subject), data = sleepstudy) + lm2 <- lme4::lmer(Reaction ~ Days * grp + (1 | Subject), data = sleepstudy) + + # with reference level + cp <- compare_parameters( + lm1, + lm2, + select = "{estimate} ({ci})|{p}", + drop = "^\\(Intercept", + include_reference = TRUE + ) + out <- print_md(cp, groups = list(Groups = 2:4, Interactions = 5:6, Controls = 1)) + expect_snapshot(print(out)) + }) + + test_that("compare_parameters, print_md-5", { + skip_if_not_installed("lme4") + skip_if_not_installed("knitr") + skip_if_not_installed("tinytable") + + data(sleepstudy, package = "lme4") + set.seed(1234) + sleepstudy$grp <- as.factor(sample.int(3, nrow(sleepstudy), replace = TRUE)) + lm1 <- lme4::lmer(Reaction ~ Days + grp + (1 | Subject), data = sleepstudy) + lm2 <- lme4::lmer(Reaction ~ Days * grp + (1 | Subject), data = sleepstudy) + + # with reference level + cp <- compare_parameters(lm1, lm2, drop = "^\\(Intercept", include_reference = TRUE) + out <- print_md(cp, groups = list(Groups = 2:4, Interactions = 5:6, Controls = 1)) + expect_snapshot(print(out)) + + # error + cp <- compare_parameters( + lm1, + lm2, + select = "{estimate} ({ci})|{p}", + drop = "^\\(Intercept" + ) + expect_error( + print_md( + cp, + groups = list(Groups = c(2, 3), Interactions = c(4, 5), Controls = "XDays") + ), + regex = "Some group indices" + ) + expect_error( + print_md(cp, groups = list(Groups = 1:2, Interactions = 4:5, Controls = 10)), + regex = "Some group indices" + ) + + # output identical for both calls + cp1 <- compare_parameters( + lm1, + lm2, + select = "{estimate} ({ci})|{p}", + drop = "^\\(Intercept" + ) + out1 <- capture.output(print_md( + cp1, + groups = list(Groups = 2:3, Interactions = 4:5, Controls = 1) + )) + cp2 <- compare_parameters( + lm1, + lm2, + select = "{estimate} ({ci})|{p}", + drop = "^\\(Intercept", + groups = list(Groups = c(2, 3), Interactions = c(4, 5), Controls = 1) + ) + out2 <- capture.output(print_md(cp2)) + expect_identical(out1, out2) + }) +}) skip_on_cran() skip_if_not_installed("blme") @@ -272,7 +341,9 @@ skip_if_not_installed("lme4") test_that("compare_parameters, works with blmer and glmmTMB", { data(sleepstudy, package = "lme4") control <- lme4::lmerControl(check.conv.grad = "ignore") - fm1 <- blme::blmer(Reaction ~ Days + (0 + Days | Subject), sleepstudy, + fm1 <- blme::blmer( + Reaction ~ Days + (0 + Days | Subject), + sleepstudy, control = control, cov.prior = gamma ) diff --git a/tests/testthat/test-glmer.R b/tests/testthat/test-glmer.R index ee55e6343..0c5cb76c0 100644 --- a/tests/testthat/test-glmer.R +++ b/tests/testthat/test-glmer.R @@ -95,5 +95,13 @@ test_that("robust SE/VCOV, using FPC", { tolerance = 1e-4 ) out <- model_parameters(model, vcov = "fpc", vcov_args = list(population_size = 500)) + + expect_snapshot(print(out, table_width = Inf)) + out <- model_parameters( + model, + ci_method = "wald", + vcov = "fpc", + vcov_args = list(population_size = 500) + ) expect_snapshot(print(out, table_width = Inf)) }) diff --git a/tests/testthat/test-lavaan.R b/tests/testthat/test-lavaan.R index 210469514..c31e135a1 100644 --- a/tests/testthat/test-lavaan.R +++ b/tests/testthat/test-lavaan.R @@ -64,7 +64,7 @@ test_that("standardized no CI", { test_that("simulate_model and equivalence_test work for lavaan", { skip_on_cran() - skip_if_not_installed("bayestestR") + skip_if_not_installed("bayestestR", minimum_version = "0.19.0.2") skip_if_not_installed("lavaan") skip_if_not_installed("insight", minimum_version = "1.5.2") @@ -86,7 +86,7 @@ test_that("simulate_model and equivalence_test work for lavaan", { ) set.seed(123) - out <- equivalence_test(m, range = c(-0.2, 0.2)) + out <- equivalence_test(m, range = c(-0.2, 0.2), ci_method = "ETI") expect_identical( capture.output(out), c( @@ -94,7 +94,7 @@ test_that("simulate_model and equivalence_test work for lavaan", { "", " ROPE: [-0.20 0.20]", "", - "Parameter | H0 | inside ROPE | 95% HDI", + "Parameter | H0 | inside ROPE | 95% ETI", "--------------------------------------------------", "y~x | Undecided | 23.05 % | [0.09, 0.42]", "y~~y | Rejected | 0.00 % | [0.43, 0.76]", diff --git a/tests/testthat/test-lmerTest.R b/tests/testthat/test-lmerTest.R index b0706718c..9ef3fb306 100644 --- a/tests/testthat/test-lmerTest.R +++ b/tests/testthat/test-lmerTest.R @@ -4,10 +4,13 @@ skip_if_not_installed("lmerTest") skip_if_not_installed("pbkrtest") data("carrots", package = "lmerTest") -m1 <- lmerTest::lmer(Preference ~ sens2 + Homesize + (1 + sens2 | Consumer), data = carrots) +m1 <- lmerTest::lmer( + Preference ~ sens2 + Homesize + (1 + sens2 | Consumer), + data = carrots +) test_that("model_parameters, satterthwaite", { - params <- model_parameters(m1, effects = "fixed", ci_method = "satterthwaite") + params <- model_parameters(m1, effects = "fixed") s <- summary(m1) expect_equal(params$df, as.vector(s$coefficients[, "df"]), tolerance = 1e-4) expect_equal(params$t, as.vector(s$coefficients[, "t value"]), tolerance = 1e-4) @@ -21,3 +24,64 @@ test_that("model_parameters, kenward", { expect_equal(params$t, as.vector(s$coefficients[, "t value"]), tolerance = 1e-4) expect_equal(params$p, as.vector(s$coefficients[, "Pr(>|t|)"]), tolerance = 1e-4) }) + + +test_that("mixed-model defaults use satterthwaite for lmerModLmerTest", { + params_default <- model_parameters(m1, effects = "fixed") + params_satterthwaite <- model_parameters( + m1, + effects = "fixed", + ci_method = "satterthwaite" + ) + params_wald <- model_parameters(m1, effects = "fixed", ci_method = "wald") + + expect_identical(params_default, params_satterthwaite) + expect_false(identical(params_default, params_wald)) + expect_true(all(params_wald$p < params_default$p)) + expect_identical(params_wald$t, params_default$t) + + expect_identical(ci(m1), ci(m1, method = "satterthwaite")) + expect_identical(standard_error(m1), standard_error(m1, method = "satterthwaite")) + expect_identical(p_value(m1), p_value(m1, method = "satterthwaite")) +}) + + +test_that("satterthwaite default keeps a robust vcov", { + skip_if_not_installed("clubSandwich") + data("sleepstudy", package = "lme4") + m <- lmerTest::lmer(Reaction ~ Days + (1 | Subject), data = sleepstudy) + out <- model_parameters( + m, + effects = "fixed", + ci_method = "satterthwaite", + vcov = "CR0", + vcov_args = list(cluster = sleepstudy$Subject) + ) + expect_equal( + out$CI_low, + out$Coefficient - stats::qt(0.975, out$df_error) * out$SE, + tolerance = 1e-6 + ) + out_ci <- ci(m, vcov = "CR0", vcov_args = list(cluster = sleepstudy$Subject)) + expect_equal(out_ci$CI_low, out$CI_low, tolerance = 1e-6) +}) + +test_that("glmer", { + glmer_model <- lme4::glmer(vs ~ cyl + (1 | gear), data = mtcars, family = "binomial") + + expect_identical(ci(glmer_model), ci(glmer_model, method = "wald")) + expect_identical( + standard_error(glmer_model), + standard_error(glmer_model, method = "wald") + ) + expect_identical(p_value(glmer_model), p_value(glmer_model, method = "wald")) +}) + +test_that("lmerMod with lme4 give a warning once", { + data("sleepstudy", package = "lme4") + m <- lme4::lmer(Reaction ~ Days + (1 | Subject), data = sleepstudy) + # other tests in this session may already have shown the message + withr::local_options(.suggest_satterthwaite_for_lmerMod = TRUE) + expect_message(ci(m), "satterthwaite") + expect_no_message(ci(m)) +}) diff --git a/tests/testthat/test-model_parameters.anova.R b/tests/testthat/test-model_parameters.anova.R index 5e3eee158..d9566a703 100644 --- a/tests/testthat/test-model_parameters.anova.R +++ b/tests/testthat/test-model_parameters.anova.R @@ -1,15 +1,17 @@ skip_on_cran() -m <- glm(am ~ mpg + hp + factor(cyl), - data = mtcars, family = binomial() -) +m <- glm(am ~ mpg + hp + factor(cyl), data = mtcars, family = binomial()) test_that("model_parameters.anova", { a <- anova(m, test = "Chisq") mp <- model_parameters(a) expect_named(mp, c("Parameter", "df", "Deviance", "df_error", "Deviance_error", "p")) - expect_equal(mp$Deviance_error, c(43.22973, 29.67517, 19.23255, 10.48692), tolerance = 1e-3) + expect_equal( + mp$Deviance_error, + c(43.22973, 29.67517, 19.23255, 10.48692), + tolerance = 1e-3 + ) expect_equal(mp$p, c(NA, 0.00023, 0.00123, 0.01262), tolerance = 1e-3) expect_snapshot(mp) }) @@ -27,7 +29,10 @@ test_that("model_parameters.anova for mixed models", { skip_if_not_installed("lmerTest") m <- lmerTest::lmer(mpg ~ wt + (1 | gear), data = mtcars) out <- parameters::model_parameters(anova(m)) - expect_named(out, c("Parameter", "Sum_Squares", "df", "df_error", "Mean_Square", "F", "p")) + expect_named( + out, + c("Parameter", "Sum_Squares", "df", "df_error", "Mean_Square", "F", "p") + ) expect_equal(out$df_error, 21.92272, tolerance = 1e-4) }) @@ -95,12 +100,16 @@ test_that("model_parameters_Anova.mlm-2", { test_that("model_parameters_Anova-effectsize", { skip_if_not_installed("lme4") + skip_if_not_installed("lmerTest") skip_if_not_installed("effectsize") df <- iris df$Sepal.Big <- ifelse(df$Sepal.Width >= 3, "Yes", "No") - mm <- suppressMessages(lme4::lmer(Sepal.Length ~ Sepal.Big + Petal.Width + (1 | Species), data = df)) + mm <- suppressMessages(lme4::lmer( + Sepal.Length ~ Sepal.Big + Petal.Width + (1 | Species), + data = df + )) model <- anova(mm) # parameters table including effect sizes @@ -114,8 +123,14 @@ test_that("model_parameters_Anova-effectsize", { expect_identical( colnames(mp), c( - "Parameter", "Sum_Squares", "df", "Mean_Square", "F", "Eta2_partial", - "Eta2_CI_low", "Eta2_CI_high" + "Parameter", + "Sum_Squares", + "df", + "Mean_Square", + "F", + "Eta2_partial", + "Eta2_CI_low", + "Eta2_CI_high" ) ) expect_equal(mp$Eta2_partial, c(0.03262, 0.6778), tolerance = 1e-3) @@ -146,15 +161,13 @@ test_that("anova type | lm", { m <- lm(mpg ~ factor(cyl) + hp + disp, mtcars) expect_warning(model_parameters(aov(m)), regexp = NA) # no need for warning, because no interactions - m <- lm(mpg ~ factor(cyl) * scale(disp, TRUE, FALSE) + scale(disp, TRUE, FALSE), + m <- lm( + mpg ~ factor(cyl) * scale(disp, TRUE, FALSE) + scale(disp, TRUE, FALSE), mtcars, contrasts = list("factor(cyl)" = contr.helmert) ) a3 <- car::Anova(m, type = 3) - expect_message( - model_parameters(a3), - "Type 3 ANOVAs only give" - ) + expect_message(model_parameters(a3), "Type 3 ANOVAs only give") }) test_that("anova type | mlm", { @@ -198,7 +211,9 @@ test_that("anova type | lme4", { m1 <- lme4::lmer(mpg ~ factor(cyl) * hp + disp + (1 | gear), mtcars) suppressMessages({ - m2 <- lme4::glmer(carb ~ factor(cyl) * hp + disp + (1 | gear), mtcars, + m2 <- lme4::glmer( + carb ~ factor(cyl) * hp + disp + (1 | gear), + mtcars, family = poisson() ) }) @@ -238,9 +253,13 @@ test_that("anova type | afex + Anova.mlm", { data(obk.long, package = "afex") suppressMessages({ - m <- afex::aov_ez("id", "value", obk.long, + m <- afex::aov_ez( + "id", + "value", + obk.long, between = c("treatment", "gender"), - within = c("phase", "hour"), observed = "gender" + within = c("phase", "hour"), + observed = "gender" ) }) @@ -256,7 +275,10 @@ test_that("anova rms", { expect_identical(attr(mp, "anova_type"), 2) expect_identical(mp$Parameter, c("cyl", "disp", "hp", "drat", "Total", "Residuals")) - expect_identical(colnames(mp), c("Parameter", "Sum_Squares_Partial", "df", "Mean_Square", "F", "p")) + expect_identical( + colnames(mp), + c("Parameter", "Sum_Squares_Partial", "df", "Mean_Square", "F", "p") + ) expect_equal(mp$Sum_Squares_Partial, data.frame(a)$Partial.SS, tolerance = 1e-3) }) diff --git a/tests/testthat/test-model_parameters.mixed.R b/tests/testthat/test-model_parameters.mixed.R index 3e7aa6d5f..e12bc404c 100644 --- a/tests/testthat/test-model_parameters.mixed.R +++ b/tests/testthat/test-model_parameters.mixed.R @@ -18,7 +18,7 @@ test_that("model_parameters.mixed", { expect_identical(c(nrow(params), ncol(params)), c(2L, 10L)) expect_equal(params$CI_high, c(1.6373105660317, 0.554067677205595), tolerance = 1e-3) - params <- model_parameters(m1, effects = "fixed") + params <- model_parameters(m1, ci_method = "wald", effects = "fixed") expect_identical(c(nrow(params), ncol(params)), c(2L, 10L)) expect_equal(params$CI_high, c(1.68181, 0.56083), tolerance = 1e-3) @@ -49,11 +49,6 @@ test_that("model_parameters.mixed", { expect_equal(params$CI_high_0.8, c(1.31154, 0.50455), tolerance = 1e-3) expect_equal(params$CI_high_0.9, c(1.50707, 0.53427), tolerance = 1e-3) - params <- model_parameters(m1, ci = c(0.8, 0.9), effects = "fixed") - expect_identical(c(nrow(params), ncol(params)), c(2L, 11L)) - expect_equal(params$CI_high_0.8, c(1.31154, 0.50455), tolerance = 1e-3) - expect_equal(params$CI_high_0.9, c(1.50707, 0.53427), tolerance = 1e-3) - params <- model_parameters(m2, effects = "fixed") expect_identical(c(nrow(params), ncol(params)), c(2L, 10L)) diff --git a/tests/testthat/test-p_value.R b/tests/testthat/test-p_value.R index a378d0101..e1fc0cfc0 100644 --- a/tests/testthat/test-p_value.R +++ b/tests/testthat/test-p_value.R @@ -10,7 +10,6 @@ test_that("p_value", { }) - skip_on_cran() test_that("p_value", { @@ -122,7 +121,6 @@ test_that("p_value", { skip_if(is.null(model)) expect_equal(p_value(model)$p[2], 0, tolerance = 0.01) - # Mixed models model <- lme4::lmer(wt ~ cyl + (1 | gear), data = mtcars) expect_equal(p_value(model)$p[1], 0.206219, tolerance = 0.01) diff --git a/tests/testthat/test-printing2.R b/tests/testthat/test-printing2.R index 04ff9eaf0..4339284a3 100644 --- a/tests/testthat/test-printing2.R +++ b/tests/testthat/test-printing2.R @@ -233,7 +233,7 @@ withr::with_options(list(parameters_interaction = "*", easystats_table_width = I "Parameter | m0 | m1 | m2", "--------------------------------------------------------------------------------", "(Intercept) | 0.91 ( 0.75, 1.07) | 0.68 (-0.54, 1.91) | 1.41 ( 1.06, 1.75)", - "child | -1.23 (-1.39, -1.08) | -1.67 (-1.84, -1.51) | -0.53 (-0.77, -0.29)", + "child | -1.23 (-1.40, -1.08) | -1.67 (-1.84, -1.51) | -0.53 (-0.77, -0.29)", "camper [1] | 1.05 ( 0.88, 1.23) | 0.94 ( 0.77, 1.12) | 0.58 ( 0.39, 0.78)", "zg | | | 0.13 ( 0.05, 0.21)", "", diff --git a/tests/testthat/test-random_effects_ci.R b/tests/testthat/test-random_effects_ci.R index 86919ee3b..af53fb70c 100644 --- a/tests/testthat/test-random_effects_ci.R +++ b/tests/testthat/test-random_effects_ci.R @@ -30,26 +30,26 @@ m5 <- suppressMessages(lme4::lmer( expect_message( { - mp1 <- model_parameters(m1, ci_random = TRUE) + mp1 <- model_parameters(m1, ci_random = TRUE, ci_method = "wald") }, regex = "meaningful" ) -mp2 <- model_parameters(m2, ci_random = TRUE) +mp2 <- model_parameters(m2, ci_random = TRUE, effects = "random") expect_message( { - mp3 <- model_parameters(m3, ci_random = TRUE) + mp3 <- model_parameters(m3, ci_random = TRUE, effects = "random") }, regex = "meaningful" ) expect_message( { - mp4 <- model_parameters(m4, ci_random = TRUE) + mp4 <- model_parameters(m4, ci_random = TRUE, effects = "random") }, regex = "meaningful" ) expect_message( { - mp5 <- model_parameters(m5, ci_random = TRUE) + mp5 <- model_parameters(m5, ci_random = TRUE, effects = "random") }, regex = "meaningful" ) @@ -62,7 +62,8 @@ test_that("random effects CIs, two slopes, categorical", { expect_equal( mp1$CI_low, c( - 28.75405, 4.97865, -1.95011, -2.70111, -3.62199, -2.69102, + 28.7559334902632, 4.97904339539053, -1.95014363947862, -2.70058819820767, + -3.62294029941172, -2.69095690811178, 4.28813, 0.21457, 0.5742, 0.28738, 0.02089, 1e-05, 0.55402, 0, 0, 0.2781, 0.38107, 0.00945, -0.65343, -0.7222, -1, -0.99521, -0.97784, -1, -1, -1, -1, -1, -1, -0.99594, -1, -0.90229, -0.99736, @@ -190,24 +191,17 @@ test_that("random effects CIs, two slopes, categorical", { test_that("random effects CIs, simple slope", { expect_equal( mp2$CI_low, - c(237.93546, 7.41637, 15.5817, 3.91828, -0.50907, 22.80044), + c(15.5817, 3.91828, -0.50907, 22.80044), tolerance = 1e-3, ignore_attr = TRUE ) expect_identical( mp2$Parameter, - c( - "(Intercept)", - "Days", - "SD (Intercept)", - "SD (Days)", - "Cor (Intercept~Days)", - "SD (Observations)" - ) + c("SD (Intercept)", "SD (Days)", "Cor (Intercept~Days)", "SD (Observations)") ) - expect_identical(mp2$Group, c("", "", "Subject", "Subject", "Subject", "Residual")) + expect_identical(mp2$Group, c("Subject", "Subject", "Subject", "Residual")) }) @@ -215,40 +209,15 @@ test_that("random effects CIs, simple slope", { test_that("random effects CIs, categorical slope-1", { expect_equal( - mp3$CI_low[14:28], + mp3$CI_low[8:22], c(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 7.09933), tolerance = 1e-2, ignore_attr = TRUE ) - expect_equal( - mp3$CI_low[1:12], - c( - 30.91139, - 4.33247, - -2.6798, - -3.20703, - -4.07681, - -3.27237, - 0.06301, - 0, - 0, - 0.1192, - 0.32213, - 0 - ), - tolerance = 1e-2, - ignore_attr = TRUE - ) expect_identical( mp3$Parameter, c( - "(Intercept)", - "temperature.L", - "temperature.Q", - "temperature.C", - "temperature^4", - "temperature^5", "SD (Intercept)", "SD (temperature.L)", "SD (temperature.Q)", @@ -277,12 +246,6 @@ test_that("random effects CIs, categorical slope-1", { expect_identical( mp3$Group, c( - "", - "", - "", - "", - "", - "", "recipe", "recipe", "recipe", @@ -317,7 +280,6 @@ test_that("random effects CIs, categorical slope-2", { expect_equal( mp4$CI_low, c( - 28.88447, 4.96795, -1.93231, -1.98596, -2.68856, -2.55248, 4.28006, 0.51326, 0.23954, 0.01238, 0, 0.5001, -0.68888, -0.74701, -1, -0.99746, -0.98211, -1, -0.99788, -1, -0.92289, -0.99878, -1, -0.98562, -1, -1, -1, 4.21137 @@ -329,12 +291,6 @@ test_that("random effects CIs, categorical slope-2", { expect_identical( mp4$Parameter, c( - "(Intercept)", - "temperature.L", - "temperature.Q", - "temperature.C", - "temperature^4", - "temperature^5", "SD (Intercept)", "SD (temperature.L)", "SD (temperature.Q)", @@ -363,12 +319,6 @@ test_that("random effects CIs, categorical slope-2", { expect_identical( mp4$Group, c( - "", - "", - "", - "", - "", - "", "replicate", "replicate", "replicate", @@ -401,7 +351,7 @@ test_that("random effects CIs, categorical slope-2", { test_that("random effects CIs, double slope", { expect_equal( mp5$CI_low, - c(237.99863, 7.4022, 12.63814, 3.91669, 0, -0.58599, -1, -1, 22.65226), + c(12.63814, 3.91669, 0, -0.58599, -1, -1, 22.65226), tolerance = 1e-3, ignore_attr = TRUE ) @@ -409,8 +359,6 @@ test_that("random effects CIs, double slope", { expect_identical( mp5$Parameter, c( - "(Intercept)", - "Days", "SD (Intercept)", "SD (Days)", "SD (Months)", @@ -423,17 +371,7 @@ test_that("random effects CIs, double slope", { expect_identical( mp5$Group, - c( - "", - "", - "Subject", - "Subject", - "Subject", - "Subject", - "Subject", - "Subject", - "Residual" - ) + c("Subject", "Subject", "Subject", "Subject", "Subject", "Subject", "Residual") ) }) @@ -447,37 +385,22 @@ test_that("random effects CIs, simple slope", { m2 <- lme4::lmer(Reaction ~ Days + (0 + Days | Subject), data = sleepstudy) m5 <- lme4::lmer(Reaction ~ Days + (0 + Days + Months | Subject), data = sleepstudy) - mp2 <- model_parameters(m2) - mp5 <- model_parameters(m5) - expect_equal( - mp2$CI_low, - c(243.47155, 6.77765, 5.09041, 26.01525), - tolerance = 1e-3, - ignore_attr = TRUE - ) + mp2 <- model_parameters(m2, effects = "random") + mp5 <- model_parameters(m5, effects = "random") + expect_equal(mp2$CI_low, c(5.09041, 26.01525), tolerance = 1e-3, ignore_attr = TRUE) - expect_identical( - mp2$Parameter, - c("(Intercept)", "Days", "SD (Days)", "SD (Observations)") - ) + expect_identical(mp2$Parameter, c("SD (Days)", "SD (Observations)")) expect_equal( mp5$CI_low, - c(241.61021, 7.43503, 4.11446, 2.69857, -0.40595, 24.632), + c(4.11446, 2.69857, -0.40595, 24.632), tolerance = 1e-3, ignore_attr = TRUE ) expect_identical( mp5$Parameter, - c( - "(Intercept)", - "Days", - "SD (Days)", - "SD (Months)", - "Cor (Days~Months)", - "SD (Observations)" - ) + c("SD (Days)", "SD (Months)", "Cor (Days~Months)", "SD (Observations)") ) }) @@ -491,13 +414,13 @@ test_that("random effects CIs, poly slope", { data = cake ) }) - mp <- model_parameters(m, ci_random = TRUE) + mp <- model_parameters(m, ci_random = TRUE, effects = "random") # fmt: skip expect_equal( mp$CI_low, c( - 28.78854, 33.56292, -12.84337, 4.27419, 0.16217, 2.30959, 0.87852, + 4.27419, 0.16217, 2.30959, 0.87852, -0.81742, -0.80941, -1, 4.32856 ), tolerance = 1e-3, @@ -507,9 +430,6 @@ test_that("random effects CIs, poly slope", { expect_identical( mp$Parameter, c( - "(Intercept)", - "poly(temp, 2)1", - "poly(temp, 2)2", "SD (Intercept)", "SD (Intercept)", "SD (poly(temp, 2)1)", @@ -533,7 +453,7 @@ test_that("random effects CIs, poly categorical slope", { angle ~ poly(temp, 2) + (poly(temp, 2) | replicate) + (temperature | recipe), data = cake ) - mp <- model_parameters(m, effects = "random", ci = TRUE) + mp <- model_parameters(m, effects = "random", ci_random = TRUE) # fmt: skip expect_equal( diff --git a/tests/testthat/test-random_effects_covstruct.R b/tests/testthat/test-random_effects_covstruct.R index 058f2a4d0..af0dc3d3b 100644 --- a/tests/testthat/test-random_effects_covstruct.R +++ b/tests/testthat/test-random_effects_covstruct.R @@ -142,7 +142,7 @@ test_that("random effects, lme4, cov-struct AR1", { y ~ 1 + (as.numeric(time) | id) + ar1(time + 0 | id), data = dat )) - out <- model_parameters(m_ar1, effects = "random", ci_random = 0.95, verbose = FALSE) + out <- model_parameters(m_ar1, effects = "random", verbose = FALSE) expect_named( out, c("Parameter", "Coefficient", "SE", "CI", "CI_low", "CI_high", "Effects", "Group") @@ -164,8 +164,6 @@ test_that("random effects, lme4, cov-struct AR1", { c(0.3929, 0.0747, 0.9012, 0.1467, 0.242, 0.1319), tolerance = 1e-3 ) - out <- model_parameters(m_ar1, effects = "random", ci_random = FALSE, verbose = FALSE) - expect_named(out, c("Parameter", "Coefficient", "SE", "Effects", "Group", "CI")) }) test_that("random effects, glmmTMB, cov-struct OU", { diff --git a/tests/testthat/test-robust.R b/tests/testthat/test-robust.R index 1a6649f5a..af1b1cc8c 100644 --- a/tests/testthat/test-robust.R +++ b/tests/testthat/test-robust.R @@ -396,7 +396,12 @@ test_that("robust-ci lmer", { Sepal.Length ~ Species * Sepal.Width + Petal.Length + (1 | grp), data = iris ) - ci1 <- ci(m, vcov = "vcovCR", vcov_args = list(type = "CR1", cluster = iris$grp)) + ci1 <- ci( + m, + method = "wald", + vcov = "vcovCR", + vcov_args = list(type = "CR1", cluster = iris$grp) + ) # robust CI manually params <- insight::get_parameters(m) se <- sqrt(diag(clubSandwich::vcovCR(m, type = "CR1", cluster = iris$grp)))