diff --git a/R/int_utils.R b/R/int_utils.R index ed5bf9e..20a8861 100644 --- a/R/int_utils.R +++ b/R/int_utils.R @@ -422,7 +422,7 @@ center_ss_non_survey <- function(d, weights, facvars = NULL, fvars, pred, # Dealing with two-level factors that aren't part # of an interaction/focal pred for (v in fv2) { - if (is.factor(d[[v]]) & length(unique(d[[v]])) == 2) { + if (is.factor(d[[v]]) && length(unique(d[[v]])) == 2) { facvars <- c(facvars, v) diff --git a/R/johnson_neyman.R b/R/johnson_neyman.R index 6c94815..514aff4 100644 --- a/R/johnson_neyman.R +++ b/R/johnson_neyman.R @@ -190,7 +190,7 @@ johnson_neyman <- function(model, pred, modx, vmat = NULL, alpha = 0.05, # Construct interaction term ## Create helper function to use either fixef() or coef() depending on input get_coef <- function(mod) { - if (inherits(mod, "merMod") | inherits(mod, "brmsfit")) { + if (inherits(mod, "merMod") || inherits(mod, "brmsfit")) { coef <- lme4::fixef(model) if (inherits(mod, "brmsfit")) { coefs <- coef[,1, drop = TRUE] @@ -307,7 +307,7 @@ johnson_neyman <- function(model, pred, modx, vmat = NULL, alpha = 0.05, test <- 0 i <- 1 + length(marginal_effects) - while (test == 0 & i > 1) { + while (test == 0 && i > 1) { i <- i - 1 test <- min(ps[ps_o][1:i] <= multipliers[i] * (alpha * 2)) @@ -557,7 +557,7 @@ johnson_neyman <- function(model, pred, modx, vmat = NULL, alpha = 0.05, ggplot2::geom_segment(ggplot2::aes(x = modrangeo[1], xend = modrangeo[2], y = 0, yend = 0, linetype = "Range of\nobserved\ndata"), - lineend = "square", size = 1.25) + lineend = "square", linewidth = 1.25) } # Adding this scale allows me to have consistent ordering diff --git a/R/simple_slopes.R b/R/simple_slopes.R index eb846d9..7db31ad 100644 --- a/R/simple_slopes.R +++ b/R/simple_slopes.R @@ -240,6 +240,7 @@ sim_slopes <- function(model, pred, modx, mod2 = NULL, modx.values = NULL, of model. If you are using a package like glmmTMB or other mixed modeling packages, install and load the broom.mixed package and try again. Make sure you have the broom package installed and loaded otherwise.")) + pred_names <- pred_names %just% tidied$term if (length(pred_names) == 0) { stop_wrap("Could not find the focal predictor in the model. If it was @@ -283,14 +284,14 @@ sim_slopes <- function(model, pred, modx, mod2 = NULL, modx.values = NULL, modx.labels = modx.labels, any.mod2 = !is.null(mod2), sims = TRUE) - if ((pred_factor | !is.numeric(d[[modx]])) & johnson_neyman == TRUE) { + if ((pred_factor || !is.numeric(d[[modx]])) && johnson_neyman == TRUE) { warn_wrap("Johnson-Neyman intervals are not available for factor predictors or moderators.", call. = FALSE) johnson_neyman <- FALSE } # Now specify def or not (for labeling w/ print method) - if (is.character(modx.values) | is.null(modx.values) | !is.null(modx.labels)) { + if (is.character(modx.values) || is.null(modx.values) || !is.null(modx.labels)) { ss <- structure(ss, def = TRUE) @@ -326,7 +327,7 @@ sim_slopes <- function(model, pred, modx, mod2 = NULL, modx.values = NULL, } # Now specify def or not - if (is.character(mod2.values) | is.null(mod2.values) | !is.null(mod2.labels)) { + if (is.character(mod2.values) || is.null(mod2.values) || !is.null(mod2.labels)) { ss <- structure(ss, def2 = TRUE) @@ -411,7 +412,7 @@ sim_slopes <- function(model, pred, modx, mod2 = NULL, modx.values = NULL, } - # Looping through (perhaps non-existent) + # Looping through (perhaps non-existent) second moderator values for (j in seq_len(mod2val_len)) { # We don't want to do the J-N interval with the 1st moderator adjusted, @@ -456,7 +457,7 @@ sim_slopes <- function(model, pred, modx, mod2 = NULL, modx.values = NULL, } # Getting SEs, robust or otherwise - if (robust != FALSE & is.null(v.cov)) { + if (robust != FALSE && is.null(v.cov)) { # For J-N covmat <- get_robust_se(newmod, robust, cluster, dt)$vcov } else if (is.null(v.cov)) { @@ -545,7 +546,7 @@ sim_slopes <- function(model, pred, modx, mod2 = NULL, modx.values = NULL, } else { covmat <- NULL } - # Use j_summ to get the coefficients + # Use summ to get the coefficients if (has_summ) { sum <- summ(newmod, robust = robust, model.fit = FALSE, confint = TRUE, ci.width = ci.width, vifs = FALSE, @@ -554,8 +555,6 @@ sim_slopes <- function(model, pred, modx, mod2 = NULL, modx.values = NULL, } else { sum <- generics::tidy(newmod, conf.int = TRUE, conf.level = ci.width) } - - } else { if (is.null(v.cov)) { # For J-N @@ -587,7 +586,6 @@ sim_slopes <- function(model, pred, modx, mod2 = NULL, modx.values = NULL, intp <- summat[summat$term == "(Intercept)", ] } - # Have to account for variable amount of rows needed due to factor # predictors rows <- split(1:nrow(retmat),