context("Test that APA style documentation functions are working properly.")
library(HDA)
options(scipen=12)
# Make reproducible
set.seed(1)
load(file = "../../etc/dat.RData")
test_that("Test that p.txt outputs appropriately for various p values",
{expect_identical(p.txt(.000485),"p<.001")
expect_identical(p.txt(.009485),"p<.01")
expect_identical(p.txt(.0239485),"p<.05")
expect_identical(p.txt(.0939485),"p<.1")
expect_identical(p.txt(.39485),"p=0.39")})
test_that("apa works for all supported test types with HTML output",{
expect_identical(apa(kruskal.test(dat$y, dat$x), type = "html"), htmltools::HTML("Kruskal-Wallis chi-squared<sub>(14)</sub>=14, p=0.45"), label = "Kruskal")
expect_identical(apa(wilcox.test(dat$y, dat$x), type = "html"), htmltools::HTML("W=110, p=0.93"), label = "Wilcox")
expect_identical(apa(t.test(dat$y, dat$x), type = "html"), htmltools::HTML("t<sub>(27)</sub>=0.1, CI<sub>(α=0.05)</sub>[-0.67,0.74], p=0.92"), label = "t-test")
expect_identical(apa(aov(y ~ x + fac, data = dat)), htmltools::HTML(c(x = "F<sub>(1)</sub>=0.111, p=0.74", fac = "F<sub>(2)</sub>=0.003, p=1")), label = "aov")
expect_identical(apa(anova(lm(y ~ x + fac, data = dat))), htmltools::HTML(c(x = "F<sub>(1)</sub>=0.111, p=0.74", fac = "F<sub>(2)</sub>=0.003, p=1")), label = "anova")
expect_identical(apa(effsize::cohen.d(y ~ fac, data = dat[dat$fac %in% c("a","b"),])), htmltools::HTML("d=-0.01, CI<sub>(α=0.05)</sub>[-1.47,1.45]. This effect size is considered negligible."), label = "Cohen")
expect_identical(apa(shapiro.test(dat$x), type = "html"), htmltools::HTML("W=0.86, p<.05"), label = "Shapiro")
expect_identical(apa(car::leveneTest(dat$y, dat$fac), type = "html"), htmltools::HTML("F<sub>(2,12)</sub>=0.92, p=0.42"), label = "Levene")
expect_identical(apa(bartlett.test(dat$y, dat$fac), type = "html"), htmltools::HTML("K<sup>2</sup><sub>(2)</sub>=2.29, p=0.32"), label = "Bartlett")
expect_identical(apa(fligner.test(dat$y, dat$fac), type = "html"), htmltools::HTML("χ<sup>2</sup><sub>(2)</sub>=1.02, p=0.6"), label = "Fligner")
expect_identical(apa(cor.test(dat$y, dat$x,method = "pearson"), type = "html"), htmltools::HTML("r<sub>(13)</sub>=0.1, CI<sub>(α=0.05)</sub>[-0.43,0.58], p=0.72"), label = "Pearson")
expect_identical(apa(cor.test(dat$y, dat$x,method = "kendall"), type = "html"), htmltools::HTML("τ=-0.05, p=0.85"), label = "Kendall")
expect_identical(apa(cor.test(dat$y, dat$x,method = "spearman"), type = "html"), htmltools::HTML("ρ=-0.05, p=0.86"), label = "Spearman")
})
test_that("apa works for all supported test types with Latex output",{
expect_identical(apa(kruskal.test(dat$y, dat$x), type = "latex"), paste0("Kruskal-Wallis chi-squared_{(14)}=14, p=0.45"), label = "Kruskal")
expect_identical(apa(wilcox.test(dat$y, dat$x), type = "latex"), paste0("W=110, p=0.93"), label = "Wilcox")
expect_identical(apa(t.test(dat$y, dat$x), type = "latex"), paste0("t_{(27)}=0.1, CI[-0.67,0.74], p=0.92"), label = "t-test")
expect_true(all(apa(aov(y ~ x + fac, data = dat), type = "latex") == c(x = "F_{(1)}=0.111, p=0.74", fac = "F_{(2)}=0.003, p=1")), label = "aov")
expect_identical(apa(anova(lm(y ~ x + fac, data = dat)), type = "latex"), c(x = "F_{(1)}=0.111, p=0.74", fac = "F_{(2)}=0.003, p=1"), label = "anova")
expect_identical(apa(effsize::cohen.d(y ~ fac, data = dat[dat$fac %in% c("a","b"),]), type = "latex"), paste0("d=-0.01, CI[-1.47,1.45]. This effect size is considered negligible."), label = "Cohen")
expect_identical(apa(shapiro.test(dat$x), type = "latex"), paste0("W=0.86, p<.05"), label = "Shapiro")
expect_identical(apa(car::leveneTest(dat$y, dat$fac), type = "latex"), paste0("F_{(2,12)}=0.92, p=0.42"), label = "Levene")
expect_identical(apa(bartlett.test(dat$y, dat$fac), type = "latex"), paste0("K^2_{(2)}=2.29, p=0.32"), label = "Bartlett")
expect_identical(apa(fligner.test(dat$y, dat$fac), type = "latex"), paste0("x^2_{(2)}=1.02, p=0.6"), label = "Fligner")
expect_identical(apa(cor.test(dat$y, dat$x,method = "pearson"), type = "latex"), paste0("r_{(13)}=0.1, CI[-0.43,0.58], p=0.72"), label = "Pearson")
expect_identical(apa(cor.test(dat$y, dat$x,method = "kendall"), type = "latex"), paste0("\\tau=-0.05, p=0.85"), label = "Kendall")
expect_identical(apa(cor.test(dat$y, dat$x,method = "spearman"), type = "latex"), paste0("\\rho=-0.05, p=0.86"), label = "Spearman")
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.