Skip to content

Commit

Permalink
Merge branch 'main' into report_participants_gender
Browse files Browse the repository at this point in the history
  • Loading branch information
rempsyc authored Aug 18, 2023
2 parents 8705fda + 0b1046d commit 1e24952
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 58 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Depends:
Imports:
bayestestR (>= 0.13.0),
effectsize (>= 0.8.5),
insight (>= 0.19.1),
insight (>= 0.19.3.2),
parameters (>= 0.20.2),
performance (>= 0.10.2),
datawizard (>= 0.7.0),
Expand Down
6 changes: 4 additions & 2 deletions R/report_htest_chi2.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# report_effectsize ---------------------

.report_effectsize_chi2 <- function(x, table, dot_args, type, rules = "funder2019") {
.report_effectsize_chi2 <- function(x, table, dot_args, rules = "funder2019") {
if (grepl("Pearson", x$method, fixed = TRUE)) {
args <- c(list(x), dot_args)
table <- do.call(effectsize::effectsize, args)
Expand All @@ -31,10 +31,12 @@
main <- paste0("Adjusted Cramer's v = ", insight::format_value(table[[estimate]]))
} else if (estimate %in% "Tschuprows_t") {
main <- paste0("Tschuprow's t = ", insight::format_value(table[[estimate]]))
} else if (estimate %in% "Tschuprows_t_adjusted") {
main <- paste0("Adjusted Tschuprow's t = ", insight::format_value(table[[estimate]]))
} else if (estimate %in% "Pearsons_c") {
main <- paste0("Pearson's c = ", insight::format_value(table[[estimate]]))
} else if (estimate %in% "phi_adjusted") {
main <- paste0("Adjusted's Phi = ", insight::format_value(table[[estimate]]))
main <- paste0("Adjusted Phi = ", insight::format_value(table[[estimate]]))
} else if (estimate %in% "Cohens_h") {
main <- paste0("Cohen's h = ", insight::format_value(table[[estimate]]))
} else if (estimate %in% "Odds_ratio") {
Expand Down
14 changes: 0 additions & 14 deletions tests/testthat/_snaps/report.lm.md

This file was deleted.

32 changes: 0 additions & 32 deletions tests/testthat/_snaps/report_sample.md

This file was deleted.

13 changes: 11 additions & 2 deletions tests/testthat/_snaps/windows/report.htest-chi2.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,21 @@
---

Code
report_effectsize(x, type = "tschuprows_t")
report_effectsize(x, type = "tschuprows_t", adjust = FALSE)
Output
Effect sizes were labelled following Funder's (2019) recommendations.
very small (Tschuprows_t_adjusted = 0.08, 95% CI [0.06, 1.00])

---

Code
report_effectsize(x, type = "tschuprows_t")
Output
(Adjusted Tschuprow's t = 0.08, 95% CI [0.06, 1.00])

---

Code
Expand All @@ -95,7 +104,7 @@
Output
Effect sizes were labelled following Funder's (2019) recommendations.
large (Adjusted's Phi = 0.36, 95% CI [0.25, 1.00])
large (Adjusted Phi = 0.36, 95% CI [0.25, 1.00])

---

Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/_snaps/windows/report.lm.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,17 @@
version of the dataset. 95% Confidence Intervals (CIs) and p-values were
computed using a Wald z-distribution approximation.

# report.lm - lm intercept-only

Code
out
Output
We fitted a constant (intercept-only) linear model (estimated using OLS) to
predict d_wide$group0 - d_wide$group1 (formula: d_wide$group0 - d_wide$group1 ~
1). The model's intercept is at -1.58 (95% CI [-2.46, -0.70], t(9) = -4.06, p =
0.003).
Standardized parameters were obtained by fitting the model on a standardized
version of the dataset. 95% Confidence Intervals (CIs) and p-values were
computed using a Wald t-distribution approximation.

32 changes: 32 additions & 0 deletions tests/testthat/_snaps/windows/report_sample.md
Original file line number Diff line number Diff line change
Expand Up @@ -618,3 +618,35 @@
Species [versicolor], % | 36.9
Species [virginica], % | 56.3

# report_sample, with more than one grouping variable

Code
out
Output
# Descriptive Statistics
Variable | setosa, a (n=16) | versicolor, a (n=17) | virginica, a (n=9) | setosa, b (n=15) | versicolor, b (n=17) | virginica, b (n=22) | setosa, c (n=19) | versicolor, c (n=16) | virginica, c (n=19) | Total (n=150)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Mean Sepal.Length (SD) | 5.13 (0.36) | 6.08 (0.48) | 6.59 (0.44) | 4.91 (0.31) | 5.84 (0.54) | 6.77 (0.63) | 4.97 (0.36) | 5.88 (0.53) | 6.38 (0.69) | 5.84 (0.83)
Mean Sepal.Width (SD) | 3.50 (0.42) | 2.76 (0.40) | 3.02 (0.25) | 3.34 (0.25) | 2.81 (0.25) | 3.05 (0.36) | 3.44 (0.43) | 2.74 (0.29) | 2.87 (0.30) | 3.06 (0.44)

# report_sample, print vertical

Code
print(out, layout = "vertical")
Output
# Descriptive Statistics
Groups | Mean Sepal.Length (SD) | Mean Sepal.Width (SD) | Mean Petal.Length (SD)
----------------------------------------------------------------------------------------------
setosa, a (n=16) | 5.13 (0.36) | 3.50 (0.42) | 1.50 (0.12)
versicolor, a (n=17) | 6.08 (0.48) | 2.76 (0.40) | 4.37 (0.44)
virginica, a (n=9) | 6.59 (0.44) | 3.02 (0.25) | 5.57 (0.52)
setosa, b (n=15) | 4.91 (0.31) | 3.34 (0.25) | 1.47 (0.17)
versicolor, b (n=17) | 5.84 (0.54) | 2.81 (0.25) | 4.25 (0.44)
virginica, b (n=22) | 6.77 (0.63) | 3.05 (0.36) | 5.73 (0.57)
setosa, c (n=19) | 4.97 (0.36) | 3.44 (0.43) | 1.43 (0.21)
versicolor, c (n=16) | 5.88 (0.53) | 2.74 (0.29) | 4.16 (0.53)
virginica, c (n=19) | 6.38 (0.69) | 2.87 (0.30) | 5.34 (0.49)
Total (n=150) | 5.84 (0.83) | 3.06 (0.44) | 3.76 (1.77)

11 changes: 8 additions & 3 deletions tests/testthat/test-report.htest-chi2.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
test_that("report.htest-chi2", {
M <- as.table(rbind(c(762, 327, 468), c(484, 239, 477)))
dimnames(M) <- list(gender = c("F", "M"), party = c("Democrat", "Independent", "Republican"))
x <- chisq.test(M)
m <- as.table(rbind(c(762, 327, 468), c(484, 239, 477)))
dimnames(m) <- list(gender = c("F", "M"), party = c("Democrat", "Independent", "Republican"))
x <- chisq.test(m)

expect_snapshot(
variant = "windows",
Expand Down Expand Up @@ -45,6 +45,11 @@ test_that("report.htest-chi2", {
report_effectsize(x, type = "pearsons_c")
)

expect_snapshot(
variant = "windows",
report_effectsize(x, type = "tschuprows_t", adjust = FALSE)
)

expect_snapshot(
variant = "windows",
report_effectsize(x, type = "tschuprows_t")
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-report.lm.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ test_that("report.lm - lm intercept-only", {
)

model_io <- lm(d_wide$group0 - d_wide$group1 ~ 1)
out <- report(model_io)
expect_snapshot(out)
out <- suppressWarnings(report(model_io, verbose = FALSE))
expect_snapshot(variant = "windows", out)
})
4 changes: 2 additions & 2 deletions tests/testthat/test-report_sample.R
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ test_that("report_sample, with more than one grouping variable", {
)
# verified against
expected <- aggregate(iris["Sepal.Length"], iris[c("Species", "grp")], mean)
expect_snapshot(out)
expect_snapshot(variant = "windows", out)
})

test_that("report_sample, numeric select", {
Expand All @@ -286,5 +286,5 @@ test_that("report_sample, print vertical", {
iris$grp <- sample(letters[1:3], nrow(iris), TRUE)
iris_grp <- datawizard::data_group(iris, c("Species", "grp"))
out <- report_sample(iris_grp, select = 1:3)
expect_snapshot(print(out, layout = "vertical"))
expect_snapshot(variant = "windows", print(out, layout = "vertical"))
})

0 comments on commit 1e24952

Please sign in to comment.