diff --git a/R/check_distribution.R b/R/check_distribution.R index 9aa1b244a..80f947f1f 100644 --- a/R/check_distribution.R +++ b/R/check_distribution.R @@ -77,7 +77,6 @@ check_distribution.default <- function(model) { } else { x <- stats::residuals(model) } - # x_scaled <- .normalize(x) dat <- .extract_features(x) dist_residuals <- as.data.frame(t(stats::predict(classify_distribution, dat, type = "prob"))) @@ -171,11 +170,11 @@ check_distribution.numeric <- function(model) { insight::check_if_installed("randomForest") dat <- .extract_features(model) - dist <- as.data.frame(t(stats::predict(classify_distribution, dat, type = "prob"))) + distance <- as.data.frame(t(stats::predict(classify_distribution, dat, type = "prob"))) out <- data.frame( - Distribution = rownames(dist), - p_Vector = dist[[1]], + Distribution = rownames(distance), + p_Vector = distance[[1]], stringsAsFactors = FALSE, row.names = NULL ) diff --git a/R/check_factorstructure.R b/R/check_factorstructure.R index 691bce154..644cd1cf6 100644 --- a/R/check_factorstructure.R +++ b/R/check_factorstructure.R @@ -95,7 +95,7 @@ check_factorstructure <- function(x, n = NULL, ...) { kmo <- check_kmo(x, n, ...) sphericity <- check_sphericity_bartlett(x, n, ...) - text <- paste0("\n - Sphericity: ", attributes(sphericity)$text, "\n - KMO: ", attributes(kmo)$text) + res_text <- paste0("\n - Sphericity: ", attributes(sphericity)$text, "\n - KMO: ", attributes(kmo)$text) if (attributes(kmo)$color == "red" || attributes(sphericity)$color == "red") { color <- "red" @@ -105,7 +105,7 @@ check_factorstructure <- function(x, n = NULL, ...) { out <- list(KMO = kmo, sphericity = sphericity) - attr(out, "text") <- text + attr(out, "text") <- res_text attr(out, "color") <- color attr(out, "title") <- "Is the data suitable for Factor Analysis?" class(out) <- c("easystats_check", class(out)) @@ -136,18 +136,16 @@ check_kmo <- function(x, n = NULL, ...) { # TODO: add interpret_kmo in effectsize and use that here for more fine-grained interpretation if (MSA < 0.5) { - text <- - sprintf( - "The Kaiser, Meyer, Olkin (KMO) overall measure of sampling adequacy suggests that factor analysis is likely to be inappropriate (KMO = %.2f).", - MSA - ) + msg_text <- sprintf( + "The Kaiser, Meyer, Olkin (KMO) overall measure of sampling adequacy suggests that factor analysis is likely to be inappropriate (KMO = %.2f).", # nolint + MSA + ) color <- "red" } else { - text <- - sprintf( - "The Kaiser, Meyer, Olkin (KMO) overall measure of sampling adequacy suggests that data seems appropriate for factor analysis (KMO = %.2f).", - MSA - ) + msg_text <- sprintf( + "The Kaiser, Meyer, Olkin (KMO) overall measure of sampling adequacy suggests that data seems appropriate for factor analysis (KMO = %.2f).", # nolint + MSA + ) color <- "green" } @@ -160,9 +158,9 @@ check_kmo <- function(x, n = NULL, ...) { ")" )) - text <- paste0(text, " The individual KMO scores are: ", text_ind, ".") + msg_text <- paste0(msg_text, " The individual KMO scores are: ", text_ind, ".") - attr(out, "text") <- text + attr(out, "text") <- msg_text attr(out, "color") <- color attr(out, "title") <- "KMO Measure of Sampling Adequacy" class(out) <- c("easystats_check", class(out)) @@ -189,26 +187,24 @@ check_sphericity_bartlett <- function(x, n = NULL, ...) { out <- list(chisq = statistic, p = pval, dof = df) if (pval < 0.001) { - text <- - sprintf( - "Bartlett's test of sphericity suggests that there is sufficient significant correlation in the data for factor analysis (Chisq(%i) = %.2f, %s).", - df, - statistic, - insight::format_p(pval) - ) + msg_text <- sprintf( + "Bartlett's test of sphericity suggests that there is sufficient significant correlation in the data for factor analysis (Chisq(%i) = %.2f, %s).", # nolint + df, + statistic, + insight::format_p(pval) + ) color <- "green" } else { - text <- - sprintf( - "Bartlett's test of sphericity suggests that there is not enough significant correlation in the data for factor analysis (Chisq(%i) = %.2f, %s).", - df, - statistic, - insight::format_p(pval) - ) + msg_text <- sprintf( + "Bartlett's test of sphericity suggests that there is not enough significant correlation in the data for factor analysis (Chisq(%i) = %.2f, %s).", # nolint + df, + statistic, + insight::format_p(pval) + ) color <- "red" } - attr(out, "text") <- text + attr(out, "text") <- msg_text attr(out, "color") <- color attr(out, "title") <- "Test of Sphericity" class(out) <- c("easystats_check", class(out)) diff --git a/tests/testthat/test-pkg-fixest.R b/tests/testthat/test-pkg-fixest.R index dd851f360..8a187e33b 100644 --- a/tests/testthat/test-pkg-fixest.R +++ b/tests/testthat/test-pkg-fixest.R @@ -1,21 +1,23 @@ -base <- iris -names(base) <- c("y1", "y2", "x1", "x2", "species") +base_iris <- iris +names(base_iris) <- c("y1", "y2", "x1", "x2", "species") test_that("fixest: r2", { skip_if_not_installed("fixest") - res <- fixest::feols(y1 ~ x1 + x2 + x2^2 | species, base) + fixest::setFixest_nthreads(1) + res <- fixest::feols(y1 ~ x1 + x2 + x2^2 | species, base_iris) r2_res <- performance::r2(res) - expect_equal(r2_res$R2, fixest::fitstat(res, "r2")[[1]]) - expect_equal(r2_res$R2_adjusted, fixest::fitstat(res, "ar2")[[1]]) - expect_equal(r2_res$R2_within, fixest::fitstat(res, "wr2")[[1]]) - expect_equal(r2_res$R2_within_adjusted, fixest::fitstat(res, "war2")[[1]]) + expect_equal(r2_res$R2, fixest::fitstat(res, "r2")[[1]], ignore_attr = TRUE) + expect_equal(r2_res$R2_adjusted, fixest::fitstat(res, "ar2")[[1]], ignore_attr = TRUE) + expect_equal(r2_res$R2_within, fixest::fitstat(res, "wr2")[[1]], ignore_attr = TRUE) + expect_equal(r2_res$R2_within_adjusted, fixest::fitstat(res, "war2")[[1]], ignore_attr = TRUE) }) test_that("fixest: overdispersion", { skip_if_not_installed("fixest") - res <- fixest::feols(y1 ~ x1 + x2 + x2^2 | species, base) + fixest::setFixest_nthreads(1) + res <- fixest::feols(y1 ~ x1 + x2 + x2^2 | species, base_iris) expect_error( check_overdispersion(res), "can only be used for models from Poisson" @@ -24,14 +26,16 @@ test_that("fixest: overdispersion", { test_that("fixest: outliers", { skip_if_not_installed("fixest") - res <- fixest::feols(y1 ~ x1 + x2 + x2^2 | species, base) + fixest::setFixest_nthreads(1) + res <- fixest::feols(y1 ~ x1 + x2 + x2^2 | species, base_iris) outliers_list <- suppressMessages(check_outliers(res)) expect_identical(attr(outliers_list, "outlier_count"), list()) }) test_that("fixest: model_performance", { skip_if_not_installed("fixest") - res <- fixest::feols(y1 ~ x1 + x2 + x2^2 | species, base) + fixest::setFixest_nthreads(1) + res <- fixest::feols(y1 ~ x1 + x2 + x2^2 | species, base_iris) perf <- model_performance(res) expect_equal(perf$AIC, 107.743, tolerance = 1e-3) expect_equal(perf$BIC, 125.807, tolerance = 1e-3) @@ -47,7 +51,8 @@ test_that("fixest: model_performance", { test_that("fixest_multi: r2", { skip_if_not_installed("fixest") - res <- fixest::feols(c(y1, y2) ~ x1 + csw(x2, x2^2) | species, base) + fixest::setFixest_nthreads(1) + res <- fixest::feols(c(y1, y2) ~ x1 + csw(x2, x2^2) | species, base_iris) r2_res <- performance::r2(res) expect_equal(unname(r2_res[[1]]$R2), 0.837, tolerance = 1e-3) @@ -55,7 +60,8 @@ test_that("fixest_multi: r2", { test_that("fixest_multi: overdispersion", { skip_if_not_installed("fixest") - res <- fixest::feols(c(y1, y2) ~ x1 + csw(x2, x2^2) | species, base) + fixest::setFixest_nthreads(1) + res <- fixest::feols(c(y1, y2) ~ x1 + csw(x2, x2^2) | species, base_iris) expect_error( check_overdispersion(res), "can only be used for models from Poisson" @@ -64,15 +70,17 @@ test_that("fixest_multi: overdispersion", { test_that("fixest_multi: outliers", { skip_if_not_installed("fixest") - res <- fixest::feols(c(y1, y2) ~ x1 + csw(x2, x2^2) | species, base) + fixest::setFixest_nthreads(1) + res <- fixest::feols(c(y1, y2) ~ x1 + csw(x2, x2^2) | species, base_iris) outliers_list <- suppressMessages(check_outliers(res)[[1]]) expect_identical(attr(outliers_list, "outlier_count"), list()) }) test_that("fixest_multi: model_performance", { skip_if_not_installed("fixest") - res <- fixest::feols(c(y1, y2) ~ x1 + csw(x2, x2^2) | species, base) - res2 <- fixest::feols(y1 ~ x1 + x2 + x2^2 | species, base) + fixest::setFixest_nthreads(1) + res <- fixest::feols(c(y1, y2) ~ x1 + csw(x2, x2^2) | species, base_iris) + res2 <- fixest::feols(y1 ~ x1 + x2 + x2^2 | species, base_iris) perf <- model_performance(res) perf2 <- model_performance(res2) expect_identical(perf[[2]], perf2)