Skip to content

Commit

Permalink
lintr
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Feb 4, 2024
1 parent 435f975 commit 388609a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 53 deletions.
42 changes: 19 additions & 23 deletions R/icc.R
Original file line number Diff line number Diff line change
Expand Up @@ -532,14 +532,12 @@ print.icc_decomposed <- function(x, digits = 2, ...) {
name_full = "ICC",
verbose = TRUE) {
vars <- tryCatch(
{
insight::get_variance(model,
name_fun = name_fun,
name_full = name_full,
tolerance = tolerance,
verbose = verbose
)
},
insight::get_variance(model,
name_fun = name_fun,
name_full = name_full,
tolerance = tolerance,
verbose = verbose
),
error = function(e) {
if (inherits(e, c("simpleError", "error")) && verbose) {
insight::print_color(e$message, "red")
Expand Down Expand Up @@ -597,7 +595,7 @@ print.icc_decomposed <- function(x, digits = 2, ...) {
# prepare arguments for "lme4::bootMer"
.do_lme4_bootmer <- function(model, .boot_fun, iterations, dots) {
insight::check_if_installed(c("lme4", "boot"))
args <- list(
my_args <- list(
model,
.boot_fun,
nsim = iterations,
Expand All @@ -608,25 +606,25 @@ print.icc_decomposed <- function(x, digits = 2, ...) {
)
# add/overwrite dot-args
if (!is.null(dots[["use.u"]])) {
args$use.u <- dots[["use.u"]]
my_args$use.u <- dots[["use.u"]]

Check warning on line 609 in R/icc.R

View check run for this annotation

Codecov / codecov/patch

R/icc.R#L609

Added line #L609 was not covered by tests
}
if (!is.null(dots[["re.form"]])) {
args$re.form <- dots[["re.form"]]
my_args$re.form <- dots[["re.form"]]

Check warning on line 612 in R/icc.R

View check run for this annotation

Codecov / codecov/patch

R/icc.R#L612

Added line #L612 was not covered by tests
}
if (!is.null(dots[["type"]])) {
args$type <- dots[["type"]]
if (args$type == "semiparametric") {
args$use.u <- TRUE
my_args$type <- dots[["type"]]
if (my_args$type == "semiparametric") {
my_args$use.u <- TRUE

Check warning on line 617 in R/icc.R

View check run for this annotation

Codecov / codecov/patch

R/icc.R#L615-L617

Added lines #L615 - L617 were not covered by tests
}
}
if (!is.null(dots[["parallel"]])) {
args$parallel <- dots[["parallel"]]
my_args$parallel <- dots[["parallel"]]

Check warning on line 621 in R/icc.R

View check run for this annotation

Codecov / codecov/patch

R/icc.R#L621

Added line #L621 was not covered by tests
}
if (!is.null(dots[["ncpus"]])) {
args$ncpus <- dots[["ncpus"]]
my_args$ncpus <- dots[["ncpus"]]

Check warning on line 624 in R/icc.R

View check run for this annotation

Codecov / codecov/patch

R/icc.R#L624

Added line #L624 was not covered by tests
}
# bootsrap
do.call(lme4::bootMer, args)
do.call(lme4::bootMer, args = my_args)
}


Expand Down Expand Up @@ -664,12 +662,10 @@ print.icc_decomposed <- function(x, digits = 2, ...) {
}

model_rank <- tryCatch(
{
if (!is.null(model$rank)) {
model$rank - df_int
} else {
insight::n_parameters(model) - df_int
}
if (!is.null(model$rank)) {
model$rank - df_int

Check warning on line 666 in R/icc.R

View check run for this annotation

Codecov / codecov/patch

R/icc.R#L666

Added line #L666 was not covered by tests
} else {
insight::n_parameters(model) - df_int

Check warning on line 668 in R/icc.R

View check run for this annotation

Codecov / codecov/patch

R/icc.R#L668

Added line #L668 was not covered by tests
},
error = function(e) insight::n_parameters(model) - df_int
)
Expand Down
58 changes: 28 additions & 30 deletions R/r2_loo.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ r2_loo <- function(model, robust = TRUE, ci = 0.95, verbose = TRUE, ...) {
loo_r2 <- structure(
class = "r2_loo",
lapply(loo_r2, ifelse(robust, stats::median, mean)),
"SE" = lapply(loo_r2, ifelse(robust, stats::mad, stats::sd)),
SE = lapply(loo_r2, ifelse(robust, stats::mad, stats::sd)),
# "Estimates" = lapply(r2_bayesian, bayestestR::point_estimate, centrality = "all", dispersion = TRUE),
"CI" = lapply(loo_r2, bayestestR::hdi, ci = ci),
"robust" = robust
CI = lapply(loo_r2, bayestestR::hdi, ci = ci),
robust = robust
)
return(loo_r2)
}
Expand Down Expand Up @@ -84,13 +84,13 @@ r2_loo_posterior.brmsfit <- function(model, verbose = TRUE, ...) {
res <- insight::find_response(model)
if (mi[[1]]$is_mixed) {
br2_mv <- list(
"R2_loo" = rstantools::loo_R2(
R2_loo = rstantools::loo_R2(

Check warning on line 87 in R/r2_loo.R

View check run for this annotation

Codecov / codecov/patch

R/r2_loo.R#L87

Added line #L87 was not covered by tests
model,
re.form = NULL,
re_formula = NULL,
summary = FALSE
),
"R2_loo_marginal" = rstantools::loo_R2(
R2_loo_marginal = rstantools::loo_R2(

Check warning on line 93 in R/r2_loo.R

View check run for this annotation

Codecov / codecov/patch

R/r2_loo.R#L93

Added line #L93 was not covered by tests
model,
re.form = NA,
re_formula = NA,
Expand All @@ -99,40 +99,38 @@ r2_loo_posterior.brmsfit <- function(model, verbose = TRUE, ...) {
)
br2 <- lapply(seq_along(res), function(x) {
list(
"R2_loo" = unname(as.vector(br2_mv$R2_loo[, x])),
"R2_loo_marginal" = unname(as.vector(br2_mv$R2_loo_marginal[, x]))
R2_loo = unname(as.vector(br2_mv$R2_loo[, x])),
R2_loo_marginal = unname(as.vector(br2_mv$R2_loo_marginal[, x]))

Check warning on line 103 in R/r2_loo.R

View check run for this annotation

Codecov / codecov/patch

R/r2_loo.R#L102-L103

Added lines #L102 - L103 were not covered by tests
)
})
names(br2) <- res
} else {
br2_mv <- list("R2_loo" = rstantools::loo_R2(model, summary = FALSE))
br2_mv <- list(R2_loo = rstantools::loo_R2(model, summary = FALSE))

Check warning on line 108 in R/r2_loo.R

View check run for this annotation

Codecov / codecov/patch

R/r2_loo.R#L108

Added line #L108 was not covered by tests
br2 <- lapply(seq_along(res), function(x) {
list("R2_loo" = unname(as.vector(br2_mv$R2_loo[, x])))
list(R2_loo = unname(as.vector(br2_mv$R2_loo[, x])))

Check warning on line 110 in R/r2_loo.R

View check run for this annotation

Codecov / codecov/patch

R/r2_loo.R#L110

Added line #L110 was not covered by tests
})
names(br2) <- res
}
} else if (mi$is_mixed) {
br2 <- list(
R2_loo = as.vector(rstantools::loo_R2(
model,
re.form = NULL,
re_formula = NULL,
summary = FALSE
)),
R2_loo_marginal = as.vector(rstantools::loo_R2(
model,
re.form = NA,
re_formula = NA,
summary = FALSE
))
)
names(br2$R2_loo) <- rep("Conditional R2_adjusted", length(br2$R2_loo))
names(br2$R2_loo_marginal) <- rep("Marginal R2_adjusted", length(br2$R2_loo))
} else {
if (mi$is_mixed) {
br2 <- list(
"R2_loo" = as.vector(rstantools::loo_R2(
model,
re.form = NULL,
re_formula = NULL,
summary = FALSE
)),
"R2_loo_marginal" = as.vector(rstantools::loo_R2(
model,
re.form = NA,
re_formula = NA,
summary = FALSE
))
)
names(br2$R2_loo) <- rep("Conditional R2_adjusted", length(br2$R2_loo))
names(br2$R2_loo_marginal) <- rep("Marginal R2_adjusted", length(br2$R2_loo))
} else {
br2 <- list("R2_loo" = as.vector(rstantools::loo_R2(model, summary = FALSE)))
names(br2$R2_loo) <- rep("R2_adjusted", length(br2$R2_loo))
}
br2 <- list(R2_loo = as.vector(rstantools::loo_R2(model, summary = FALSE)))
names(br2$R2_loo) <- rep("R2_adjusted", length(br2$R2_loo))
}

br2
Expand Down

0 comments on commit 388609a

Please sign in to comment.