Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap Argument in parameters::parameters() Function Not Working with svyglm Models #919

Merged
merged 15 commits into from
Nov 21, 2023
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: parameters
Title: Processing of Model Parameters
Version: 0.21.3.2
Version: 0.21.3.3
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down Expand Up @@ -146,6 +146,7 @@ Suggests:
lme4,
lmerTest,
lmtest,
logistf,
logspline,
lqmm,
M3C,
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
`marginaleffects::predictions()` now defaults to `FALSE`, in line with all
the other `model_parameters()` methods.

## Changes

* `model_parameters()` for models of package *survey* now gives informative
messages when `bootstrap = TRUE` (which is currently not supported).

# parameters 0.21.3

## Changes
Expand Down
20 changes: 10 additions & 10 deletions R/1_model_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
#'
#' Compared to fixed effects (or single-level) models, determining appropriate
#' df for Wald-based inference in mixed models is more difficult.
#' See [the R GLMM FAQ](https://bbolker.github.io/mixedmodels-misc/glmmFAQ.html#what-are-the-p-values-listed-by-summaryglmerfit-etc.-are-they-reliable)

Check warning on line 184 in R/1_model_parameters.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/1_model_parameters.R,line=184,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 151 characters.

Check warning on line 184 in R/1_model_parameters.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/1_model_parameters.R,line=184,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 151 characters.
#' for a discussion.
#'
#' Several approximate methods for computing df are available, but you should
Expand Down Expand Up @@ -576,14 +576,14 @@
ci_method <- "quantile"
}

args <- list(
fun_args <- list(
model,
iterations = iterations,
ci = ci,
ci_method = ci_method
)
args <- c(args, dots)
params <- do.call("bootstrap_parameters", args)
fun_args <- c(fun_args, dots)
params <- do.call("bootstrap_parameters", fun_args)

# Processing, non-bootstrapped parameters
} else {
Expand All @@ -592,7 +592,7 @@
ci_method <- "wald"
}

args <- list(
fun_args <- list(
model,
ci = ci,
component = component,
Expand All @@ -607,8 +607,8 @@
vcov = vcov,
vcov_args = vcov_args
)
args <- c(args, dots)
params <- do.call(".extract_parameters_generic", args)
fun_args <- c(fun_args, dots)
params <- do.call(".extract_parameters_generic", fun_args)
}


Expand Down Expand Up @@ -686,12 +686,12 @@
# tell user that profiled CIs don't respect vcov-args
if (identical(ci_method, "profile") && (!is.null(vcov) || !is.null(vcov_args)) && isTRUE(verbose)) {
insight::format_alert(
"When `ci_method=\"profile\"`, `vcov` only modifies standard errors, test-statistic and p-values, but not confidence intervals.",
"When `ci_method=\"profile\"`, `vcov` only modifies standard errors, test-statistic and p-values, but not confidence intervals.", # nolint
"Use `ci_method=\"wald\"` to return confidence intervals based on robust standard errors."
)
}

args <- list(
fun_args <- list(
model = model,
ci = ci,
ci_method = ci_method,
Expand All @@ -708,8 +708,8 @@
vcov_args = vcov_args,
verbose = verbose
)
args <- c(args, dots)
out <- do.call(".model_parameters_generic", args)
fun_args <- c(fun_args, dots)
out <- do.call(".model_parameters_generic", fun_args)

attr(out, "object_name") <- insight::safe_deparse_symbol(substitute(model))
out
Expand Down
6 changes: 3 additions & 3 deletions R/3_p_value.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ p_value.default <- function(model,
if (inherits(vcov, "data.frame") || "SE" %in% colnames(vcov)) {
se <- vcov
} else {
args <- list(model,
fun_args <- list(model,
vcov_args = vcov_args,
vcov = vcov,
verbose = verbose
)
args <- c(args, dots)
se <- do.call("standard_error", args)
fun_args <- c(fun_args, dots)
se <- do.call("standard_error", fun_args)
}

dof <- degrees_of_freedom(model, method = "wald", verbose = FALSE)
Expand Down
4 changes: 2 additions & 2 deletions R/4_standard_error.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@

# vcov: function which returns a matrix
if (is.function(vcov)) {
args <- c(list(model), vcov_args, dots)
se <- .safe(sqrt(diag(do.call("vcov", args))))
fun_args <- c(list(model), vcov_args, dots)
se <- .safe(sqrt(diag(do.call("vcov", fun_args))))
}

# vcov: character (with backward compatibility for `robust = TRUE`)
Expand Down Expand Up @@ -185,27 +185,27 @@


# .ranef_se <- function(x) {
# insight::check_if_installed("lme4")

Check warning on line 188 in R/4_standard_error.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/4_standard_error.R,line=188,col=3,[commented_code_linter] Commented code should be removed.
#
# cc <- stats::coef(model)

Check warning on line 190 in R/4_standard_error.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/4_standard_error.R,line=190,col=5,[commented_code_linter] Commented code should be removed.
#
# # get names of intercepts
# inames <- names(cc)

Check warning on line 193 in R/4_standard_error.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/4_standard_error.R,line=193,col=5,[commented_code_linter] Commented code should be removed.
#
# # variances of fixed effects
# fixed.vars <- diag(as.matrix(stats::vcov(model)))

Check warning on line 196 in R/4_standard_error.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/4_standard_error.R,line=196,col=5,[commented_code_linter] Commented code should be removed.
#
# # extract variances of conditional modes
# r1 <- lme4::ranef(model, condVar = TRUE)

Check warning on line 199 in R/4_standard_error.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/4_standard_error.R,line=199,col=5,[commented_code_linter] Commented code should be removed.
#
# # we may have multiple random intercepts, iterate all
# se.merMod <- lapply(1:length(cc), function(i) {
# cmode.vars <- t(apply(attr(r1[[i]], "postVar"), 3, diag))

Check warning on line 203 in R/4_standard_error.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/4_standard_error.R,line=203,col=7,[commented_code_linter] Commented code should be removed.
# seVals <- sqrt(sweep(cmode.vars, 2, fixed.vars[names(r1[[i]])], "+", check.margin = FALSE))

Check warning on line 204 in R/4_standard_error.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/4_standard_error.R,line=204,col=7,[commented_code_linter] Commented code should be removed.
#
# if (length(r1[[i]]) == 1) {
# seVals <- as.data.frame(t(seVals))

Check warning on line 207 in R/4_standard_error.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/4_standard_error.R,line=207,col=9,[commented_code_linter] Commented code should be removed.
# stats::setNames(seVals, names(r1[[i]]))

Check warning on line 208 in R/4_standard_error.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/4_standard_error.R,line=208,col=9,[commented_code_linter] Commented code should be removed.
# } else {
# seVals <- seVals[, 1:2]
# stats::setNames(as.data.frame(seVals), names(r1[[i]]))
Expand Down
16 changes: 8 additions & 8 deletions R/ci_profile_boot.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@
dot_args <- .check_profile_uniroot_args(...)

if (is.null(profiled)) {
args <- list(x, method = "profile", level = ci, dot_args)
out <- as.data.frame(do.call(stats::confint, args))
fun_args <- list(x, method = "profile", level = ci, dot_args)
out <- as.data.frame(do.call(stats::confint, fun_args))
} else {
args <- list(profiled, level = ci, dot_args)
out <- .safe(as.data.frame(do.call(stats::confint, args)))
fun_args <- list(profiled, level = ci, dot_args)
out <- .safe(as.data.frame(do.call(stats::confint, fun_args)))
if (is.null(out)) {
args <- list(x, method = "profile", level = ci, dot_args)
out <- as.data.frame(do.call(stats::confint, args))
fun_args <- list(x, method = "profile", level = ci, dot_args)
out <- as.data.frame(do.call(stats::confint, fun_args))
}
}
.process_glmmTMB_CI(x, out, ci, component)
Expand All @@ -103,8 +103,8 @@
.ci_uniroot_glmmTMB <- function(x, ci, component, ...) {
# make sure "..." doesn't pass invalid arguments to package TMB
dot_args <- .check_profile_uniroot_args(...)
args <- list(x, level = ci, method = "uniroot", dot_args)
out <- as.data.frame(do.call(stats::confint, args))
fun_args <- list(x, level = ci, method = "uniroot", dot_args)
out <- as.data.frame(do.call(stats::confint, fun_args))
.process_glmmTMB_CI(x, out, ci, component)
}

Expand Down
7 changes: 3 additions & 4 deletions R/dominance_analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
}

model_info <- insight::model_info(model)
if (any(unlist(model_info[c("is_bayesian", "is_mixed", "is_gam", "is_multivariate", "is_zero_inflated", "is_hurdle")]))) {

Check warning on line 159 in R/dominance_analysis.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/dominance_analysis.R,line=159,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 124 characters.
insight::format_error(
paste0("`dominance_analysis()` does not yet support models of class `", class(model)[[1]], "`."),
"You may be able to dominance analyze this model using the {.pkg domir} package."
Expand Down Expand Up @@ -228,7 +228,7 @@
reg <- as.list(insight::get_call(model))[[1]]

# Process sets ----
if (!is.null(sets)) {

Check warning on line 231 in R/dominance_analysis.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/dominance_analysis.R,line=231,col=7,[if_not_else_linter] In a simple if/else statement, prefer `if (A) x else y` to the less-readable `if (!A) y else x`.
# gather predictors from each set
sets_processed <- lapply(sets, function(x) attr(stats::terms(x), "term.labels"))

Expand All @@ -250,7 +250,7 @@
# apply names to sets
set_names <- names(sets)

missing_set_names <- which(set_names == "")

Check warning on line 253 in R/dominance_analysis.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/dominance_analysis.R,line=253,col=32,[nzchar_linter] Instead of comparing strings to "", use nzchar(). Note that if x is a factor, you'll have use as.character() to replicate an implicit conversion that happens in x == "". Whenever missing data is possible, please take care to use nzchar(., keepNA = TRUE); nzchar(NA) is TRUE by default.

if (length(missing_set_names) > 0) {
set_names[missing_set_names] <- paste0("set", missing_set_names)
Expand All @@ -277,7 +277,7 @@
}

# Process all ----
if (!is.null(all)) {

Check warning on line 280 in R/dominance_analysis.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/dominance_analysis.R,line=280,col=7,[if_not_else_linter] In a simple if/else statement, prefer `if (A) x else y` to the less-readable `if (!A) y else x`.
# gather predictors in all
all_processed <- attr(stats::terms(all), "term.labels")

Expand Down Expand Up @@ -331,9 +331,9 @@
if (length(ivs) == 0) ivs <- "1"
fml <- stats::reformulate(ivs, response = dv, intercept = insight::has_intercept(model))

data <- insight::get_data(model, verbose = FALSE)

Check warning on line 334 in R/dominance_analysis.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/dominance_analysis.R,line=334,col=3,[object_overwrite_linter] 'data' is an exported object from package 'utils'. Avoid re-using such symbols.

args <- as.list(insight::get_call(model), collapse = "") # extract all arguments from call

Check warning on line 336 in R/dominance_analysis.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/dominance_analysis.R,line=336,col=3,[object_overwrite_linter] 'args' is an exported object from package 'base'. Avoid re-using such symbols.

loc <- which(!(names(args) %in% c("formula", "data"))) # find formula and data arguments

Expand All @@ -342,16 +342,15 @@
insight::format_error("Model submitted does not have a formula and `data` argument.")
}

args <- args[loc] # remove formula and data arguments

Check warning on line 345 in R/dominance_analysis.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/dominance_analysis.R,line=345,col=3,[object_overwrite_linter] 'args' is an exported object from package 'base'. Avoid re-using such symbols.
args <- args[-1] # remove function name

Check warning on line 346 in R/dominance_analysis.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/dominance_analysis.R,line=346,col=3,[object_overwrite_linter] 'args' is an exported object from package 'base'. Avoid re-using such symbols.

# quote arguments for domin
for (arg in quote_args) {
if (!(arg %in% names(args))) {
insight::format_error(arg, " in `quote_args` not among arguments in model.")
if (arg %in% names(args)) {
args[[arg]] <- str2lang(paste0("quote(", deparse(args[[arg]]), ")", collapse = ""))
} else {
args[[arg]] <-
str2lang(paste0("quote(", deparse(args[[arg]]), ")", collapse = ""))
insight::format_error(arg, " in `quote_args` not among arguments in model.")
}
}

Expand Down Expand Up @@ -444,7 +443,7 @@
# Apply set names
if (!is.null(sets)) {
for (set in seq_along(sets)) {
set_name <- if (!is.null(names(sets)[[set]])) {

Check warning on line 446 in R/dominance_analysis.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/dominance_analysis.R,line=446,col=23,[if_not_else_linter] In a simple if/else statement, prefer `if (A) x else y` to the less-readable `if (!A) y else x`.
names(sets)[[set]]
} else {
paste0("set", set)
Expand Down
Loading
Loading