Skip to content

Commit f57f0b1

Browse files
authored
parameters.fixest: Uninformative error (#1055)
* `parameters.fixest`: Uninformative error Fixes #1054 * fix standard_error.fixest, add test * Update DESCRIPTION * styler * update snapshots * update vignette * styler * lintr * lintr
1 parent 1fb5413 commit f57f0b1

File tree

100 files changed

+258
-703
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+258
-703
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: parameters
33
Title: Processing of Model Parameters
4-
Version: 0.24.0.4
4+
Version: 0.24.0.5
55
Authors@R:
66
c(person(given = "Daniel",
77
family = "Lüdecke",
@@ -224,4 +224,4 @@ Config/testthat/edition: 3
224224
Config/testthat/parallel: true
225225
Config/Needs/website: easystats/easystatstemplate
226226
Config/rcmdcheck/ignore-inconsequential-notes: true
227-
Remotes: easystats/datawizard, easystats/performance
227+
Remotes: easystats/insight, easystats/datawizard, easystats/performance

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# parameters 0.24.1
22

3+
## Changes
4+
5+
* `model_parameters()` now gives informative error messages for more model
6+
classes than before when the function fails to extract model parameters.
7+
38
## Bug fixes
49

510
* Fixed issue when printing `model_parameters()` with models from `mgcv::gam()`.

R/1_model_parameters.R

Lines changed: 103 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -605,32 +605,31 @@ model_parameters.default <- function(model,
605605
)
606606

607607
# extract model parameters table, as data frame
608-
out <- tryCatch(
609-
.model_parameters_generic(
610-
model = model,
611-
ci = ci,
612-
ci_method = ci_method,
613-
bootstrap = bootstrap,
614-
iterations = iterations,
615-
merge_by = "Parameter",
616-
standardize = standardize,
617-
exponentiate = exponentiate,
618-
p_adjust = p_adjust,
619-
include_info = include_info,
620-
keep_parameters = keep,
621-
drop_parameters = drop,
622-
vcov = vcov,
623-
vcov_args = vcov_args,
624-
verbose = verbose,
625-
...
626-
),
627-
error = function(e) {
628-
fail <- NA
629-
attr(fail, "error") <- gsub(" ", " ", gsub("\\n", "", e$message), fixed = TRUE)
630-
fail
631-
}
608+
out <- .model_parameters_generic(
609+
model = model,
610+
ci = ci,
611+
ci_method = ci_method,
612+
bootstrap = bootstrap,
613+
iterations = iterations,
614+
merge_by = "Parameter",
615+
standardize = standardize,
616+
exponentiate = exponentiate,
617+
p_adjust = p_adjust,
618+
include_info = include_info,
619+
keep_parameters = keep,
620+
drop_parameters = drop,
621+
vcov = vcov,
622+
vcov_args = vcov_args,
623+
verbose = verbose,
624+
...
632625
)
633626

627+
attr(out, "object_name") <- insight::safe_deparse_symbol(substitute(model))
628+
out
629+
}
630+
631+
632+
.fail_error_message <- function(out, model) {
634633
# tell user if something went wrong...
635634
if (length(out) == 1 && isTRUE(is.na(out))) {
636635
insight::format_error(
@@ -650,14 +649,9 @@ model_parameters.default <- function(model,
650649
)
651650
)
652651
}
653-
654-
attr(out, "object_name") <- insight::safe_deparse_symbol(substitute(model))
655-
out
656652
}
657653

658654

659-
660-
661655
# helper function for the composition of the parameters table,
662656
# including a bunch of attributes required for further processing
663657
# (like printing etc.)
@@ -682,79 +676,91 @@ model_parameters.default <- function(model,
682676
...) {
683677
dots <- list(...)
684678

685-
# ==== 1. first step, extracting (bootstrapped) model parameters -------
686-
687-
# Processing, bootstrapped parameters
688-
if (bootstrap) {
689-
# set default method for bootstrapped CI
690-
if (is.null(ci_method) || missing(ci_method)) {
691-
ci_method <- "quantile"
692-
}
693-
694-
fun_args <- list(
695-
model,
696-
iterations = iterations,
697-
ci = ci,
698-
ci_method = ci_method
699-
)
700-
fun_args <- c(fun_args, dots)
701-
params <- do.call("bootstrap_parameters", fun_args)
679+
out <- tryCatch(
680+
{
681+
# ==== 1. first step, extracting (bootstrapped) model parameters -------
682+
683+
# Processing, bootstrapped parameters
684+
if (bootstrap) {
685+
# set default method for bootstrapped CI
686+
if (is.null(ci_method) || missing(ci_method)) {
687+
ci_method <- "quantile"
688+
}
689+
690+
fun_args <- list(
691+
model,
692+
iterations = iterations,
693+
ci = ci,
694+
ci_method = ci_method
695+
)
696+
fun_args <- c(fun_args, dots)
697+
params <- do.call("bootstrap_parameters", fun_args)
698+
699+
# Processing, non-bootstrapped parameters
700+
} else {
701+
# set default method for CI
702+
if (is.null(ci_method) || missing(ci_method)) {
703+
ci_method <- "wald"
704+
}
705+
706+
fun_args <- list(
707+
model,
708+
ci = ci,
709+
component = component,
710+
merge_by = merge_by,
711+
standardize = standardize,
712+
effects = effects,
713+
ci_method = ci_method,
714+
p_adjust = p_adjust,
715+
keep_parameters = keep_parameters,
716+
drop_parameters = drop_parameters,
717+
verbose = verbose,
718+
vcov = vcov,
719+
vcov_args = vcov_args
720+
)
721+
fun_args <- c(fun_args, dots)
722+
params <- do.call(".extract_parameters_generic", fun_args)
723+
}
724+
725+
726+
# ==== 2. second step, exponentiate -------
727+
728+
# exponentiate coefficients and SE/CI, if requested
729+
params <- .exponentiate_parameters(params, model, exponentiate)
730+
731+
732+
# ==== 3. third step, add information as attributes -------
733+
734+
# add further information as attributes
735+
params <- .add_model_parameters_attributes(
736+
params,
737+
model,
738+
ci,
739+
exponentiate,
740+
bootstrap,
741+
iterations,
742+
ci_method = ci_method,
743+
p_adjust = p_adjust,
744+
include_info = include_info,
745+
verbose = verbose,
746+
...
747+
)
702748

703-
# Processing, non-bootstrapped parameters
704-
} else {
705-
# set default method for CI
706-
if (is.null(ci_method) || missing(ci_method)) {
707-
ci_method <- "wald"
749+
class(params) <- c("parameters_model", "see_parameters_model", class(params))
750+
params
751+
},
752+
error = function(e) {
753+
fail <- NA
754+
attr(fail, "error") <- gsub(" ", " ", gsub("\\n", "", e$message), fixed = TRUE)
755+
fail
708756
}
709-
710-
fun_args <- list(
711-
model,
712-
ci = ci,
713-
component = component,
714-
merge_by = merge_by,
715-
standardize = standardize,
716-
effects = effects,
717-
ci_method = ci_method,
718-
p_adjust = p_adjust,
719-
keep_parameters = keep_parameters,
720-
drop_parameters = drop_parameters,
721-
verbose = verbose,
722-
vcov = vcov,
723-
vcov_args = vcov_args
724-
)
725-
fun_args <- c(fun_args, dots)
726-
params <- do.call(".extract_parameters_generic", fun_args)
727-
}
728-
729-
730-
# ==== 2. second step, exponentiate -------
731-
732-
# exponentiate coefficients and SE/CI, if requested
733-
params <- .exponentiate_parameters(params, model, exponentiate)
734-
735-
736-
# ==== 3. third step, add information as attributes -------
737-
738-
# add further information as attributes
739-
params <- .add_model_parameters_attributes(
740-
params,
741-
model,
742-
ci,
743-
exponentiate,
744-
bootstrap,
745-
iterations,
746-
ci_method = ci_method,
747-
p_adjust = p_adjust,
748-
include_info = include_info,
749-
verbose = verbose,
750-
...
751757
)
752758

753-
class(params) <- c("parameters_model", "see_parameters_model", class(params))
754-
params
755-
}
756-
759+
# check if everything is ok
760+
.fail_error_message(out, model)
757761

762+
out
763+
}
758764

759765

760766
#################### .glm ----------------------

R/4_standard_error.R

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ standard_error <- function(model, ...) {
7070
}
7171

7272

73-
7473
# Default methods ---------------------------------------------------------
7574

7675
#' @rdname standard_error
@@ -160,8 +159,6 @@ standard_error.default <- function(model,
160159
}
161160

162161

163-
164-
165162
# helper -----------------------------------------------------------------
166163

167164

@@ -192,15 +189,12 @@ standard_error.default <- function(model,
192189
}
193190

194191

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

201197

202-
203-
204198
# .ranef_se <- function(x) {
205199
# insight::check_if_installed("lme4")
206200
#

R/5_simulate_model.R

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ simulate_model <- function(model, iterations = 1000, ...) {
5656
}
5757

5858

59-
6059
# Models with single component only -----------------------------------------
6160

6261
#' @rdname simulate_model
@@ -224,10 +223,6 @@ simulate_model.brmultinom <- simulate_model.default
224223
simulate_model.bracl <- simulate_model.default
225224

226225

227-
228-
229-
230-
231226
# helper -----------------------------------------
232227

233228

R/bootstrap_model.R

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ bootstrap_model <- function(model,
5757
}
5858

5959

60-
61-
62-
63-
6460
#' @rdname bootstrap_model
6561
#' @export
6662
bootstrap_model.default <- function(model,

R/ci_kenward.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ ci_kenward <- function(model, ci = 0.95) {
2020
}
2121

2222

23-
2423
.ci_kenward_dof <- function(model, ci = 0.95, df_kr) {
2524
out <- lapply(ci, function(i) {
2625
.ci_dof(

R/ci_profile_boot.R

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
}
3333

3434

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

10099

101-
102100
#' @keywords internal
103101
.ci_uniroot_glmmTMB <- function(x, ci, component, ...) {
104102
# make sure "..." doesn't pass invalid arguments to package TMB
@@ -157,7 +155,6 @@
157155
}
158156

159157

160-
161158
#' @keywords internal
162159
.ci_boot_merMod <- function(x, ci, iterations = 500, effects = "fixed", ...) {
163160
insight::check_if_installed("lme4")

R/cluster_analysis.R

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ cluster_analysis <- function(x,
197197
}
198198

199199

200-
201200
# Apply clustering --------------------------------------------------------
202201

203202

@@ -286,7 +285,6 @@ cluster_analysis <- function(x,
286285
}
287286

288287

289-
290288
# Clustering Methods --------------------------------------------------------
291289

292290
#' @keywords internal
@@ -406,7 +404,6 @@ cluster_analysis <- function(x,
406404
}
407405

408406

409-
410407
# Methods ----------------------------------------------------------------
411408

412409
#' @export

R/cluster_discrimination.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ cluster_discrimination.cluster_analysis <- function(x, cluster_groups = NULL, ..
3434
}
3535

3636

37-
3837
#' @export
3938
cluster_discrimination.default <- function(x, cluster_groups = NULL, ...) {
4039
if (is.null(cluster_groups)) {

0 commit comments

Comments
 (0)