Skip to content

Commit bcfc470

Browse files
authored
Style with air (#862)
1 parent 4e85784 commit bcfc470

File tree

171 files changed

+4885
-1696
lines changed

Some content is hidden

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

171 files changed

+4885
-1696
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ Suggests:
159159
withr (>= 3.0.0)
160160
Encoding: UTF-8
161161
Language: en-US
162-
RoxygenNote: 7.3.2
162+
RoxygenNote: 7.3.3
163163
Roxygen: list(markdown = TRUE)
164164
Config/testthat/edition: 3
165165
Config/testthat/parallel: true

R/binned_residuals.R

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,18 @@
7575
#' }
7676
#'
7777
#' @export
78-
binned_residuals <- function(model,
79-
term = NULL,
80-
n_bins = NULL,
81-
show_dots = NULL,
82-
ci = 0.95,
83-
ci_type = "exact",
84-
residuals = "deviance",
85-
iterations = 1000,
86-
verbose = TRUE,
87-
...) {
78+
binned_residuals <- function(
79+
model,
80+
term = NULL,
81+
n_bins = NULL,
82+
show_dots = NULL,
83+
ci = 0.95,
84+
ci_type = "exact",
85+
residuals = "deviance",
86+
iterations = 1000,
87+
verbose = TRUE,
88+
...
89+
) {
8890
ci_type <- insight::validate_argument(
8991
ci_type,
9092
c("exact", "gaussian", "boot")
@@ -98,7 +100,9 @@ binned_residuals <- function(model,
98100
if (isFALSE(insight::model_info(model)$is_bernoulli)) {
99101
ci_type <- "gaussian"
100102
if (verbose) {
101-
insight::format_alert("Using `ci_type = \"gaussian\"` because model is not bernoulli.")
103+
insight::format_alert(
104+
"Using `ci_type = \"gaussian\"` because model is not bernoulli."
105+
)
102106
}
103107
}
104108

@@ -121,18 +125,23 @@ binned_residuals <- function(model,
121125
y0 <- .recode_to_zero(insight::get_response(model, verbose = FALSE))
122126

123127
# calculate residuals
124-
y <- switch(residuals,
128+
y <- switch(
129+
residuals,
125130
response = y0 - fitted_values,
126131
pearson = .safe((y0 - fitted_values) / sqrt(fitted_values * (1 - fitted_values))),
127132
deviance = .safe(stats::residuals(model, type = "deviance"))
128133
)
129134

130135
# make sure we really have residuals
131136
if (is.null(y)) {
132-
insight::format_error("Could not calculate residuals. Try using `residuals = \"response\"`.")
137+
insight::format_error(
138+
"Could not calculate residuals. Try using `residuals = \"response\"`."
139+
)
133140
}
134141

135-
if (is.null(n_bins)) n_bins <- round(sqrt(length(pred)))
142+
if (is.null(n_bins)) {
143+
n_bins <- round(sqrt(length(pred)))
144+
}
136145

137146
breaks.index <- floor(length(pred) * (1:(n_bins - 1)) / n_bins)
138147
breaks <- unique(c(-Inf, sort(pred)[breaks.index], Inf))
@@ -151,8 +160,13 @@ binned_residuals <- function(model,
151160
if (n == 0) {
152161
conf_int <- stats::setNames(c(NA, NA), c("CI_low", "CI_high"))
153162
} else {
154-
conf_int <- switch(ci_type,
155-
gaussian = stats::qnorm(c((1 - ci) / 2, (1 + ci) / 2), mean = ybar, sd = sdev / sqrt(n)),
163+
conf_int <- switch(
164+
ci_type,
165+
gaussian = stats::qnorm(
166+
c((1 - ci) / 2, (1 + ci) / 2),
167+
mean = ybar,
168+
sd = sdev / sqrt(n)
169+
),
156170
exact = {
157171
out <- stats::binom.test(sum(y0[items]), n)$conf.int
158172
# center CIs around point estimate

R/check_autocorrelation.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ check_autocorrelation.default <- function(x, nsim = 1000, ...) {
5353

5454
#' @export
5555
plot.check_autocorrelation <- function(x, ...) {
56-
insight::format_warning("There is currently no `plot()` method for `check_autocorrelation()`.")
56+
insight::format_warning(
57+
"There is currently no `plot()` method for `check_autocorrelation()`."
58+
)
5759
}
5860

5961

R/check_clusterstructure.R

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@
3737
#' assessment of (cluster) tendency. In Proceedings of the 2002 International
3838
#' Joint Conference on Neural Networks. IJCNN02 (3), 2225-2230. IEEE.
3939
#' @export
40-
check_clusterstructure <- function(x,
41-
standardize = TRUE,
42-
distance = "euclidean",
43-
...) {
40+
check_clusterstructure <- function(x, standardize = TRUE, distance = "euclidean", ...) {
4441
if (standardize) {
4542
x <- as.data.frame(scale(x))
4643
}
@@ -64,13 +61,22 @@ check_clusterstructure <- function(x,
6461

6562
out <- list(
6663
H = H,
67-
dissimilarity_matrix = .clusterstructure_dm(x, distance = distance, method = "ward.D2")
64+
dissimilarity_matrix = .clusterstructure_dm(
65+
x,
66+
distance = distance,
67+
method = "ward.D2"
68+
)
6869
)
6970

7071
attr(out, "text") <- res_text
7172
attr(out, "color") <- color
7273
attr(out, "title") <- "Clustering tendency"
73-
class(out) <- c("see_check_clusterstructure", "check_clusterstructure", "easystats_check", class(out))
74+
class(out) <- c(
75+
"see_check_clusterstructure",
76+
"check_clusterstructure",
77+
"easystats_check",
78+
class(out)
79+
)
7480
out
7581
}
7682

@@ -80,8 +86,10 @@ plot.check_clusterstructure <- function(x, ...) {
8086
# Can be reimplemented with ggplot in see
8187
stats::heatmap(
8288
x$dissimilarity_matrix,
83-
Rowv = NA, Colv = NA,
84-
labRow = FALSE, labCol = FALSE,
89+
Rowv = NA,
90+
Colv = NA,
91+
labRow = FALSE,
92+
labCol = FALSE,
8593
col = grDevices::colorRampPalette(c("#2196F3", "#FAFAFA", "#E91E63"))(100)
8694
)
8795
}

R/check_collinearity.R

Lines changed: 71 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,13 @@ check_collinearity.betamfx <- check_collinearity.logitor
313313

314314
#' @rdname check_collinearity
315315
#' @export
316-
check_collinearity.glmmTMB <- function(x,
317-
component = "all",
318-
ci = 0.95,
319-
verbose = TRUE,
320-
...) {
316+
check_collinearity.glmmTMB <- function(
317+
x,
318+
component = "all",
319+
ci = 0.95,
320+
verbose = TRUE,
321+
...
322+
) {
321323
component <- insight::validate_argument(
322324
component,
323325
c("all", "conditional", "count", "zi", "zero_inflated")
@@ -327,11 +329,13 @@ check_collinearity.glmmTMB <- function(x,
327329

328330

329331
#' @export
330-
check_collinearity.MixMod <- function(x,
331-
component = "all",
332-
ci = 0.95,
333-
verbose = TRUE,
334-
...) {
332+
check_collinearity.MixMod <- function(
333+
x,
334+
component = "all",
335+
ci = 0.95,
336+
verbose = TRUE,
337+
...
338+
) {
335339
component <- insight::validate_argument(
336340
component,
337341
c("all", "conditional", "count", "zi", "zero_inflated")
@@ -341,11 +345,13 @@ check_collinearity.MixMod <- function(x,
341345

342346

343347
#' @export
344-
check_collinearity.hurdle <- function(x,
345-
component = "all",
346-
ci = 0.95,
347-
verbose = verbose,
348-
...) {
348+
check_collinearity.hurdle <- function(
349+
x,
350+
component = "all",
351+
ci = 0.95,
352+
verbose = verbose,
353+
...
354+
) {
349355
component <- insight::validate_argument(
350356
component,
351357
c("all", "conditional", "count", "zi", "zero_inflated")
@@ -355,11 +361,13 @@ check_collinearity.hurdle <- function(x,
355361

356362

357363
#' @export
358-
check_collinearity.zeroinfl <- function(x,
359-
component = "all",
360-
ci = 0.95,
361-
verbose = verbose,
362-
...) {
364+
check_collinearity.zeroinfl <- function(
365+
x,
366+
component = "all",
367+
ci = 0.95,
368+
verbose = verbose,
369+
...
370+
) {
363371
component <- insight::validate_argument(
364372
component,
365373
c("all", "conditional", "count", "zi", "zero_inflated")
@@ -369,11 +377,13 @@ check_collinearity.zeroinfl <- function(x,
369377

370378

371379
#' @export
372-
check_collinearity.zerocount <- function(x,
373-
component = "all",
374-
ci = 0.95,
375-
verbose = verbose,
376-
...) {
380+
check_collinearity.zerocount <- function(
381+
x,
382+
component = "all",
383+
ci = 0.95,
384+
verbose = verbose,
385+
...
386+
) {
377387
component <- insight::validate_argument(
378388
component,
379389
c("all", "conditional", "count", "zi", "zero_inflated")
@@ -385,11 +395,17 @@ check_collinearity.zerocount <- function(x,
385395
# utilities ---------------------------------
386396

387397
.check_collinearity_zi_model <- function(x, component, ci = 0.95, verbose = TRUE) {
388-
if (component == "count") component <- "conditional"
389-
if (component == "zi") component <- "zero_inflated"
398+
if (component == "count") {
399+
component <- "conditional"
400+
}
401+
if (component == "zi") {
402+
component <- "zero_inflated"
403+
}
390404

391405
mi <- insight::model_info(x, verbose = FALSE)
392-
if (!mi$is_zero_inflated) component <- "conditional"
406+
if (!mi$is_zero_inflated) {
407+
component <- "conditional"
408+
}
393409

394410
if (component == "all") {
395411
cond <- .check_collinearity(x, "conditional", ci = ci, verbose = verbose)
@@ -439,7 +455,10 @@ check_collinearity.zerocount <- function(x,
439455
if (isTRUE(verbose)) {
440456
insight::format_alert(
441457
paste(
442-
sprintf("Could not extract the variance-covariance matrix for the %s component of the model.", component),
458+
sprintf(
459+
"Could not extract the variance-covariance matrix for the %s component of the model.",
460+
component
461+
),
443462
"Please try to run `vcov(model)`, which may help identifying the problem."
444463
)
445464
)
@@ -453,13 +472,15 @@ check_collinearity.zerocount <- function(x,
453472
if (is.null(term_assign) || all(is.na(term_assign))) {
454473
if (verbose) {
455474
insight::format_alert(
456-
sprintf("Could not extract model terms for the %s component of the model.", component)
475+
sprintf(
476+
"Could not extract model terms for the %s component of the model.",
477+
component
478+
)
457479
)
458480
}
459481
return(NULL)
460482
}
461483

462-
463484
# we have rank-deficiency here. remove NA columns from assignment
464485
if (isTRUE(attributes(v)$rank_deficient) && !is.null(attributes(v)$na_columns_index)) {
465486
term_assign <- term_assign[-attributes(v)$na_columns_index]
@@ -482,9 +503,11 @@ check_collinearity.zerocount <- function(x,
482503

483504
# hurdle or zeroinfl model can have no zero-inflation formula, in which case
484505
# we have the same formula as for conditional formula part
485-
if (inherits(x, c("hurdle", "zeroinfl", "zerocount")) &&
486-
component == "zero_inflated" &&
487-
is.null(f[["zero_inflated"]])) {
506+
if (
507+
inherits(x, c("hurdle", "zeroinfl", "zerocount")) &&
508+
component == "zero_inflated" &&
509+
is.null(f[["zero_inflated"]])
510+
) {
488511
f$zero_inflated <- f$conditional
489512
}
490513

@@ -503,7 +526,10 @@ check_collinearity.zerocount <- function(x,
503526
if (n.terms < 2) {
504527
if (isTRUE(verbose)) {
505528
insight::format_alert(
506-
sprintf("Not enough model terms in the %s part of the model to check for multicollinearity.", component)
529+
sprintf(
530+
"Not enough model terms in the %s part of the model to check for multicollinearity.",
531+
component
532+
)
507533
)
508534
}
509535
return(NULL)
@@ -639,17 +665,20 @@ check_collinearity.zerocount <- function(x,
639665
tryCatch(
640666
{
641667
if (inherits(x, c("hurdle", "zeroinfl", "zerocount"))) {
642-
term_assign <- switch(component,
668+
term_assign <- switch(
669+
component,
643670
conditional = attr(insight::get_modelmatrix(x, model = "count"), "assign"),
644671
zero_inflated = attr(insight::get_modelmatrix(x, model = "zero"), "assign")
645672
)
646673
} else if (inherits(x, "glmmTMB")) {
647-
term_assign <- switch(component,
674+
term_assign <- switch(
675+
component,
648676
conditional = attr(insight::get_modelmatrix(x), "assign"),
649677
zero_inflated = .zi_term_assignment(x, component, verbose = verbose)
650678
)
651679
} else if (inherits(x, "MixMod")) {
652-
term_assign <- switch(component,
680+
term_assign <- switch(
681+
component,
653682
conditional = attr(insight::get_modelmatrix(x, type = "fixed"), "assign"),
654683
zero_inflated = attr(insight::get_modelmatrix(x, type = "zi_fixed"), "assign")
655684
)
@@ -692,7 +721,10 @@ check_collinearity.zerocount <- function(x,
692721
}))
693722

694723
if (insight::is_gam_model(x)) {
695-
model_params <- as.vector(unlist(insight::find_parameters(x)[c(component, "smooth_terms")]))
724+
model_params <- as.vector(unlist(insight::find_parameters(x)[c(
725+
component,
726+
"smooth_terms"
727+
)]))
696728
} else {
697729
model_params <- insight::find_parameters(x)[[component]]
698730
}

0 commit comments

Comments
 (0)