Skip to content

Commit 2d04732

Browse files
authored
Support for svyolr (#1173)
* Support for svyolr * tests * Update DESCRIPTION * typo
1 parent 129f35b commit 2d04732

File tree

10 files changed

+657
-388
lines changed

10 files changed

+657
-388
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
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.28.2.5
4+
Version: 0.28.2.7
55
Authors@R:
66
c(person(given = "Daniel",
77
family = "Lüdecke",

NAMESPACE

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,11 @@ S3method(model_parameters,draws)
243243
S3method(model_parameters,emmGrid)
244244
S3method(model_parameters,emm_list)
245245
S3method(model_parameters,epi.2by2)
246-
S3method(model_parameters,externVar)
247-
S3method(model_parameters,externX)
248246
S3method(model_parameters,estimate_contrasts)
249247
S3method(model_parameters,estimate_means)
250248
S3method(model_parameters,estimate_slopes)
249+
S3method(model_parameters,externVar)
250+
S3method(model_parameters,externX)
251251
S3method(model_parameters,fa)
252252
S3method(model_parameters,fa.ci)
253253
S3method(model_parameters,feglm)
@@ -360,6 +360,7 @@ S3method(model_parameters,summary_emm)
360360
S3method(model_parameters,survfit)
361361
S3method(model_parameters,svy2lme)
362362
S3method(model_parameters,svyglm)
363+
S3method(model_parameters,svyolr)
363364
S3method(model_parameters,svytable)
364365
S3method(model_parameters,systemfit)
365366
S3method(model_parameters,t1way)
@@ -803,11 +804,11 @@ S3method(standard_error,draws)
803804
S3method(standard_error,effectsize_table)
804805
S3method(standard_error,emmGrid)
805806
S3method(standard_error,emm_list)
806-
S3method(standard_error,externVar)
807-
S3method(standard_error,externX)
808807
S3method(standard_error,estimate_contrasts)
809808
S3method(standard_error,estimate_means)
810809
S3method(standard_error,estimate_slopes)
810+
S3method(standard_error,externVar)
811+
S3method(standard_error,externX)
811812
S3method(standard_error,factor)
812813
S3method(standard_error,feglm)
813814
S3method(standard_error,fitdistr)

R/1_model_parameters.R

Lines changed: 66 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -396,15 +396,13 @@ model_parameters <- function(model, ...) {
396396

397397
# DF naming convention --------------------
398398

399-
400399
# DF column naming
401400
# F has df, df_error
402401
# t has df_error
403402
# z has df_error = Inf
404403
# Chisq has df
405404
# https://github.com/easystats/parameters/issues/455
406405

407-
408406
# Options -------------------------------------
409407

410408
# Add new options to the docs in "print.parameters_model"
@@ -417,7 +415,6 @@ model_parameters <- function(model, ...) {
417415
# getOption("parameters_interaction"): separator char for interactions
418416
# getOption("parameters_select"): default for the `select` argument
419417

420-
421418
#' @rdname model_parameters
422419
#' @export
423420
parameters <- model_parameters
@@ -578,21 +575,23 @@ parameters <- model_parameters
578575
#' }
579576
#' @return A data frame of indices related to the model's parameters.
580577
#' @export
581-
model_parameters.default <- function(model,
582-
ci = 0.95,
583-
ci_method = NULL,
584-
bootstrap = FALSE,
585-
iterations = 1000,
586-
standardize = NULL,
587-
exponentiate = FALSE,
588-
p_adjust = NULL,
589-
vcov = NULL,
590-
vcov_args = NULL,
591-
include_info = getOption("parameters_info", FALSE),
592-
keep = NULL,
593-
drop = NULL,
594-
verbose = TRUE,
595-
...) {
578+
model_parameters.default <- function(
579+
model,
580+
ci = 0.95,
581+
ci_method = NULL,
582+
bootstrap = FALSE,
583+
iterations = 1000,
584+
standardize = NULL,
585+
exponentiate = FALSE,
586+
p_adjust = NULL,
587+
vcov = NULL,
588+
vcov_args = NULL,
589+
include_info = getOption("parameters_info", FALSE),
590+
keep = NULL,
591+
drop = NULL,
592+
verbose = TRUE,
593+
...
594+
) {
596595
# validation check for inputs
597596
.is_model_valid(model)
598597

@@ -642,13 +641,11 @@ model_parameters.default <- function(model,
642641
attr(out, "error")
643642
)
644643
} else if (is.null(out)) {
645-
insight::format_error(
646-
paste0(
647-
"Sorry, `model_parameters()` does not currently work for objects of class `",
648-
class(model)[1],
649-
"`."
650-
)
651-
)
644+
insight::format_error(paste0(
645+
"Sorry, `model_parameters()` does not currently work for objects of class `",
646+
class(model)[1],
647+
"`."
648+
))
652649
}
653650
}
654651

@@ -657,24 +654,26 @@ model_parameters.default <- function(model,
657654
# including a bunch of attributes required for further processing
658655
# (like printing etc.)
659656

660-
.model_parameters_generic <- function(model,
661-
ci = 0.95,
662-
bootstrap = FALSE,
663-
iterations = 1000,
664-
merge_by = "Parameter",
665-
standardize = NULL,
666-
exponentiate = FALSE,
667-
effects = "fixed",
668-
component = "conditional",
669-
ci_method = NULL,
670-
p_adjust = NULL,
671-
include_info = FALSE,
672-
keep_parameters = NULL,
673-
drop_parameters = NULL,
674-
vcov = NULL,
675-
vcov_args = NULL,
676-
verbose = TRUE,
677-
...) {
657+
.model_parameters_generic <- function(
658+
model,
659+
ci = 0.95,
660+
bootstrap = FALSE,
661+
iterations = 1000,
662+
merge_by = "Parameter",
663+
standardize = NULL,
664+
exponentiate = FALSE,
665+
effects = "fixed",
666+
component = "conditional",
667+
ci_method = NULL,
668+
p_adjust = NULL,
669+
include_info = FALSE,
670+
keep_parameters = NULL,
671+
drop_parameters = NULL,
672+
vcov = NULL,
673+
vcov_args = NULL,
674+
verbose = TRUE,
675+
...
676+
) {
678677
dots <- list(...)
679678

680679
out <- tryCatch(
@@ -688,12 +687,7 @@ model_parameters.default <- function(model,
688687
ci_method <- "quantile"
689688
}
690689

691-
fun_args <- list(
692-
model,
693-
iterations = iterations,
694-
ci = ci,
695-
ci_method = ci_method
696-
)
690+
fun_args <- list(model, iterations = iterations, ci = ci, ci_method = ci_method)
697691
fun_args <- c(fun_args, dots)
698692
params <- do.call("bootstrap_parameters", fun_args)
699693

@@ -723,13 +717,11 @@ model_parameters.default <- function(model,
723717
params <- do.call(".extract_parameters_generic", fun_args)
724718
}
725719

726-
727720
# ==== 2. second step, exponentiate -------
728721

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

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

735727
# add further information as attributes
@@ -766,30 +758,31 @@ model_parameters.default <- function(model,
766758

767759
#################### .glm ----------------------
768760

769-
770761
#' @export
771-
model_parameters.glm <- function(model,
772-
ci = 0.95,
773-
ci_method = NULL,
774-
bootstrap = FALSE,
775-
iterations = 1000,
776-
standardize = NULL,
777-
exponentiate = FALSE,
778-
p_adjust = NULL,
779-
vcov = NULL,
780-
vcov_args = NULL,
781-
include_info = getOption("parameters_info", FALSE),
782-
keep = NULL,
783-
drop = NULL,
784-
verbose = TRUE,
785-
...) {
762+
model_parameters.glm <- function(
763+
model,
764+
ci = 0.95,
765+
ci_method = NULL,
766+
bootstrap = FALSE,
767+
iterations = 1000,
768+
standardize = NULL,
769+
exponentiate = FALSE,
770+
p_adjust = NULL,
771+
vcov = NULL,
772+
vcov_args = NULL,
773+
include_info = getOption("parameters_info", FALSE),
774+
keep = NULL,
775+
drop = NULL,
776+
verbose = TRUE,
777+
...
778+
) {
786779
dots <- list(...)
787780

788781
# set default
789782
if (is.null(ci_method)) {
790783
if (isTRUE(bootstrap)) {
791784
ci_method <- "quantile"
792-
} else if (!is.null(vcov) || !is.null(vcov_args)) {
785+
} else if (!is.null(vcov) || !is.null(vcov_args) || inherits(model, "svyolr")) {
793786
ci_method <- "wald"
794787
} else {
795788
ci_method <- "profile"
@@ -805,7 +798,11 @@ model_parameters.glm <- function(model,
805798
}
806799

807800
# tell user that profiled CIs don't respect vcov-args
808-
if (identical(ci_method, "profile") && (!is.null(vcov) || !is.null(vcov_args)) && isTRUE(verbose)) {
801+
if (
802+
identical(ci_method, "profile") &&
803+
(!is.null(vcov) || !is.null(vcov_args)) &&
804+
isTRUE(verbose)
805+
) {
809806
insight::format_alert(
810807
"When `ci_method=\"profile\"`, `vcov` only modifies standard errors, test-statistic and p-values, but not confidence intervals.", # nolint
811808
"Use `ci_method=\"wald\"` to return confidence intervals based on robust standard errors."

R/dof.R

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ dof <- degrees_of_freedom
8080
method <- tolower(method)
8181

8282
# exceptions 1
83-
if (inherits(model, c("polr", "glm", "svyglm"))) {
83+
if (inherits(model, c("polr", "glm", "svyglm", "svyolr"))) {
84+
# fmt: skip
8485
if (method %in% c(
8586
"analytical", "any", "fit", "profile", "residual",
8687
"wald", "nokr", "likelihood", "normal"
@@ -96,11 +97,17 @@ dof <- degrees_of_freedom
9697

9798
# exceptions 2
9899
if (inherits(model, c("phylolm", "phyloglm"))) {
99-
if (method %in% c("analytical", "any", "fit", "residual", "wald", "nokr", "normal", "boot")) {
100+
if (
101+
method %in%
102+
c("analytical", "any", "fit", "residual", "wald", "nokr", "normal", "boot")
103+
) {
100104
return(TRUE)
101105
} else {
102106
if (verbose) {
103-
insight::format_alert(sprintf("`%s` must be one of \"wald\", \"normal\" or \"boot\". Using \"wald\" now.", type)) # nolint
107+
insight::format_alert(sprintf(
108+
"`%s` must be one of \"wald\", \"normal\" or \"boot\". Using \"wald\" now.",
109+
type
110+
))
104111
}
105112
return(FALSE)
106113
}
@@ -109,31 +116,52 @@ dof <- degrees_of_freedom
109116
info <- insight::model_info(model, verbose = FALSE)
110117
if (!is.null(info) && isFALSE(info$is_mixed) && method == "boot") {
111118
if (verbose) {
112-
insight::format_alert(sprintf("`%s=boot` only works for mixed models of class `merMod`. To bootstrap this model, use `bootstrap=TRUE, ci_method=\"bcai\"`.", type)) # nolint
119+
insight::format_alert(sprintf(
120+
"`%s=boot` only works for mixed models of class `merMod`. To bootstrap this model, use `bootstrap=TRUE, ci_method=\"bcai\"`.",
121+
type
122+
))
113123
}
114124
return(TRUE)
115125
}
116126

127+
# fmt: skip
117128
if (is.null(info) || !info$is_mixed) {
118-
if (!(method %in% c("analytical", "any", "fit", "betwithin", "nokr", "wald", "ml1", "profile", "boot", "uniroot", "residual", "normal"))) { # nolint
129+
if (!(method %in% c(
130+
"analytical", "any", "fit", "betwithin", "nokr", "wald", "ml1",
131+
"profile", "boot", "uniroot", "residual", "normal"
132+
))) {
119133
if (verbose) {
120-
insight::format_alert(sprintf("`%s` must be one of \"residual\", \"wald\", \"normal\", \"profile\", \"boot\", \"uniroot\", \"betwithin\" or \"ml1\". Using \"wald\" now.", type)) # nolint
134+
insight::format_alert(sprintf(
135+
"`%s` must be one of \"residual\", \"wald\", \"normal\", \"profile\", \"boot\", \"uniroot\", \"betwithin\" or \"ml1\". Using \"wald\" now.",
136+
type
137+
))
121138
}
122139
return(FALSE)
123140
}
124141
return(TRUE)
125142
}
126143

127-
if (!(method %in% c("analytical", "any", "fit", "satterthwaite", "betwithin", "kenward", "kr", "nokr", "wald", "ml1", "profile", "boot", "uniroot", "residual", "normal"))) { # nolint
144+
# fmt: skip
145+
if (!(method %in% c(
146+
"analytical", "any", "fit", "satterthwaite", "betwithin", "kenward",
147+
"kr", "nokr", "wald", "ml1", "profile", "boot", "uniroot", "residual",
148+
"normal"
149+
))) {
128150
if (verbose) {
129-
insight::format_alert(sprintf("`%s` must be one of \"residual\", \"wald\", \"normal\", \"profile\", \"boot\", \"uniroot\", \"kenward\", \"satterthwaite\", \"betwithin\" or \"ml1\". Using \"wald\" now.", type)) # nolint
151+
insight::format_alert(sprintf(
152+
"`%s` must be one of \"residual\", \"wald\", \"normal\", \"profile\", \"boot\", \"uniroot\", \"kenward\", \"satterthwaite\", \"betwithin\" or \"ml1\". Using \"wald\" now.",
153+
type
154+
))
130155
}
131156
return(FALSE)
132-
}
157+
}
133158

134159
if (!info$is_linear && method %in% c("satterthwaite", "kenward", "kr")) {
135160
if (verbose) {
136-
insight::format_alert(sprintf("`%s`-degrees of freedoms are only available for linear mixed models.", method))
161+
insight::format_alert(sprintf(
162+
"`%s`-degrees of freedoms are only available for linear mixed models.",
163+
method
164+
))
137165
}
138166
return(FALSE)
139167
}

0 commit comments

Comments
 (0)