Skip to content

Commit

Permalink
lintr
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Sep 22, 2023
1 parent bebd95b commit bb877a4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 35 deletions.
32 changes: 16 additions & 16 deletions R/compute_variances.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@


compact_list(list(
"var.fixed" = var.fixed,
"var.random" = var.random,
"var.residual" = var.residual,
"var.distribution" = var.distribution,
"var.dispersion" = var.dispersion,
"var.intercept" = var.intercept,
"var.slope" = var.slope,
"cor.slope_intercept" = cor.slope_intercept,
"cor.slopes" = cor.slopes
var.fixed = var.fixed,
var.random = var.random,
var.residual = var.residual,
var.distribution = var.distribution,
var.dispersion = var.dispersion,
var.intercept = var.intercept,
var.slope = var.slope,
cor.slope_intercept = cor.slope_intercept,
cor.slopes = cor.slopes
))
}

Expand Down Expand Up @@ -308,12 +308,12 @@
vc <- lapply(names(lme4::VarCorr(x)), function(i) {
element <- lme4::VarCorr(x)[[i]]
if (i != "residual__") {
if (!is.null(element$cov)) {
out <- as.matrix(drop(element$cov[, 1, ]))
colnames(out) <- rownames(out) <- gsub("Intercept", "(Intercept)", rownames(element$cov), fixed = TRUE)
} else {
if (is.null(element$cov)) {
out <- as.matrix(drop(element$sd[, 1])^2)
colnames(out) <- rownames(out) <- gsub("Intercept", "(Intercept)", rownames(element$sd), fixed = TRUE)
} else {
out <- as.matrix(drop(element$cov[, 1, ]))
colnames(out) <- rownames(out) <- gsub("Intercept", "(Intercept)", rownames(element$cov), fixed = TRUE)
}
attr(out, "sttdev") <- element$sd[, 1]
} else {
Expand Down Expand Up @@ -600,7 +600,9 @@
.null_model <- null_model(x, verbose = verbose)

# check if null-model could be computed
if (!is.null(.null_model)) {
if (is.null(.null_model)) {
mu <- NA
} else {
if (inherits(.null_model, "cpglmm")) {
# installed?
check_if_installed("cplm")
Expand All @@ -609,8 +611,6 @@
null_fixef <- unname(.collapse_cond(lme4::fixef(.null_model)))
}
mu <- exp(null_fixef)
} else {
mu <- NA
}

if (is.na(mu)) {
Expand Down
26 changes: 13 additions & 13 deletions R/find_formula.R
Original file line number Diff line number Diff line change
Expand Up @@ -564,14 +564,14 @@ find_formula.RM <- find_formula.MANOVA
find_formula.gls <- function(x, verbose = TRUE, ...) {
## TODO this is an intermediate fix to return the correlation variables from gls-objects
fcorr <- x$call$correlation
if (!is.null(fcorr)) {
if (is.null(fcorr)) {
f_corr <- NULL
} else {
if (inherits(fcorr, "name")) {
f_corr <- attributes(eval(fcorr))$formula
} else {
f_corr <- parse(text = safe_deparse(fcorr))[[1]]
}
} else {
f_corr <- NULL
}
if (is.symbol(f_corr)) {
f_corr <- paste("~", safe_deparse(f_corr))
Expand Down Expand Up @@ -1272,14 +1272,14 @@ find_formula.lme <- function(x, verbose = TRUE, ...) {
}
## TODO this is an intermediate fix to return the correlation variables from lme-objects
fcorr <- x$call$correlation
if (!is.null(fcorr)) {
if (is.null(fcorr)) {
fc <- NULL
} else {
if (inherits(fcorr, "name")) {
fc <- attributes(eval(fcorr))$formula
} else {
fc <- parse(text = safe_deparse(fcorr))[[1]]$form
}
} else {
fc <- NULL
}

f <- compact_list(list(
Expand Down Expand Up @@ -1313,11 +1313,11 @@ find_formula.mixor <- function(x, verbose = TRUE, ...) {
f_id <- deparse(x$call$id)
f_rs <- x$call$which.random.slope

if (!is.null(f_rs)) {
if (is.null(f_rs)) {
fmr <- f_id
} else {
f_rs <- trim_ws(unlist(strsplit(safe_deparse(x$call$formula[[3]]), "+", fixed = TRUE), use.names = FALSE))[f_rs]
fmr <- paste(f_rs, "|", f_id)
} else {
fmr <- f_id
}

fmr <- stats::as.formula(paste("~", fmr))
Expand Down Expand Up @@ -1489,7 +1489,10 @@ find_formula.BFBayesFactor <- function(x, verbose = TRUE, ...) {
dt <- utils::tail(x@numerator, 1)[[1]]@dataTypes
frand <- names(dt)[which(dt == "random")]

if (!is_empty_object(frand)) {
if (is_empty_object(frand)) {
f.random <- NULL
f.cond <- stats::as.formula(fcond)
} else {
f.random <- stats::as.formula(paste0("~", paste(frand, collapse = " + ")))
for (i in frand) {
fcond <- sub(i, "", fcond, fixed = TRUE)
Expand All @@ -1505,9 +1508,6 @@ find_formula.BFBayesFactor <- function(x, verbose = TRUE, ...) {
fcond <- paste(fcond, "1")
}
f.cond <- stats::as.formula(trim_ws(fcond))
} else {
f.random <- NULL
f.cond <- stats::as.formula(fcond)
}
} else if (.classify_BFBayesFactor(x) %in% c("ttest1", "ttest2")) {
f.cond <- .safe(stats::as.formula(x@numerator[[1]]@identifier$formula))
Expand Down
10 changes: 5 additions & 5 deletions R/find_parameters_bayesian.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ find_parameters.BGGM <- function(x,
...) {
component <- match.arg(component)
l <- switch(component,
"correlation" = list(correlation = colnames(get_parameters(x, component = "correlation"))),
"conditional" = list(conditional = colnames(get_parameters(x, component = "conditional"))),
"intercept" = list(intercept = colnames(x$Y)),
"all" = list(
correlation = list(correlation = colnames(get_parameters(x, component = "correlation"))),
conditional = list(conditional = colnames(get_parameters(x, component = "conditional"))),
intercept = list(intercept = colnames(x$Y)),
all = list(
intercept = colnames(x$Y),
correlation = colnames(get_parameters(x, component = "correlation")),
conditional = colnames(get_parameters(x, component = "conditional"))
Expand Down Expand Up @@ -549,7 +549,7 @@ find_parameters.stanmvreg <- function(x,
}


l <- mapply(c, l.cond, l.random, l.sigma, SIMPLIFY = FALSE)
l <- Map(c, l.cond, l.random, l.sigma)
l <- .filter_pars(l, parameters, is_mv = TRUE)

effects <- match.arg(effects)
Expand Down
2 changes: 1 addition & 1 deletion R/format_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ format_table <- function(x,
other_ci_colname <- sprintf("%s %g%% CI", other, unique(stats::na.omit(att[[paste0("ci_", other)]])) * 100)
} else if (!is.null(att[["ci"]])) {
other_ci_colname <- sprintf("%s %g%% CI", other, unique(stats::na.omit(att[["ci"]])) * 100)
} else if (length(other == 1) && paste0(other, "_CI") %in% colnames(x)) {
} else if (length(other) == 1 && paste0(other, "_CI") %in% colnames(x)) {
other_ci_colname <- sprintf("%s %g%% CI", other, unique(stats::na.omit(x[[paste0(other, "_CI")]])) * 100)
} else {
other_ci_colname <- paste(other, " CI")
Expand Down

0 comments on commit bb877a4

Please sign in to comment.