1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
skip_on_cran()
iris$Cat1 <- rep_len(c("X", "X", "Y"), nrow(iris))
iris$Cat2 <- rep_len(c("A", "B"), nrow(iris))
# aov ----------------------------------
test_that("model_parameters.aov", {
skip_if_not_installed("effectsize", minimum_version = "0.5.0")
model <- aov(Sepal.Width ~ Species, data = iris)
mp <- suppressMessages(model_parameters(model, es_type = c("omega", "eta", "epsilon")))
expect_identical(mp$Parameter, c("Species", "Residuals"))
expect_equal(mp$Sum_Squares, c(11.34493, 16.962), tolerance = 1e-3)
})
test_that("model_parameters.aov", {
skip_if_not_installed("effectsize", minimum_version = "0.5.0")
model <- aov(Sepal.Width ~ Species, data = iris)
mp <- suppressMessages(model_parameters(model, es_type = c("omega", "eta", "epsilon")))
expect_identical(sum(mp$df), 149)
expect_named(mp, c(
"Parameter", "Sum_Squares", "df", "Mean_Square", "F", "p",
"Omega2", "Eta2", "Epsilon2"
))
model <- aov(Sepal.Length ~ Species * Cat1 * Cat2, data = iris)
expect_identical(sum(model_parameters(model, es_type = c("omega", "eta", "epsilon"), verbose = FALSE)$df), 149)
model <- aov(Sepal.Length ~ Species / Cat1 * Cat2, data = iris)
expect_identical(sum(model_parameters(model, verbose = FALSE)$df), 149)
})
test_that("model_parameters.anova", {
skip_if_not_installed("lme4")
model <- anova(lm(Sepal.Width ~ Species, data = iris))
expect_identical(sum(model_parameters(model)$df), 149L)
model <- anova(lm(Sepal.Length ~ Species * Cat1 * Cat2, data = iris))
expect_identical(sum(model_parameters(model)$df), 149L)
model <- anova(lme4::lmer(wt ~ 1 + (1 | gear), data = mtcars))
expect_identical(nrow(model_parameters(model)), 0L)
model <- anova(lme4::lmer(wt ~ cyl + (1 | gear), data = mtcars))
expect_identical(sum(model_parameters(model)$df), 1L)
model <- anova(lme4::lmer(wt ~ drat + cyl + (1 | gear), data = mtcars))
expect_identical(sum(model_parameters(model)$df), 2L)
model <- anova(lme4::lmer(wt ~ drat * cyl + (1 | gear), data = mtcars))
expect_identical(sum(model_parameters(model, verbose = FALSE)$df), 3L)
model <- anova(lme4::lmer(wt ~ drat / cyl + (1 | gear), data = mtcars))
expect_identical(sum(model_parameters(model, verbose = FALSE)$df), 2L)
})
test_that("model_parameters.anova", {
skip_if_not_installed("curl")
skip_if_offline()
skip_if_not_installed("httr2")
model <- insight::download_model("anova_3")
expect_identical(sum(model_parameters(model, verbose = FALSE)$df), 149L)
model <- insight::download_model("anova_4")
expect_identical(sum(model_parameters(model, verbose = FALSE)$df, na.rm = TRUE), 2)
model <- insight::download_model("anova_lmerMod_5")
expect_identical(sum(model_parameters(model, verbose = FALSE)$df), 1L)
model <- insight::download_model("anova_lmerMod_6")
expect_identical(sum(model_parameters(model, verbose = FALSE)$df), 12)
})
test_that("model_parameters.anova", {
model <- aov(wt ~ cyl + Error(gear), data = mtcars)
expect_identical(sum(model_parameters(model, verbose = FALSE)$df), 31)
model <- aov(Sepal.Length ~ Species * Cat1 + Error(Cat2), data = iris)
expect_identical(sum(model_parameters(model, verbose = FALSE)$df), 149)
model <- aov(Sepal.Length ~ Species / Cat1 + Error(Cat2), data = iris)
expect_identical(sum(model_parameters(model, verbose = FALSE)$df), 149)
})
test_that("model_parameters.aov - table_wide", {
skip_if_not_installed("effectsize")
skip_if_not_installed("datawizard")
data("iris")
# can't use the pipe yet :(
iris_long <- datawizard::data_modify(iris, id = seq_along(Species))
iris_long <- datawizard::data_to_long(iris_long, select = colnames(iris)[1:4])
iris_long <- datawizard::data_separate(iris_long,
select = "name", separator = "\\.",
new_columns = c("attribute", "measure")
)
mod1 <- stats::aov(
formula = value ~ attribute * measure + Error(id),
data = iris_long
)
mod2 <- stats::aov(
formula = value ~ attribute * measure + Error(id / (attribute * measure)),
data = iris_long
)
mp1 <- model_parameters(mod1, eta_squared = "partial", ci = 0.95, table_wide = TRUE)
mp2 <- model_parameters(mod2, eta_squared = "partial", ci = 0.95, table_wide = TRUE)
expect_identical(nrow(mp1), 3L)
expect_identical(nrow(mp2), 6L)
mod1 <- aov(yield ~ N * P * K + Error(block), data = npk)
out1 <- model_parameters(mod1, table_wide = FALSE)
out2 <- model_parameters(mod1, table_wide = TRUE)
idx <- which(out1$Parameter == "Residuals")
expect_true(all(out2$Sum_Squares_Error %in% out1$Sum_Squares[idx]))
expect_true(all(out1$Sum_Squares[idx] %in% out2$Sum_Squares_Error))
expect_true(all(out2$Mean_Square_Error %in% out1$Mean_Square[idx]))
expect_true(all(out1$Mean_Square[idx] %in% out2$Mean_Square_Error))
expect_true(all(out2$df_error %in% out1$df[idx]))
expect_true(all(out1$df[idx] %in% out2$df_error))
})
|