Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed May 12, 2024
1 parent 32622de commit 9d7dcf5
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions tests/testthat/test-chi_squared_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,22 @@ test_that("chi_squared_test", {
data(efc)
set.seed(123)
efc$weight <- abs(rnorm(nrow(efc), 1, 0.3))
chi_squared_test(efc, "c161sex", by = "e16sex")
chi_squared_test(efc, "c161sex", by = "e16sex", weights = "weight")
chi_squared_test(efc, "c161sex", probabilities = c(0.3, 0.7))
out1 <- chi_squared_test(efc, "c161sex", by = "e16sex")
out2 <- chisq.test(efc$c161sex, efc$e16sex)
expect_equal(out1$statistic, out2$statistic, tolerance = 1e-4, ignore_attr = TRUE)
expect_equal(out1$p, out2$p.value, tolerance = 1e-4, ignore_attr = TRUE)

out <- chi_squared_test(efc, "c161sex", by = "e16sex", weights = "weight")
expect_equal(out$statistic, 2.415755, tolerance = 1e-4, ignore_attr = TRUE)
expect_equal(out$effect_size, 0.05448519, tolerance = 1e-4, ignore_attr = TRUE)
expect_equal(out$p, 0.1201201, tolerance = 1e-4, ignore_attr = TRUE)

out1 <- chi_squared_test(efc, "c161sex", probabilities = c(0.3, 0.7))
out2 <- chisq.test(table(efc$c161sex), p = c(0.3, 0.7))
expect_equal(out1$statistic, out2$statistic, tolerance = 1e-4, ignore_attr = TRUE)
expect_equal(out1$p, out2$p.value, tolerance = 1e-4, ignore_attr = TRUE)

out <- chi_squared_test(efc, "c161sex", probabilities = c(0.3, 0.7), weights = "weight")
expect_equal(out$statistic, 20.07379, tolerance = 1e-4, ignore_attr = TRUE)
expect_equal(out$effect_size, 0.0974456, tolerance = 1e-4, ignore_attr = TRUE)
})

0 comments on commit 9d7dcf5

Please sign in to comment.