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

parameters.fixest: Uninformative error #1055

Merged
merged 9 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 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.24.0.4
Version: 0.24.0.5
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down Expand Up @@ -224,4 +224,4 @@ Config/testthat/edition: 3
Config/testthat/parallel: true
Config/Needs/website: easystats/easystatstemplate
Config/rcmdcheck/ignore-inconsequential-notes: true
Remotes: easystats/datawizard, easystats/performance
Remotes: easystats/insight, easystats/datawizard, easystats/performance
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# parameters 0.24.1

## Changes

* `model_parameters()` now gives informative error messages for more model
classes than before when the function fails to extract model parameters.

## Bug fixes

* Fixed issue when printing `model_parameters()` with models from `mgcv::gam()`.
Expand Down
200 changes: 103 additions & 97 deletions R/1_model_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,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 187 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=187,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 151 characters.

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

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/1_model_parameters.R,line=187,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 @@ -605,32 +605,31 @@
)

# extract model parameters table, as data frame
out <- tryCatch(
.model_parameters_generic(
model = model,
ci = ci,
ci_method = ci_method,
bootstrap = bootstrap,
iterations = iterations,
merge_by = "Parameter",
standardize = standardize,
exponentiate = exponentiate,
p_adjust = p_adjust,
include_info = include_info,
keep_parameters = keep,
drop_parameters = drop,
vcov = vcov,
vcov_args = vcov_args,
verbose = verbose,
...
),
error = function(e) {
fail <- NA
attr(fail, "error") <- gsub(" ", " ", gsub("\\n", "", e$message), fixed = TRUE)
fail
}
out <- .model_parameters_generic(
model = model,
ci = ci,
ci_method = ci_method,
bootstrap = bootstrap,
iterations = iterations,
merge_by = "Parameter",
standardize = standardize,
exponentiate = exponentiate,
p_adjust = p_adjust,
include_info = include_info,
keep_parameters = keep,
drop_parameters = drop,
vcov = vcov,
vcov_args = vcov_args,
verbose = verbose,
...
)

attr(out, "object_name") <- insight::safe_deparse_symbol(substitute(model))
out
}


.fail_error_message <- function(out, model) {
# tell user if something went wrong...
if (length(out) == 1 && isTRUE(is.na(out))) {
insight::format_error(
Expand All @@ -650,14 +649,9 @@
)
)
}

attr(out, "object_name") <- insight::safe_deparse_symbol(substitute(model))
out
}




# helper function for the composition of the parameters table,
# including a bunch of attributes required for further processing
# (like printing etc.)
Expand All @@ -682,79 +676,91 @@
...) {
dots <- list(...)

# ==== 1. first step, extracting (bootstrapped) model parameters -------

# Processing, bootstrapped parameters
if (bootstrap) {
# set default method for bootstrapped CI
if (is.null(ci_method) || missing(ci_method)) {
ci_method <- "quantile"
}

fun_args <- list(
model,
iterations = iterations,
ci = ci,
ci_method = ci_method
)
fun_args <- c(fun_args, dots)
params <- do.call("bootstrap_parameters", fun_args)
out <- tryCatch(
{
# ==== 1. first step, extracting (bootstrapped) model parameters -------

# Processing, bootstrapped parameters
if (bootstrap) {
# set default method for bootstrapped CI
if (is.null(ci_method) || missing(ci_method)) {
ci_method <- "quantile"
}

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

# Processing, non-bootstrapped parameters
} else {
# set default method for CI
if (is.null(ci_method) || missing(ci_method)) {
ci_method <- "wald"
}

fun_args <- list(
model,
ci = ci,
component = component,
merge_by = merge_by,
standardize = standardize,
effects = effects,
ci_method = ci_method,
p_adjust = p_adjust,
keep_parameters = keep_parameters,
drop_parameters = drop_parameters,
verbose = verbose,
vcov = vcov,
vcov_args = vcov_args
)
fun_args <- c(fun_args, dots)
params <- do.call(".extract_parameters_generic", fun_args)
}


# ==== 2. second step, exponentiate -------

# exponentiate coefficients and SE/CI, if requested
params <- .exponentiate_parameters(params, model, exponentiate)


# ==== 3. third step, add information as attributes -------

# add further information as attributes
params <- .add_model_parameters_attributes(
params,
model,
ci,
exponentiate,
bootstrap,
iterations,
ci_method = ci_method,
p_adjust = p_adjust,
include_info = include_info,
verbose = verbose,
...
)

# Processing, non-bootstrapped parameters
} else {
# set default method for CI
if (is.null(ci_method) || missing(ci_method)) {
ci_method <- "wald"
class(params) <- c("parameters_model", "see_parameters_model", class(params))
params
},
error = function(e) {
fail <- NA
attr(fail, "error") <- gsub(" ", " ", gsub("\\n", "", e$message), fixed = TRUE)
fail
}

fun_args <- list(
model,
ci = ci,
component = component,
merge_by = merge_by,
standardize = standardize,
effects = effects,
ci_method = ci_method,
p_adjust = p_adjust,
keep_parameters = keep_parameters,
drop_parameters = drop_parameters,
verbose = verbose,
vcov = vcov,
vcov_args = vcov_args
)
fun_args <- c(fun_args, dots)
params <- do.call(".extract_parameters_generic", fun_args)
}


# ==== 2. second step, exponentiate -------

# exponentiate coefficients and SE/CI, if requested
params <- .exponentiate_parameters(params, model, exponentiate)


# ==== 3. third step, add information as attributes -------

# add further information as attributes
params <- .add_model_parameters_attributes(
params,
model,
ci,
exponentiate,
bootstrap,
iterations,
ci_method = ci_method,
p_adjust = p_adjust,
include_info = include_info,
verbose = verbose,
...
)

class(params) <- c("parameters_model", "see_parameters_model", class(params))
params
}

# check if everything is ok
.fail_error_message(out, model)

out
}


#################### .glm ----------------------
Expand Down
6 changes: 0 additions & 6 deletions R/4_standard_error.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ standard_error <- function(model, ...) {
}



# Default methods ---------------------------------------------------------

#' @rdname standard_error
Expand Down Expand Up @@ -160,8 +159,6 @@ standard_error.default <- function(model,
}




# helper -----------------------------------------------------------------


Expand Down Expand Up @@ -192,15 +189,12 @@ standard_error.default <- function(model,
}



.check_vcov_args <- function(robust, ...) {
dots <- list(...)
isTRUE(isTRUE(robust) || isTRUE(dots$robust) || ("vcov" %in% names(dots) && !is.null(dots[["vcov"]])))
}




# .ranef_se <- function(x) {
# insight::check_if_installed("lme4")
#
Expand Down
5 changes: 0 additions & 5 deletions R/5_simulate_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
}



# Models with single component only -----------------------------------------

#' @rdname simulate_model
Expand Down Expand Up @@ -224,10 +223,6 @@
simulate_model.bracl <- simulate_model.default






# helper -----------------------------------------


Expand Down Expand Up @@ -258,7 +253,7 @@
# }
}

.mvrnorm <- function(n = 1, mu, Sigma, tol = 1e-06) {

Check warning on line 256 in R/5_simulate_model.R

View workflow job for this annotation

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

file=R/5_simulate_model.R,line=256,col=29,[function_argument_linter] Arguments without defaults should come before arguments with defaults.

Check warning on line 256 in R/5_simulate_model.R

View workflow job for this annotation

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

file=R/5_simulate_model.R,line=256,col=33,[function_argument_linter] Arguments without defaults should come before arguments with defaults.

Check warning on line 256 in R/5_simulate_model.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/5_simulate_model.R,line=256,col=29,[function_argument_linter] Arguments without defaults should come before arguments with defaults.

Check warning on line 256 in R/5_simulate_model.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/5_simulate_model.R,line=256,col=33,[function_argument_linter] Arguments without defaults should come before arguments with defaults.
p <- length(mu)
if (!all(dim(Sigma) == c(p, p))) {
insight::format_error(
Expand Down
4 changes: 0 additions & 4 deletions R/bootstrap_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ bootstrap_model <- function(model,
}






#' @rdname bootstrap_model
#' @export
bootstrap_model.default <- function(model,
Expand Down
1 change: 0 additions & 1 deletion R/ci_kenward.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
}



.ci_kenward_dof <- function(model, ci = 0.95, df_kr) {

Check warning on line 23 in R/ci_kenward.R

View workflow job for this annotation

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

file=R/ci_kenward.R,line=23,col=47,[function_argument_linter] Arguments without defaults should come before arguments with defaults.

Check warning on line 23 in R/ci_kenward.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/ci_kenward.R,line=23,col=47,[function_argument_linter] Arguments without defaults should come before arguments with defaults.
out <- lapply(ci, function(i) {
.ci_dof(
model = model,
Expand Down
3 changes: 0 additions & 3 deletions R/ci_profile_boot.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
}



# we need this function for models where confint and get_parameters return
# different length (e.g. as for "polr" models)
.ci_profiled2 <- function(model, ci) {
Expand Down Expand Up @@ -98,7 +97,6 @@
}



#' @keywords internal
.ci_uniroot_glmmTMB <- function(x, ci, component, ...) {
# make sure "..." doesn't pass invalid arguments to package TMB
Expand Down Expand Up @@ -157,7 +155,6 @@
}



#' @keywords internal
.ci_boot_merMod <- function(x, ci, iterations = 500, effects = "fixed", ...) {
insight::check_if_installed("lme4")
Expand Down
3 changes: 0 additions & 3 deletions R/cluster_analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ cluster_analysis <- function(x,
}



# Apply clustering --------------------------------------------------------


Expand Down Expand Up @@ -286,7 +285,6 @@ cluster_analysis <- function(x,
}



# Clustering Methods --------------------------------------------------------

#' @keywords internal
Expand Down Expand Up @@ -406,7 +404,6 @@ cluster_analysis <- function(x,
}



# Methods ----------------------------------------------------------------

#' @export
Expand Down
1 change: 0 additions & 1 deletion R/cluster_discrimination.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ cluster_discrimination.cluster_analysis <- function(x, cluster_groups = NULL, ..
}



#' @export
cluster_discrimination.default <- function(x, cluster_groups = NULL, ...) {
if (is.null(cluster_groups)) {
Expand Down
Loading
Loading