Skip to content

Commit

Permalink
lintr
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Jan 3, 2025
1 parent 05dc187 commit 7edb926
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
16 changes: 8 additions & 8 deletions R/smoothness.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,13 @@ smoothness.numeric <- function(x,
}

if (method == "cor") {
smooth <- stats::cor(utils::head(x, length(x) - lag), utils::tail(x, length(x) - lag))
smooth_data <- stats::cor(utils::head(x, length(x) - lag), utils::tail(x, length(x) - lag))
} else {
smooth <- stats::sd(diff(x, lag = lag)) / abs(mean(diff(x, lag = lag)))
smooth_data <- stats::sd(diff(x, lag = lag)) / abs(mean(diff(x, lag = lag)))
}

if (!is.null(iterations)) {
if (!requireNamespace("boot", quietly = TRUE)) {
insight::format_warning("Package 'boot' needed for bootstrapping SEs.")
} else {
if (requireNamespace("boot", quietly = TRUE)) {
results <- boot::boot(
data = x,
statistic = .boot_smoothness,
Expand All @@ -56,12 +54,14 @@ smoothness.numeric <- function(x,
lag = lag
)
out_se <- stats::sd(results$t, na.rm = TRUE)
smooth <- data.frame(Smoothness = smooth, SE = out_se)
smooth_data <- data.frame(Smoothness = smooth_data, SE = out_se)
} else {
insight::format_warning("Package 'boot' needed for bootstrapping SEs.")
}
}

class(smooth) <- unique(c("parameters_smoothness", class(smooth)))
smooth
class(smooth_data) <- unique(c("parameters_smoothness", class(smooth_data)))
smooth_data
}


Expand Down
24 changes: 12 additions & 12 deletions R/standardize.models.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ standardize.default <- function(x,
update_expr,

Check warning on line 107 in R/standardize.models.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/standardize.models.R,line=107,col=33,[function_argument_linter] Arguments without defaults should come before arguments with defaults.

Check warning on line 107 in R/standardize.models.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/standardize.models.R,line=107,col=33,[function_argument_linter] Arguments without defaults should come before arguments with defaults.
...) {
m_info <- .get_model_info(x, ...)
data <- insight::get_data(x, source = "mf", verbose = FALSE)
model_data <- insight::get_data(x, source = "mf", verbose = FALSE)

if (isTRUE(attr(data, "is_subset"))) {
if (isTRUE(attr(model_data, "is_subset"))) {
insight::format_error("Cannot standardize a model fit with a 'subset = '.")
}

Expand Down Expand Up @@ -164,10 +164,10 @@ standardize.default <- function(x,
weight_variable <- insight::find_weights(x)

if (!is.null(weight_variable) &&
!weight_variable %in% colnames(data) &&
"(weights)" %in% colnames(data)) {
data$.missing_weight <- data[["(weights)"]]
colnames(data)[ncol(data)] <- weight_variable
!weight_variable %in% colnames(model_data) &&
"(weights)" %in% colnames(model_data)) {
model_data$.missing_weight <- model_data[["(weights)"]]
colnames(model_data)[ncol(model_data)] <- weight_variable
weight_variable <- c(weight_variable, "(weights)")
}

Expand All @@ -178,12 +178,12 @@ standardize.default <- function(x,
## ---- SUMMARY: TO Z OR NOT TO Z? ----

dont_standardize <- c(resp, weight_variable, random_group_factor)
do_standardize <- setdiff(colnames(data), dont_standardize)
do_standardize <- setdiff(colnames(model_data), dont_standardize)

# can't std data$var variables
doller_vars <- grepl("(.*)\\$(.*)", do_standardize)
if (any(doller_vars)) {
doller_vars <- colnames(data)[doller_vars]
doller_vars <- colnames(model_data)[doller_vars]
insight::format_warning(
"Unable to standardize variables evaluated in the environment (i.e., not in `data`).",
"The following variables will not be standardizd:",
Expand All @@ -204,7 +204,7 @@ standardize.default <- function(x,

w <- insight::get_weights(x, remove_na = TRUE)

data_std <- standardize(data[do_standardize],
data_std <- standardize(model_data[do_standardize],
robust = robust,
two_sd = two_sd,
weights = if (weights) w,
Expand All @@ -213,7 +213,7 @@ standardize.default <- function(x,

# if two_sd, it must not affect the response!
if (include_response && two_sd) {
data_std[resp] <- standardize(data[resp],
data_std[resp] <- standardize(model_data[resp],
robust = robust,
two_sd = FALSE,
weights = if (weights) w,
Expand Down Expand Up @@ -254,8 +254,8 @@ standardize.default <- function(x,

## ---- ADD BACK VARS THAT WHERE NOT Z ----
if (length(dont_standardize)) {
remaining_columns <- intersect(colnames(data), dont_standardize)
data_std <- cbind(data[, remaining_columns, drop = FALSE], data_std)
remaining_columns <- intersect(colnames(model_data), dont_standardize)
data_std <- cbind(model_data[, remaining_columns, drop = FALSE], data_std)
}


Expand Down

0 comments on commit 7edb926

Please sign in to comment.