Skip to content

Commit

Permalink
lintr
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Jul 13, 2024
1 parent 715dfed commit ee91b02
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
14 changes: 7 additions & 7 deletions R/check_distribution.R
Original file line number Diff line number Diff line change
Expand Up @@ -191,33 +191,33 @@ check_distribution.numeric <- function(model) {
# validation check, remove missings
x <- x[!is.na(x)]

mode <- NULL
mode_value <- NULL
# find mode for integer, or MAP for distributions
if (all(.is_integer(x))) {
mode <- datawizard::distribution_mode(x)
mode_value <- datawizard::distribution_mode(x)
} else {
# this might fail, so we wrap in ".safe()"
mode <- tryCatch(
mode_value <- tryCatch(
as.numeric(bayestestR::map_estimate(x, bw = "nrd0")),
error = function(e) NULL
)
if (is.null(mode)) {
mode <- tryCatch(
if (is.null(mode_value)) {
mode_value <- tryCatch(
as.numeric(bayestestR::map_estimate(x, bw = "kernel")),
error = function(e) NULL
)
}
}

if (is.null(mode)) {
if (is.null(mode_value)) {
mean_mode_diff <- mean(x) - datawizard::distribution_mode(x)
msg <- "Could not accurately estimate the mode."
if (!is.null(type)) {
msg <- paste(msg, "Predicted distribution of the", type, "may be less accurate.")
}
insight::format_alert(msg)
} else {
mean_mode_diff <- .safe(mean(x) - mode)
mean_mode_diff <- .safe(mean(x) - mode_value)
}

data.frame(
Expand Down
2 changes: 1 addition & 1 deletion R/check_homogeneity.R
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ check_homogeneity.afex_aov <- function(x, method = "levene", ...) {
between <- between[!is_covar]
}

form <- stats::formula(paste0(dv, "~", paste0(between, collapse = "*")))
form <- stats::formula(paste0(dv, "~", paste(between, collapse = "*")))
test <- car::leveneTest(form, ag_data, center = mean, ...)

p.val <- test[1, "Pr(>F)"]
Expand Down
14 changes: 7 additions & 7 deletions R/icc.R
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,11 @@ icc <- function(model,
# this is experimental!
if (identical(ci_method, "analytical")) {
result <- .safe(.analytical_icc_ci(model, ci))
if (!is.null(result)) {
if (is.null(result)) {
icc_ci_adjusted <- icc_ci_unadjusted <- NA
} else {
icc_ci_adjusted <- result$ICC_adjusted
icc_ci_unadjusted <- result$ICC_unadjusted
} else {
icc_ci_adjusted <- icc_ci_unadjusted <- NA
}
} else {
result <- .bootstrap_icc(model, iterations, tolerance, ci_method, ...)
Expand Down Expand Up @@ -428,7 +428,7 @@ print.icc <- function(x, digits = 3, ...) {
}

# separate lines for multiple R2
out <- paste0(out, collapse = "\n")
out <- paste(out, collapse = "\n")

cat(out)
cat("\n")
Expand Down Expand Up @@ -693,10 +693,10 @@ print.icc_decomposed <- function(x, digits = 2, ...) {
}

model_rank <- tryCatch(
if (!is.null(model$rank)) {
model$rank - df_int
} else {
if (is.null(model$rank)) {
insight::n_parameters(model) - df_int
} else {
model$rank - df_int
},
error = function(e) insight::n_parameters(model) - df_int
)
Expand Down
10 changes: 5 additions & 5 deletions R/r2_nakagawa.R
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ r2_nakagawa <- function(model,
if (insight::is_empty_object(vars$var.random) || is.na(vars$var.random)) {
if (verbose) {
# if no random effect variance, return simple R2
insight::print_color("Random effect variances not available. Returned R2 does not account for random effects.\n", "red")
insight::print_color("Random effect variances not available. Returned R2 does not account for random effects.\n", "red") # nolint
}
r2_marginal <- vars$var.fixed / (vars$var.fixed + vars$var.residual)
r2_conditional <- NA
Expand All @@ -172,11 +172,11 @@ r2_nakagawa <- function(model,
# this is experimental!
if (identical(ci_method, "analytical")) {
result <- .safe(.analytical_icc_ci(model, ci, fun = "r2_nakagawa"))
if (!is.null(result)) {
if (is.null(result)) {
r2_ci_marginal <- r2_ci_conditional <- NA
} else {
r2_ci_marginal <- result$R2_marginal
r2_ci_conditional <- result$R2_conditional
} else {
r2_ci_marginal <- r2_ci_conditional <- NA
}
} else {
result <- .bootstrap_r2_nakagawa(model, iterations, tolerance, ci_method, ...)
Expand Down Expand Up @@ -266,7 +266,7 @@ print.r2_nakagawa <- function(x, digits = 3, ...) {
}

# separate lines for multiple R2
out <- paste0(out, collapse = "\n")
out <- paste(out, collapse = "\n")

cat(out)
cat("\n")
Expand Down

0 comments on commit ee91b02

Please sign in to comment.