# set.seed
set.seed(1)
# create example character vector
char_example <- c("cat", "dog", "cat", "dog", "giraffe")
# create example numeric vector
num_example <- c(5, 0, .5, .1, .05, .01, .005, .001, .0005)
# create example data
data_example <- data.frame(scale1_item1 = c(6, 1, 3, 4, 5, 9, 9),
scale1_item2 = c(7, 2, 4, 5, 4, 8, 9),
scale1_item3 = c(8, 1, 5, 4, 4, 9, 8),
scale2_item1 = c(9, 9, 9, 8, 4, 2, 2),
scale2_item2 = c(7, 8, 7, 9, 5, 1, 2))
data_example_2 <- data.frame(group = rep(c("A", "A", "B", "B", "A"), 2),
mach = rep(c(NA, 2, 300, 200, 3), 2),
narc = rep(c(2, 4, 500, 700, 10), 2),
psyc = rep(c(3, 4, 1800, 2000, 5), 2),
des = rep(c(100, 100, 2, 10, 1000), 2),
mor = rep(c(10, 10, 500, 1000, 20), 2))
data_example_3 <- data.frame(group = rep(c("A", "B", "C", "A", "B", "C"), 2),
mach = rep(c(3, 2, 300, 200, 3, 400), 2),
narc = rep(c(2, 4, 500, 700, 10, 100), 2),
psyc = rep(c(3, 4, 1800, 2000, 5, 200), 2))
data_example_4 <- data.frame(scale1_item1 = c(6, 1, 3, 4, 5, 9, 9),
scale1_item2 = c(7, 2, 4, 5, 4, 8, 9),
scale1_item3 = c(8, 1, 5, 4, 4, 9, 8),
scale2_item1 = c(9, 9, 9, 8, 4, 2, 2),
scale2_item2 = c(7, 8, 7, 9, 5, 1, 2),
scale3_item1 = c(6, 6, 6, 6, 6, 6, 6),
scale3_item2 = c(7, 7, 7, 7, 7, 7, 7))
data_example_5 <- data.frame(item1 = c(6, 1, 3, 4),
item2 = c(7, 2, 4, 5),
item3 = c(8, 3, 5, 6),
order_1 = c("item1|item2|item3",
"item3|item2|item1",
"item1|item3|item2",
"item3|item1|item2"),
order_2 = c("item3+item2+item1",
"item1+item2+item3",
"item3+item1+item2",
"item1+item3+item2"),
order_3 = c("i3+i2+i1",
"i1+i2+i3",
"i3+i1+i2",
"i1+i3+i2"))
data_example_6 <- data.frame(scale1_item1 = rep(c(6, 1, 3, 4, 5, 9, 9), 4),
scale1_item2 = rep(c(7, 2, 4, 5, 4, 8, 9), 4),
scale1_item3 = rep(c(8, 1, 5, 4, 4, 9, 8), 4),
scale2_item1 = rep(c(9, 9, 9, 8, 4, 2, 2), 4),
scale2_item2 = rep(c(7, 8, 7, 9, 5, 1, 2), 4))
data_example_7 <- data.frame(scale1_item1 = rep(c( 6, 1, 3, 4,
5, 9, 9, 8), 4),
scale1_item2 = rep(c(NA, 2, 4, 5,
4, 8, 9, 8), 4),
scale1_item3 = rep(c( 8, NA, NA, 4,
4, 9, 8, 2), 4),
scale2_item1 = rep(c( 9, 9, NA, 8,
4, NA, 2, NA), 4),
scale2_item2 = rep(c( 7, 8, 7, 9,
5, 1, 2, 1), 4))
data_example_profile <- data.frame(profile_1 = c(50, 55, 60, 65, 70),
profile_2 = c(25, 30, 35, 40, 45))
# create example mats
mat_a <- psych::corr.test(data_example)$p
mat_b <- psych::corr.test(matrix(rnorm(5 * 7),
nrow = 7,
dimnames = list(rownames(data_example),
colnames(data_example))))$p
mat_c <- psych::corr.test(data_example_6)
mat_d <- psych::corr.test(data_example_7)
# create example models
mod_a_example <- lm(scale1_item1 ~ scale2_item1, data = data_example)
mod_b_example <- lm(scale1_item1 ~ scale2_item1 + scale2_item2,
data = data_example)
mod_c_example <- lm(scale1_item1 ~ scale2_item1 + scale2_item2 + scale1_item3,
data = data_example)
# test lenique
test_that("lenique results are equal to length(unique(x)) results", {
expect_equal(lenique(char_example), length(unique(char_example)))
})
# test reverse
test_that("reverse returns the correct values", {
expect_equal(reverse(5), 1)
expect_equal(reverse(2), 4)
expect_equal(reverse(2, 1, 6), 5)
expect_equal(reverse(3, 1, 6), 4)
expect_equal(reverse(-2, -2, 2), 2)
expect_equal(reverse(-1, -2, 2), 1)
expect_equal(reverse(-4, -4, 2), 2)
expect_equal(reverse(-3, -4, 2), 1)
expect_equal(reverse(-2, -4, 2), 0)
expect_error(reverse("hello"), "x is of type character.")
expect_error(reverse(1, "hello", 1), "low is of type character.")
expect_error(reverse(1, 1, "hello"), "high is of type character.")
expect_error(reverse(6, 1, 5), "x \\(6\\) is not a value between low \\(1\\)")
})
# test column_find
test_that("column_find returns the correct parts of the data frame", {
expect_equal(column_find(pattern = "scale1",
return = "logical",
data = data_example),
c(TRUE, TRUE, TRUE, FALSE, FALSE))
expect_equal(column_find(pattern = "scale1",
return = "logical",
data = data_example,
invert = TRUE),
c(FALSE, FALSE, FALSE, TRUE, TRUE))
expect_equal(column_find(pattern = "scale1",
return = "numeric",
data = data_example),
c(1, 2, 3))
expect_equal(column_find(pattern = "scale1",
return = "numeric",
data = data_example,
invert = TRUE),
c(4, 5))
expect_equal(column_find(pattern = "scale1",
return = "character",
data = data_example),
c("scale1_item1", "scale1_item2", "scale1_item3"))
expect_equal(column_find(pattern = "scale1",
return = "character",
data = data_example,
invert = TRUE),
c("scale2_item1", "scale2_item2"))
expect_equal(column_find(pattern = "scale1",
return = "data.frame",
data = data_example),
data.frame(scale1_item1 = c(6, 1, 3, 4, 5, 9, 9),
scale1_item2 = c(7, 2, 4, 5, 4, 8, 9),
scale1_item3 = c(8, 1, 5, 4, 4, 9, 8)))
expect_equal(column_find(pattern = "scale1",
return = "data.frame",
data = data_example,
invert = TRUE),
data.frame(scale2_item1 = c(9, 9, 9, 8, 4, 2, 2),
scale2_item2 = c(7, 8, 7, 9, 5, 1, 2)))
expect_equal(column_find(pattern = "scale",
return = "logical",
data = data_example_4,
invert = FALSE,
antipattern = "item2"),
c(TRUE, FALSE, TRUE, TRUE, FALSE, TRUE, FALSE))
expect_equal(column_find(pattern = "scale",
return = "numeric",
data = data_example_4,
invert = FALSE,
antipattern = "item2"),
c(1, 3, 4, 6))
expect_equal(column_find(pattern = "scale",
return = "data.frame",
data = data_example_4,
invert = FALSE,
antipattern = "item2"),
structure(list(scale1_item1 = c(6, 1, 3, 4, 5, 9, 9),
scale1_item3 = c(8, 1, 5, 4, 4, 9, 8),
scale2_item1 = c(9, 9, 9, 8, 4, 2, 2),
scale3_item1 = c(6, 6, 6, 6, 6, 6, 6)),
class = "data.frame",
row.names = c(NA, -7L)))
expect_equal(column_find(pattern = "scale",
return = "character",
data = data_example_4,
invert = FALSE,
antipattern = "item2"),
c("scale1_item1",
"scale1_item3",
"scale2_item1",
"scale3_item1"))
expect_equal(column_find(pattern = "item2",
return = "character",
data = data_example_4,
invert = TRUE,
antipattern = "item3"),
c("scale1_item1",
"scale2_item1",
"scale3_item1"))
expect_warning(column_find(pattern = "scale1",
return = "abcdefghijklmnopqrstuvwxyz",
data = data_example),
regexp = "\"abcdefghijklmnopqrstuvwxyz\" is not a recognized")
expect_warning(column_find(pattern = "scale1",
return = "abcdefghijklmnopqrstuvwxyz",
data = data_example,
invert = TRUE),
regexp = "\"abcdefghijklmnopqrstuvwxyz\" is not a recognized")
expect_equal(suppressWarnings(column_find(pattern = "scale1",
return = "abcdefghijklmnopqrstuvwxyz",
data = data_example)),
c(TRUE, TRUE, TRUE, FALSE, FALSE))
expect_error(column_find(pattern = "item2",
return = "character",
data = data_example_4,
invert = TRUE,
antipattern = 9),
regexp = "antipattern is of type double")
})
# test column_alpha
test_that("column_alpha returns correct values", {
expect_equal(column_alpha(pattern = "scale1",
data = data_example),
0.974039829302987)
expect_equal(column_alpha(pattern = "scale1",
data = data_example),
psych::alpha(data_example[, 1:3],
warnings = FALSE)[[1]]$raw_alpha)
expect_equal(column_rij(pattern = "scale1",
data = data_example),
psych::alpha(data_example[, 1:3],
warnings = FALSE)[[1]]$average_r)
expect_equal(column_alpha(pattern = "scale1",
data = data_example,
return = "alpha"),
0.974039829302987)
expect_equal(column_alpha(pattern = "scale1",
data = data_example,
return = "rij"),
0.9347283)
expect_equal(column_alpha(pattern = "scale1",
data = data_example,
return = "rij",
ci = TRUE),
0.9347283)
expect_equal(column_alpha(pattern = "scale1",
data = data_example,
return = "o_h"),
0.034041966954079953822)
expect_equal(column_alpha(pattern = "scale1",
data = data_example,
return = "o_t"),
0.9781251764622046485087)
expect_equal(column_o_h(pattern = "scale1",
data = data_example),
0.034041966954079953822)
expect_equal(column_o_t(pattern = "scale1",
data = data_example),
0.9781251764622046485087)
expect_equal(column_alpha(pattern = "scale1",
data = data_example,
return = "all"),
data.frame(alpha = 0.974039829302987,
rij = 0.9347283,
o_h = 0.034041966954079953822,
o_t = 0.9781251764622046485087))
expect_equal(column_alpha(pattern = "scale1",
data = data_example,
return = "alpha",
spround = TRUE),
".97")
expect_equal(column_alpha(pattern = "scale1",
data = data_example,
return = "rij",
spround = TRUE),
".93")
expect_equal(column_alpha(pattern = "scale1",
data = data_example,
return = "o_h",
spround = TRUE),
".03")
expect_equal(column_alpha(pattern = "scale1",
data = data_example,
return = "o_t",
spround = TRUE),
".98")
expect_equal(column_o_h(pattern = "scale1",
data = data_example,
spround = TRUE),
".03")
expect_equal(column_o_t(pattern = "scale1",
data = data_example,
spround = TRUE),
".98")
expect_equal(column_alpha(pattern = "scale1",
data = data_example,
return = "all",
spround = TRUE),
data.frame(alpha = ".97",
rij = ".93",
o_h = ".03",
o_t = ".98"))
expect_equal(column_all(pattern = "scale1",
data = data_example),
data.frame(alpha = 0.974039829302987,
rij = 0.9347283,
o_h = 0.034041966954079953822,
o_t = 0.9781251764622046485087))
expect_equal(column_rij(pattern = "scale1",
data = data_example),
0.9347283)
expect_equal(column_rij(pattern = "scale1",
data = data_example,
full = TRUE)[[1]],
alpha(data_example[, 1:3], warnings = FALSE)[[1]])
expect_equal(column_alpha(pattern = "scale1",
data = data_example,
full = TRUE)[[1]],
alpha(data_example[, 1:3], warnings = FALSE)[[1]])
expect_equal(column_alpha(pattern = "scale1",
data = data_example,
full = TRUE,
message = FALSE)[[1]],
alpha(data_example[, 1:3], warnings = FALSE)[[1]])
expect_message(column_alpha(pattern = "scale1",
data = data_example),
"scale1_item3")
expect_message(column_alpha(pattern = "scale1",
data = data_example,
message = FALSE),
NA)
expect_warning(column_alpha(pattern = "scale1",
data = data_example,
return = "hello"),
"used instead")
expect_equal(suppressWarnings(column_alpha(pattern = "scale1",
data = data_example,
return = "hello")),
0.974039829302987)
expect_equal(column_alpha(pattern = "scale1",
data = data_example,
return = "all",
ci = TRUE,
spround = FALSE),
data.frame(alpha = 0.974039829302987,
alpha_lower = 0.903212900276083,
alpha_upper = 0.995162320062215,
rij = 0.9347283,
o_h = 0.034041966954079953822,
o_t = 0.9781251764622046485087))
expect_equal(column_alpha(pattern = "scale1",
data = data_example,
return = "all",
ci = TRUE,
spround = TRUE),
data.frame(alpha = ".97",
alpha_lower = ".90",
alpha_upper = "1.00",
rij = ".93",
o_h = ".03",
o_t = ".98"))
expect_equal(column_alpha(pattern = "scale1",
data = data_example,
return = "alpha",
ci = TRUE,
spround = FALSE),
data.frame(alpha = 0.974039829302987,
alpha_lower = 0.903212900276083,
alpha_upper = 0.995162320062215))
expect_equal(column_alpha(pattern = "scale1",
data = data_example,
return = "alpha",
ci = TRUE,
spround = TRUE),
data.frame(alpha = ".97",
alpha_lower = ".90",
alpha_upper = "1.00"))
expect_equal(column_alpha(pattern = "scale1",
data = data_example,
return = "all",
ci = TRUE,
spround = FALSE)[[2]],
unname(unlist(alpha(data_example[, 1:3], warnings = FALSE)$feldt$lower.ci)))
expect_equal(column_alpha(pattern = "scale1",
data = data_example,
return = "all",
ci = TRUE,
spround = FALSE)[[3]],
unname(unlist(alpha(data_example[, 1:3], warnings = FALSE)$feldt$upper.ci)))
expect_error(column_alpha(pattern = "scale1",
data = data_example,
ci = "hello"),
"ci is of type character")
expect_error(column_alpha(pattern = "scale1",
data = data_example,
ci = c(T,F)),
"ci must be of length 1")
})
# test reorder
test_that("reorder returns correct values", {
expect_equal(reorder(data_example_5, "order_1"),
list(structure(list(item1 = 6, item2 = 7, item3 = 8),
row.names = 1L, class = "data.frame"),
structure(list(item3 = 3, item2 = 2, item1 = 1),
row.names = 2L, class = "data.frame"),
structure(list(item1 = 3, item3 = 5, item2 = 4),
row.names = 3L, class = "data.frame"),
structure(list(item3 = 6, item1 = 4, item2 = 5),
row.names = 4L, class = "data.frame")))
expect_equal(reorder(data_example_5, "order_2", "\\+"),
list(structure(list(item3 = 8, item2 = 7, item1 = 6),
row.names = 1L, class = "data.frame"),
structure(list(item1 = 1, item2 = 2, item3 = 3),
row.names = 2L, class = "data.frame"),
structure(list(item3 = 5, item1 = 3, item2 = 4),
row.names = 3L, class = "data.frame"),
structure(list(item1 = 4, item3 = 6, item2 = 5),
row.names = 4L, class = "data.frame")))
expect_error(reorder(data_example_5, "order_1", "\\="),
"reorder was unable to split the key using sep")
expect_error(reorder(data_example_5, "order_3", "\\+"),
"could not find key labels in provided dataframe")
})
# test capply
test_that("capply returns correct values", {
expect_equal(capply(data_example,
function(x) x + 2),
apply(data_example, c(1, 2), function(x) x + 2))
expect_equal(capply(data_example,
sqrt),
apply(data_example, c(1, 2), sqrt))
})
# test column_combine
test_that("column_combine returns correct values", {
expect_equal(column_combine(pattern = "scale1",
data = data_example),
c(7, 1.33333333333333,
4,
4.33333333333333,
4.33333333333333,
8.66666666666667,
8.66666666666667))
expect_equal(column_combine(pattern = "scale1",
data = data_example,
fun = sum),
c(21, 4, 12, 13, 13, 26, 26))
expect_equal(column_combine(pattern = "scale1",
data = data_example,
fun = sd),
c(1,
0.577350269189626,
1, 0.577350269189626,
0.577350269189626,
0.577350269189626,
0.577350269189626))
expect_equal(column_combine(pattern = "scale1",
data = data_example,
fun = sd,
message = FALSE),
c(1,
0.577350269189626,
1, 0.577350269189626,
0.577350269189626,
0.577350269189626,
0.577350269189626))
expect_message(column_combine(pattern = "scale1",
data = data_example,
fun = sd),
"A composite column was calculated using 3 columns: scale1_")
expect_message(column_combine(pattern = "scale1",
data = data_example,
fun = sd,
message = FALSE),
NA)
})
# test group_compare
test_that("group_compare returns correct values", {
expect_equal(group_compare(data_example_2,
cols = c("mach", "narc"),
split = "group"),
structure(list(term = c("mach", "narc"),
overall_m = c(126.25, 243.2),
overall_sd = c(137.588153559818,
314.250006629541),
overall_n = c(8, 10),
group1_m = c(2.5, 5.33333333333333),
group1_sd = c(0.577350269189626,
3.72379734500505),
group1_n = c(4, 6),
group2_m = c(250, 600),
group2_sd = c(57.7350269189626,
115.470053837925),
group2_n = c(4, 4),
t = c(-8.57322284703958, -10.2963600160198),
df = c(3.000599999994, 3.00416057565331),
p = c(0.00333298849657998,
0.00194201346275585),
d = c(-6.06218401176513, -6.64627181143344)),
class = "data.frame",
row.names = c(NA, -2L)))
expect_equal(group_compare(data_example_2,
cols = c("mach", "narc"),
split = "group",
spround = TRUE),
structure(list(term = c("mach", "narc"),
overall_m = c("126.25", "243.20"),
overall_sd = c("137.59", "314.25"),
overall_n = c("8.00", "10.00"),
group1_m = c("2.50", "5.33"),
group1_sd = c("0.58", "3.72"),
group1_n = c("4.00", "6.00"),
group2_m = c("250.00", "600.00"),
group2_sd = c("57.74", "115.47"),
group2_n = c("4.00", "4.00"),
t = c("-8.57", "-10.30"),
df = c("3", "3"),
p = c(".003", ".002"),
d = c("-6.06", "-6.65")),
class = "data.frame",
row.names = c(NA, -2L)))
expect_equal(group_compare(data_example_2,
cols = c("mach", "narc"),
split = "group",
spround = TRUE,
spround.p = FALSE),
structure(list(term = c("mach", "narc"),
overall_m = c("126.25", "243.20"),
overall_sd = c("137.59", "314.25"),
overall_n = c("8.00", "10.00"),
group1_m = c("2.50", "5.33"),
group1_sd = c("0.58", "3.72"),
group1_n = c("4.00", "6.00"),
group2_m = c("250.00", "600.00"),
group2_sd = c("57.74", "115.47"),
group2_n = c("4.00", "4.00"),
t = c("-8.57", "-10.30"),
df = c("3", "3"),
p = c(0.003332988496579981398116,
0.001942013462755851679192),
d = c("-6.06", "-6.65")),
class = "data.frame",
row.names = c(NA, -2L)))
expect_equal(group_compare(data_example_2,
cols = c("mach", "narc"),
split = "group",
spround = TRUE,
collapse = TRUE),
structure(list(term = c("mach", "narc"),
overall_msd = c("126.25 (137.59)",
"243.20 (314.25)"),
overall_n = c("8.00", "10.00"),
group1_msd = c("2.50 (0.58)", "5.33 (3.72)"),
group1_n = c("4.00", "6.00"),
group2_msd = c("250.00 (57.74)",
"600.00 (115.47)"),
group2_n = c("4.00", "4.00"),
t = c("-8.57", "-10.30"),
df = c("3", "3"),
p = c(".003", ".002"),
d = c("-6.06", "-6.65")),
class = "data.frame",
row.names = c(NA, -2L)))
expect_equal(group_compare(data_example_2,
cols = c("mach", "narc"),
split = "group")[1, "df"],
unname(t.test(subset(data_example_2,
group == "A")$mach,
subset(data_example_2,
group == "B")$mach)$parameter))
expect_equal(group_compare(data_example_2,
cols = c("mach", "narc"),
split = "group")[1, "p"],
unname(t.test(subset(data_example_2,
group == "A")$mach,
subset(data_example_2,
group == "B")$mach)$p.value))
expect_equal(group_compare(data_example_2,
cols = c("mach", "narc"),
split = "group")[1, "t"],
unname(t.test(subset(data_example_2,
group == "A")$mach,
subset(data_example_2,
group == "B")$mach)$statistic))
expect_equal(group_compare(data_example_2,
cols = c("mach", "narc"),
split = "group")[1, "group1_m"],
unname(t.test(subset(data_example_2,
group == "A")$mach,
subset(data_example_2,
group == "B")$mach)$estimate[1]))
expect_equal(group_compare(data_example_2,
cols = c("mach", "narc"),
split = "group")[1, "group2_m"],
unname(t.test(subset(data_example_2,
group == "A")$mach,
subset(data_example_2,
group == "B")$mach)$estimate[2]))
expect_equal(group_compare(data_example_2,
cols = c("mach", "narc", "psyc"),
split = "group",
adjust.p = "holm")[, "p"],
p.adjust(group_compare(data_example_2,
cols = c("mach", "narc", "psyc"),
split = "group")[, "p"],
method = "holm",
n = 3))
expect_equal(group_compare(data_example_2,
cols = c("mach", "narc", "psyc"),
split = "group",
adjust.d = TRUE)[, "d"],
c(-5.27146435805663, -6.00308421677859, -19.1461294666445))
expect_equal(group_compare(data_example_2,
cols = c("mach", "narc", "psyc"),
split = "group",
adjust.p = "bonferroni")[1, "p"],
p.adjust(unname(t.test(subset(data_example_2,
group == "A")$mach,
subset(data_example_2,
group == "B")$mach)$p.value),
method = "bonferroni", n = 3))
expect_equal(group_compare(data_example_2,
cols = c("mach", "narc"),
split = "group",
var.equal = TRUE)[1, "df"],
unname(t.test(subset(data_example_2,
group == "A")$mach,
subset(data_example_2,
group == "B")$mach,
var.equal = TRUE)$parameter))
expect_equal(group_compare(data_example_2,
cols = c("mach", "narc"),
split = "group",
var.equal = TRUE)[1, "p"],
unname(t.test(subset(data_example_2,
group == "A")$mach,
subset(data_example_2,
group == "B")$mach,
var.equal = TRUE)$p.value))
expect_equal(group_compare(data_example_2,
cols = c("mach", "narc"),
split = "group",
var.equal = TRUE)[1, "t"],
unname(t.test(subset(data_example_2,
group == "A")$mach,
subset(data_example_2,
group == "B")$mach,
var.equal = TRUE)$statistic))
expect_error(group_compare(data_example_3,
cols = c("mach", "narc"),
split = "group"),
"group_compare is only able to compare two groups.")
})
# test spround
test_that("spround returns correct values", {
expect_equal(spround(x = 0.001, digits = 2, leading0 = TRUE), "0.00")
expect_equal(spround(x = 0.001, digits = 3, leading0 = TRUE), "0.001")
expect_equal(spround(x = 0.001, digits = 3, leading0 = FALSE), ".001")
expect_equal(spround(x = 0.06, digits = 1, leading0 = FALSE), ".1")
expect_equal(spround(x = 0.001, digits = 2, leading0 = TRUE, less_than = TRUE),
"< 0.01")
expect_equal(spround(x = 0.001, digits = 2, leading0 = FALSE,
less_than = TRUE),
"< .01")
expect_equal(spround(x = 0.0005, digits = 3, leading0 = FALSE,
less_than = TRUE),
"< .001")
expect_equal(spround(x = 0.001, digits = 0, less_than = FALSE),
"0")
expect_equal(spround(x = 0.001, digits = 0, less_than = TRUE),
"< 1")
expect_equal(spround(x = 10, digits = 2, leading0 = FALSE), "10.00")
expect_equal(spround(x = num_example, digits = 2, leading0 = FALSE),
c("5.00", ".00", ".50", ".10", ".05",
".01", ".00", ".00", ".00"))
})
# test pasterisk
test_that("pasterisk returns correct values", {
expect_equal(pasterisk(num_example),
c("", "***", "", "", "", "*", "**", "**", "***"))
expect_equal(pasterisk(num_example, pad = TRUE),
c(" ", "***", " ", " ", " ", "* ", "** ", "** ", "***"))
expect_equal(pasterisk(num_example, sig_symbol = "+"),
c("", "+++", "", "", "", "+", "++", "++", "+++"))
expect_equal(pasterisk(num_example,
sig_symbol = "+",
thresholds = c(.03, 3)),
c("", "++", "+", "+", "+", "++", "++", "++", "++"))
expect_equal(pasterisk(num_example,
sig_symbol = "+",
thresholds = c(.03, 3),
pad = TRUE),
c(" ", "++", "+ ", "+ ", "+ ", "++", "++", "++", "++"))
expect_equal(pasterisk(num_example,
sig_symbol = "+",
thresholds = c(.03, 3),
pad = TRUE,
pad_symbol = "f"),
c("ff", "++", "+f", "+f", "+f", "++", "++", "++", "++"))
expect_equal(pasterisk(c(5.00, 1.00, .05, .01),
sig_symbol = "+",
thresholds = c(.03, 3),
pad = TRUE,
pad_symbol = "f",
super_script = TRUE),
c("\\textsuperscript{ff}",
"\\textsuperscript{+f}",
"\\textsuperscript{+f}",
"\\textsuperscript{++}"))
})
# test first_diff
test_that("first_diff returns correct values", {
expect_equal(first_diff(num_example),
4.3335)
expect_error(first_diff(char_example),
"x is of type character")
expect_error(first_diff(10),
"The length of x must be between 2 and Inf")
})
# test d
test_that("d returns correct values", {
expect_equal(d(num_example),
structure(list(n = 9,
mean = 0.629611111111111,
sd = 1.64677468437887,
median = 0.01,
min = 0,
max = 5),
row.names = "X1",
class = c("psych",
"Pdescribe",
"data.frame")))
expect_error(d(char_example),
"x is of type character")
expect_error(d(10),
"The length of x must be between 2 and Inf")
})
# test bolder
test_that("bolder returns correct values", {
expect_equal(bolder(num_example),
c("\\textbf{5}", "0", "\\textbf{0.5}", "0.1", "0.05", "0.01",
"0.005", "0.001", "5e-04"))
expect_equal(bolder(num_example, .01),
c("\\textbf{5}", "0", "\\textbf{0.5}", "\\textbf{0.1}",
"\\textbf{0.05}", "\\textbf{0.01}", "0.005", "0.001", "5e-04"))
expect_equal(bolder(c(.001, .05), .01),
c("0.001", "\\textbf{0.05}"))
expect_equal(bolder(c(.001, .05), .01, spround = TRUE),
c("0.00", "\\textbf{0.05}"))
expect_equal(bolder(c(.001, .05), .01, spround = TRUE, leading0 = FALSE),
c(".00", "\\textbf{.05}"))
expect_equal(bolder(c(-.001, -.05), .01, spround = TRUE, leading0 = FALSE),
c("-.00", "\\textbf{-.05}"))
expect_equal(suppressWarnings(bolder(c(".001", ".05"), .01)),
c(".001", "\\textbf{.05}"))
expect_equal(suppressWarnings(bolder(c(".001", ".05"), .01, spround = TRUE)),
c("0.00", "\\textbf{0.05}"))
expect_error(bolder(num_example, "hello"),
"threshold is of type")
expect_error(bolder(num_example, c(.10, 1)),
"threshold must be of")
expect_error(bolder(char_example, .10),
"could not be coerced to type numeric")
expect_warning(bolder(c(".001", ".05"), .01),
"ef was coerced to type numeric")
})
# test text_format
test_that("text_format returns correct values", {
expect_equal(text_format("hello", format = "italic", latex = TRUE),
"\\textit{hello}")
expect_equal(text_format("hello", format = "bold", latex = TRUE),
"\\textbf{hello}")
expect_equal(italic_tex("hello"),
"\\textit{hello}")
expect_equal(bold_tex("hello"),
"\\textbf{hello}")
expect_equal(text_format("hello", format = "italic"),
"*hello*")
expect_equal(text_format("hello", format = "bold"),
"**hello**")
expect_equal(italic("hello"),
"*hello*")
expect_equal(bold("hello"),
"**hello**")
expect_equal(text_format("hello", format = "super", latex = TRUE),
"\\textsuperscript{hello}")
expect_equal(text_format("hello", format = "sub", latex = TRUE),
"\\textsubscript{hello}")
expect_equal(text_format("hello", format = "super", latex = FALSE),
"^hello^")
expect_equal(text_format("hello", format = "sub", latex = FALSE),
"~hello~")
expect_warning(text_format("hello", format = "akfeknfajkn", latex = TRUE),
"format must be \"italic\", \"bold\"")
expect_equal(text_format("hello", format = "super", latex = TRUE),
"\\textsuperscript{hello}")
expect_equal(subs_tex("hello"),
"\\textsubscript{hello}")
expect_equal(subs("hello"),
"~hello~")
expect_equal(supers_tex("hello"),
"\\textsuperscript{hello}")
expect_equal(supers("hello"),
"^hello^")
})
# test text_format
test_that("dark returns correct values", {
expect_equal(dark(constellation = "triad"),
c("Machiavellianism", "Narcissism", "Psychopathy"))
expect_equal(dark(constellation = "triad",
shorten = TRUE),
c("Mach", "Narc", "Psyc"))
expect_equal(dark(constellation = "triad",
shorten = TRUE,
shorten_length = 5),
c("Machi", "Narci", "Psych"))
expect_equal(dark(constellation = "triad",
shorten = TRUE,
shorten_length = 5,
format = "none"),
c("Machi", "Narci", "Psych"))
expect_equal(dark(constellation = "triad",
shorten = TRUE,
shorten_length = 5,
format = "bold"),
c("**Machi**", "**Narci**", "**Psych**"))
expect_equal(dark(constellation = "triad",
shorten = TRUE,
shorten_length = 5,
format = "bold",
latex = TRUE),
c("\\textbf{Machi}", "\\textbf{Narci}", "\\textbf{Psych}"))
expect_equal(dark(constellation = "tetrad",
shorten = TRUE,
shorten_length = 2,
format = "italic",
latex = TRUE),
c("\\textit{Ma}",
"\\textit{Na}",
"\\textit{Ps}",
"\\textit{Sa}"))
expect_equal(dark_triad(),
c("Machiavellianism", "Narcissism", "Psychopathy"))
expect_equal(dark_tetrad(),
c("Machiavellianism", "Narcissism", "Psychopathy", "Sadism"))
expect_warning(dark("hello"),
"constellation must be \"triad\" or \"tetrad\"")
})
# test scuttle
test_that("scuttle returns correct values", {
expect_equal(scuttle(num_example, split = "quantile"),
factor(c(3L, 1L, 3L, 3L, 2L, 2L, 2L, 1L, 1L),
labels = c("Low", "Mid", "High")))
expect_equal(scuttle(num_example, split = "sd"),
structure(c(3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L),
.Label = c("Low", "Mid", "High"),
class = "factor"))
expect_equal(scuttle(num_example, split = "sd1"),
structure(c(3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L),
.Label = c("Low", "Mid", "High"),
class = "factor"))
expect_equal(scuttle(num_example, split = "sd2"),
structure(c(3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L),
.Label = c("Low", "Mid", "High"),
class = "factor"))
expect_equal(scuttle(num_example, split = "sd3"),
structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L),
.Label = c("Low", "Mid", "High"),
class = "factor"))
expect_equal(scuttle(num_example, split = "se"),
structure(c(3L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L),
.Label = c("Low", "Mid", "High"),
class = "factor"))
expect_equal(scuttle(num_example, split = "se1"),
structure(c(3L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L),
.Label = c("Low", "Mid", "High"),
class = "factor"))
expect_equal(scuttle(num_example, split = "se2"),
structure(c(3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L),
.Label = c("Low", "Mid", "High"),
class = "factor"))
expect_equal(scuttle(num_example, split = "se3"),
structure(c(3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L),
.Label = c("Low", "Mid", "High"),
class = "factor"))
expect_equal(scuttle(num_example,
split = "quantile",
greedy_extremes = FALSE),
factor(c(3L, 1L, 3L, 2L, 2L, 2L, 2L, 2L, 1L),
labels = c("Low", "Mid", "High")))
expect_equal(scuttle(num_example, split = "quantile", as.factor = FALSE),
c("High", "Low", "High", "High", "Mid",
"Mid", "Mid", "Low", "Low"))
expect_warning(scuttle(num_example, split = "hello"), "split options")
})
# test paste_paren
test_that("check paste_paren is combining the values correctly", {
expect_equal(paste_paren(5, 10),
"5 (10)")
expect_equal(paste_paren(20.19, 2.20),
"20.19 (2.2)")
expect_equal(paste_paren("20.19", "2.20"),
"20.19 (2.20)")
expect_warning(paste_paren("20.19", c("2.20", "10.10")),
"The x value")
expect_warning(paste_paren(c("2.20", "10.10"), "20.19"),
regexp = "The y value")
expect_equal(paste_paren(10),
"(10)")
})
# test collapse
test_that("check collapse is collapsing the values correctly", {
expect_equal(collapse(char_example),
"cat + dog + cat + dog + giraffe")
expect_equal(collapse(char_example, sep = ""),
"catdogcatdoggiraffe")
expect_error(collapse(char_example, sep = 5),
regexp = "sep must be of type character")
})
# test paren_ci
test_that("check paste_ci is combining the values correctly", {
expect_equal(paste_ci(5, 10),
"[5, 10]")
expect_equal(paste_ci(20.19, 2.20),
"[20.19, 2.2]")
expect_warning(paste_ci("20.19", c("2.20", "10.10")),
"The x value")
expect_warning(paste_ci(c("2.20", "10.10"), "20.19"),
regexp = "The y value")
})
# test perble
test_that("check perble is counting correctly", {
expect_equal(perble(char_example),
structure(list(group = c("cat", "dog", "giraffe"),
count = c(2, 2, 1),
proportion = c(0.4, 0.4, 0.2),
percent = c(40, 40, 20)),
class = "data.frame",
row.names = c(NA, -3L)))
expect_equal(perble(char_example, tidy = FALSE),
structure(c(2, 0.4, 40, 2, 0.4, 40, 1, 0.2, 20),
.Dim = c(3L, 3L),
.Dimnames = list(c("count", "proportion", "percent"),
c("cat", "dog", "giraffe"))))
expect_equal(perble(char_example, spround = TRUE),
structure(list(group = c("cat", "dog", "giraffe"),
count = c("2", "2", "1"),
proportion = c(".40", ".40", ".20"),
percent = c("40.00", "40.00", "20.00")),
class = "data.frame",
row.names = c(NA, -3L)))
expect_equal(perble(char_example, tidy = FALSE, spround = TRUE),
structure(c("2", ".40", "40.00", "2", ".40",
"40.00", "1", ".20", "20.00"),
.Dim = c(3L, 3L),
.Dimnames = list(c("count", "proportion", "percent"),
c("cat", "dog", "giraffe"))))
})
# test get_paste
test_that("check that get_paste is working properly", {
expect_equal(get0("me", "an")(c(10, 20, 30, 44)), 26)
expect_equal(get0("s", "d")(c(10, 20, 30, 44)), 14.5143607047182)
})
# test mat_merge
test_that("check that mat_merge is working properly", {
expect_equal(mat_merge(mat_a,
mat_b,
x_from = "lower",
y_from = "lower",
x_to = "lower",
y_to = "upper"),
matrix(c(0, 0.000816982970622438, 0.00454442781824798,
0.0224521374608249, 0.0121453149631062,
0.524317457207586, 0, 0.00162131724305212,
0.115015191468429, 0.0646228152839355,
0.459483927231542, 0.947112709264432,
0, 0.203212111846573, 0.0747737723517703,
0.508791133749554, 0.059078101909081, 0.293710028165101,
0, 0.00288053250708112, 0.486228731120195,
0.352390494682801, 0.063056705312586, 0.668811955414348,
0), nrow = 5))
expect_equal(mat_merge(mat_a,
mat_b,
x_from = "lower",
y_from = "lower",
x_to = "lower",
y_to = "upper"),
matrix(c(0, 0.000816982970622438, 0.00454442781824798,
0.0224521374608249, 0.0121453149631062, 0.524317457207586,
0, 0.00162131724305212, 0.115015191468429,
0.0646228152839355, 0.459483927231542, 0.947112709264432,
0, 0.203212111846573, 0.0747737723517703,
0.508791133749554, 0.059078101909081, 0.293710028165101,
0, 0.00288053250708112, 0.486228731120195,
0.352390494682801, 0.063056705312586, 0.668811955414348,
0), nrow = 5))
expect_equal(mat_merge(mat_a,
mat_b,
x_from = "upper",
y_from = "lower",
x_to = "lower",
y_to = "upper"),
matrix(c(0, 0.00816982970622438, 0.0318109947277359,
0.112260687304124, 0.072871889778637, 0.524317457207586,
0, 0.014591855187469, 0.258491261135742,
0.258491261135742, 0.459483927231542, 0.947112709264432,
0, 0.258491261135742, 0.258491261135742,
0.508791133749554, 0.059078101909081, 0.293710028165101,
0, 0.023044260056649, 0.486228731120195,
0.352390494682801, 0.063056705312586, 0.668811955414348,
0), nrow = 5))
expect_equal(mat_merge(mat_a,
mat_b,
x_from = "upper",
y_from = "lower",
x_to = "upper",
y_to = "lower"),
structure(c(0, 0.524317457207586, 0.459483927231542,
0.508791133749554, 0.486228731120195,
0.00816982970622438, 0, 0.947112709264432,
0.059078101909081, 0.352390494682801,
0.0318109947277359, 0.014591855187469,
0, 0.293710028165101, 0.063056705312586,
0.112260687304124, 0.258491261135742,
0.258491261135742, 0, 0.668811955414348,
0.072871889778637, 0.258491261135742,
0.258491261135742, 0.023044260056649, 0),
.Dim = c(5L, 5L)))
expect_error(mat_merge(mat_a,
mat_b,
x_from = "lower",
y_from = "lower",
x_to = "lower",
y_to = "lower"),
"quadrant")
expect_error(mat_merge(mat_a,
mat_b,
x_from = "lower",
y_from = "lower",
x_to = "upper",
y_to = "upper"),
"quadrant")
expect_error(mat_merge(mat_a,
mat_b,
x_from = "hello",
y_from = "lower",
x_to = "upper",
y_to = "upper"),
"x_from")
expect_error(mat_merge(mat_a,
mat_b,
x_from = "lower",
y_from = "hello",
x_to = "upper",
y_to = "upper"),
"y_from")
expect_error(mat_merge(mat_a,
mat_b,
x_from = "lower",
y_from = "lower",
x_to = "hello",
y_to = "upper"),
"x_to")
expect_error(mat_merge(mat_a,
mat_b,
x_from = "lower",
y_from = "lower",
x_to = "upper",
y_to = "hello"),
"y_to")
})
# test center
test_that("check that center is producing the correct results", {
expect_equal(scale(num_example, scale = FALSE, center = TRUE),
center(num_example))
expect_false(isTRUE(all.equal(scale(num_example, scale = TRUE, center = TRUE),
center(num_example))))
expect_false(isTRUE(all.equal(scale(num_example, scale = TRUE, center = TRUE),
centre(num_example))))
expect_equal(centre(num_example),
center(num_example))
})
# test build_models
test_that("check that build_models is producing the correct results", {
expect_equal(build_models("mpg", list("1", "hp", c("vs", "am"))),
c("mpg ~ 1", "mpg ~ 1 + hp", "mpg ~ 1 + hp + vs + am"))
expect_equal(build_models("mpg", list("1", "hp", "am")),
c("mpg ~ 1", "mpg ~ 1 + hp", "mpg ~ 1 + hp + am"))
expect_equal(build_models("mpg", list("1", "hp",
c("vs", "am"),
c("hp * vs", "hp * am"))),
c("mpg ~ 1",
"mpg ~ 1 + hp",
"mpg ~ 1 + hp + vs + am",
"mpg ~ 1 + hp + vs + am + hp * vs + hp * am"))
})
# test profile
test_that("check that profile is working properly", {
expect_equal(round(profile(data_example_profile), 7),
-0.5151515)
expect_equal(round(profile(data_example_profile, "r"), 7),
1.0000000)
expect_error(profile(data_example),
"data must be of length 2. data is of length 5.")
expect_error(profile("hello"),
"data is of type character. data must be of type data.frame.")
expect_error(profile(data_example_profile, 8),
"method is of type double. method must be of type character.")
expect_warning(profile(data_example_profile, "hello"),
"is not a recognized method")
})
# test delta_rsq, delta_aic, and delta_bic
test_that("check that delta_rsq is working properly", {
expect_equal(delta_rsq(list(mod_a_example,
mod_b_example,
mod_c_example)),
structure(list(model = c("mod_a_example",
"mod_b_example",
"mod_c_example"),
delta_rsq = c(NA,
0.0711523789754419,
0.238642252570856)),
class = "data.frame",
row.names = c(NA, -3L)))
expect_equal(delta_rsq(list(mod_a_example,
mod_b_example,
mod_c_example), adjusted = TRUE),
structure(list(model = c("mod_a_example",
"mod_b_example",
"mod_c_example"),
delta_rsq_adj = c(NA,
0.0107341217334221,
0.352869950079865)),
class = "data.frame", row.names = c(NA, -3L)))
expect_error(delta_rsq(list(mod_a_example)),
paste0("The length of models must be between 2 and Inf ",
"\\(inclusive\\)\\. models is of length 1\\."))
expect_error(delta_rsq(list(mod_a_example,
mod_b_example,
mod_c_example),
adjusted = "hello"),
"adjusted must be of type logical.")
expect_error(delta_rsq(list(mod_a_example,
mod_b_example,
mod_c_example),
adjusted = c(TRUE, TRUE)),
"adjusted must be of length 1. adjusted is of length 2.")
})
test_that("check that delta_aic is working properly", {
expect_equal(delta_aic(list(mod_a_example,
mod_b_example,
mod_c_example)),
structure(list(model = c("mod_a_example",
"mod_b_example",
"mod_c_example"),
delta_aic = c(NA,
0.239522459992067,
-20.3696755929175)),
class = "data.frame",
row.names = c(NA, -3L)))
expect_error(delta_aic(list(mod_a_example)),
paste0("The length of models must be between 2 and Inf ",
"\\(inclusive\\)\\. models is of length 1\\."))
})
test_that("check that delta_bic is working properly", {
expect_equal(delta_bic(list(mod_a_example,
mod_b_example,
mod_c_example)),
structure(list(model = c("mod_a_example",
"mod_b_example",
"mod_c_example"),
delta_bic = c(NA,
0.185432609047382,
-20.4237654438622)),
class = "data.frame",
row.names = c(NA, -3L)))
expect_error(delta_bic(list(mod_a_example)),
paste0("The length of models must be between 2 and Inf ",
"\\(inclusive\\)\\. models is of length 1\\."))
})
test_that("check that tidy_std is working properly", {
expect_equal(tidy_std(mod_b_example),
structure(list(term = c("(Intercept)", "scale2_item1",
"scale2_item2"
), df = c(4L, 4L, 4L), estimate = c(10.0792602377807, -0.158520475561429,
-0.685601056803169), se = c(1.55311554460448, 0.58520326463724,
0.641058057534963), conf.low = c(5.76712018615702, -1.78330521520926,
-2.46546356279372), conf.high = c(14.3914002894044, 1.4662642640864,
1.09426144918738), estimate_std = c(1.32942805997807e-16, -0.177326030348158,
-0.700112740243083), se_std = c(2.04851877685017e-17, 0.654626927514426,
0.654626927514439), conf.low_std = c(9.27925757550034e-17, -1.46037123158655,
-1.9831579414815), conf.high_std = c(1.73093036240611e-16, 1.10571917089023,
0.58293246099533), statistic = c(6.48970404861124, -0.270881051321021,
-1.06948356509157), p.value = c(0.00290705502443555, 0.799886219422805,
0.345096043318143)), class = "data.frame", row.names = c(NA,
-3L)))
expect_equal(tidy_std(mod_b_example, conf.level = .80),
structure(list(term = c("(Intercept)", "scale2_item1", "scale2_item2"
), df = c(4L, 4L, 4L), estimate = c(10.0792602377807, -0.158520475561429,
-0.685601056803169), se = c(1.55311554460448, 0.58520326463724,
0.641058057534963), conf.low = c(7.69801374045466, -1.05575779250302,
-1.66847529265181), conf.high = c(12.4605067351068, 0.738716841380163,
0.297273179045475), estimate_std = c(1.32942805997807e-16, -0.177326030348158,
-0.700112740243083), se_std = c(2.04851877685017e-17, 0.654626927514426,
0.654626927514439), conf.low_std = c(1.06689981542609e-16, -1.01626419415192,
-1.53905090404686), conf.high_std = c(1.59195630453006e-16, 0.661612133455607,
0.138825423560699), statistic = c(6.48970404861124, -0.270881051321021,
-1.06948356509157), p.value = c(0.00290705502443555, 0.799886219422805,
0.345096043318143)), class = "data.frame", row.names = c(NA,
-3L)))
expect_error(tidy_std(mod_b_example, conf.level = "hello"),
"conf.level is of type character. conf.level must be of")
})
test_that("check that zo is working properly", {
expect_equal(zo(data_example),
structure(list(`1.` = c("-", ".95***", ".91**",
"-.82*", "-.86*"),
`2.` = c(" ", "-", ".94**",
"-.65", "-.73"),
`3.` = c(" ", " ", "-", "-.55", "-.71"),
`4.` = c(" ", " ", " ", "-", ".92**"),
`5.` = c(" ", " ", " ", " ", "-")),
row.names = c("1. scale1_item1", "2. scale1_item2",
"3. scale1_item3", "4. scale2_item1",
"5. scale2_item2"),
class = "data.frame"))
expect_equal(zo(data_example, method = "kendall"),
structure(list(`1.` = c("-", ".85*", ".72", "-.71", "-.65"),
`2.` = c(" ", "-", ".72", "-.54", "-.45"),
`3.` = c(" ", " ", "-", "-.39", "-.62"),
`4.` = c(" ", " ", " ", "-", ".60"),
`5.` = c(" ", " ", " ", " ", "-")),
row.names = c("1. scale1_item1", "2. scale1_item2",
"3. scale1_item3", "4. scale2_item1",
"5. scale2_item2"),
class = "data.frame"))
expect_equal(zo(data_example, method = "spearman"),
structure(list(`1.` = c("-", ".93**", ".85*", "-.77*", "-.80*"),
`2.` = c(" ", "-", ".85*", "-.68", "-.61"),
`3.` = c(" ", " ", "-", "-.49", "-.74"),
`4.` = c(" ", " ", " ", "-", ".74"),
`5.` = c(" ", " ", " ", " ", "-")),
row.names = c("1. scale1_item1", "2. scale1_item2",
"3. scale1_item3", "4. scale2_item1",
"5. scale2_item2"),
class = "data.frame"))
expect_equal(zo(data_example_2, split = "group"),
structure(list(`1.` = c("-", "1.00***", "1.00***", "1.00***",
"1.00***"),
`2.` = c("-1.00***", "-", ".96**", ".97**",
".97**"),
`3.` = c("-1.00***", "1.00***", "-",
".87*", ".87*"),
`4.` = c("-1.00***", "1.00***", "1.00***", "-",
"1.00***"),
`5.` = c("-1.00***", "1.00***", "1.00***",
"1.00***", "-")),
row.names = c("1. mach", "2. narc", "3. psyc",
"4. des", "5. mor"),
class = "data.frame"))
expect_equal(zo(data_example_2, split = "group", cols = c("psyc",
"mor",
"des")),
structure(list(`1.` = c("-", ".87*", ".87*"),
`2.` = c("1.00***", "-", "1.00***"),
`3.` = c("1.00***", "1.00***", "-")),
row.names = c("1. psyc", "2. mor", "3. des"),
class = "data.frame"))
expect_equal(zo(data_example_2, split = "group",
cols = c("psyc", "mor", "des"),
adjust.p = "holm"),
structure(list(`1.` = c("-", ".87", ".87"),
`2.` = c("1.00***", "-", "1.00***"),
`3.` = c("1.00***", "1.00***", "-")),
row.names = c("1. psyc", "2. mor", "3. des"),
class = "data.frame"))
expect_equal(zo(data_example_2, split = "group",
cols = c("psyc", "mor", "des"),
adjust.p = "holm",
spround = FALSE),
structure(list(`1.` = c("-", "0.866025403784439",
"0.866025403784439"),
`2.` = c("1***", "-", "1***"),
`3.` = c("1***", "1***", "-")),
row.names = c("1. psyc", "2. mor", "3. des"),
class = "data.frame"))
expect_equal(zo(data_example_2, split = "group",
cols = c("psyc", "mor", "des"),
adjust.p = "holm",
spround = FALSE,
pasterisk = FALSE),
structure(list(psyc_r = c(1, 0.866025403784439,
0.866025403784439),
mor_r = c(1, 1, 1),
des_r = c(1, 1, 1),
psyc_p = c(0, 0.0514428414850131,
0.0514428414850131),
mor_p = c(0, 0, 0),
des_p = c(0, 0, 0)),
class = "data.frame",
row.names = c("1. psyc", "2. mor", "3. des")))
expect_equal(zo(data_example_2, split = "group",
cols = c("psyc", "mor", "des"),
adjust.p = "holm",
spround = TRUE,
pasterisk = FALSE),
structure(list(psyc_r = c("1.00", ".87",
".87"),
mor_r = c("1.00", "1.00", "1.00"),
des_r = c("1.00", "1.00", "1.00"),
psyc_p = c(".000", ".051",
".051"),
mor_p = c("-.000", ".000", "-.000"),
des_p = c("-.000", "-.000", ".000")),
class = "data.frame",
row.names = c("1. psyc", "2. mor", "3. des")))
expect_equal(zo(data_example_2, split = "group",
cols = c("psyc", "mor"), pad = TRUE, pad_symbol = "f"),
structure(list(`1.` = c("-", ".87*ff"),
`2.` = c("1.00***", "-")),
row.names = c("1. psyc", "2. mor"),
class = "data.frame"))
expect_equal(zo(data_example_2, split = "group",
cols = c("psyc", "mor"), pad = TRUE, pad_symbol = "f",
bold_script = TRUE),
structure(list(`1.` = c("-", "\\textbf{.87}*ff"),
`2.` = c("\\textbf{1.00}***", "-")),
row.names = c("1. psyc", "2. mor"),
class = "data.frame"))
expect_equal(zo(data_example_2, split = "group",
cols = c("psyc", "mor"), pad = TRUE, pad_symbol = "f",
bold_script = TRUE, bold_val = .9),
structure(list(`1.` = c("-", ".87*ff"),
`2.` = c("\\textbf{1.00}***", "-")),
row.names = c("1. psyc", "2. mor"),
class = "data.frame"))
expect_message(zo(data_example_2, split = "group"),
"A is below the diagonal")
expect_error(zo(data_example_2, split = "group", cols = c("mch", "nrc")),
"cols not found in data: mch, nrc")
expect_error(zo(data_example_2, split = "group", cols = c("mach")),
"The length of cols must be between 2 and Inf \\(inclusive\\).")
expect_error(zo(data_example_3, split = "group", cols = c("mach", "narc")),
"zo is only able to distinguish between 2 groups")
expect_error(zo(data_example_2, split = "group"),
NA)
expect_warning(zo(data_example, method = "what"),
"is not a recognized method")
})
test_that("check that compare_rs is working properly", {
expect_equal(compare_rs(mat_d,
predictors = c("scale1_item1",
"scale1_item2",
"scale1_item3"),
outcome = "scale2_item2",
adjust.p = "none",
threshold = .05)$comparisons[1, "n"],
floor(mean(c(mat_d$n["scale2_item2", "scale1_item1"],
mat_d$n["scale2_item2", "scale1_item2"])))
)
expect_equal(compare_rs(mat_d,
predictors = c("scale1_item1",
"scale1_item2",
"scale1_item3"),
outcome = "scale2_item2",
adjust.p = "none",
threshold = .05)$comparisons[2, "n"],
floor(mean(c(mat_d$n["scale2_item2", "scale1_item1"],
mat_d$n["scale2_item2", "scale1_item3"])))
)
expect_equal(compare_rs(mat_d,
predictors = c("scale1_item1",
"scale1_item2",
"scale1_item3"),
outcome = "scale2_item2",
adjust.p = "none",
threshold = .05)$comparisons[3, "n"],
floor(mean(c(mat_d$n["scale2_item2", "scale1_item2"],
mat_d$n["scale2_item2", "scale1_item3"])))
)
expect_equal(compare_rs(mat_c,
predictors = c("scale1_item1",
"scale1_item2",
"scale1_item3"),
outcome = "scale2_item2",
adjust.p = "none",
threshold = .05)$comparisons[1, "p"],
cocor::cocor.dep.groups.overlap(
r.jk = mat_c$r["scale2_item2", "scale1_item1"],
r.jh = mat_c$r["scale2_item2", "scale1_item2"],
r.kh = mat_c$r["scale1_item1", "scale1_item2"],
n = mat_c$n,
return.htest = TRUE)$hittner2003$p.value
)
expect_equal(compare_rs(mat_c,
predictors = c("scale1_item1",
"scale1_item2",
"scale1_item3"),
outcome = "scale2_item2",
adjust.p = "none",
threshold = .05)$comparisons[1, "statistic"],
cocor::cocor.dep.groups.overlap(
r.jk = mat_c$r["scale2_item2", "scale1_item1"],
r.jh = mat_c$r["scale2_item2", "scale1_item2"],
r.kh = mat_c$r["scale1_item1", "scale1_item2"],
n = mat_c$n,
return.htest = TRUE)$hittner2003$statistic[[1]]
)
expect_equal(compare_rs(mat_c,
predictors = c("scale1_item1",
"scale1_item2",
"scale1_item3"),
outcome = "scale2_item2",
adjust.p = "none",
threshold = .05)$comparisons[2, "p"],
cocor::cocor.dep.groups.overlap(
r.jk = mat_c$r["scale2_item2", "scale1_item1"],
r.jh = mat_c$r["scale2_item2", "scale1_item3"],
r.kh = mat_c$r["scale1_item1", "scale1_item3"],
n = mat_c$n,
return.htest = TRUE)$hittner2003$p.value
)
expect_equal(compare_rs(mat_c,
predictors = c("scale1_item1",
"scale1_item2",
"scale1_item3"),
outcome = "scale2_item1",
adjust.p = "none",
threshold = .05)$comparisons[2, "p"],
cocor::cocor.dep.groups.overlap(
r.jk = mat_c$r["scale2_item1", "scale1_item1"],
r.jh = mat_c$r["scale2_item1", "scale1_item3"],
r.kh = mat_c$r["scale1_item1", "scale1_item3"],
n = mat_c$n,
return.htest = TRUE)$hittner2003$p.value
)
expect_equal(compare_rs(mat_c,
predictors = c("scale1_item1",
"scale1_item2",
"scale1_item3"),
outcome = "scale2_item1",
test = "hotelling1940",
adjust.p = "none",
threshold = .05)$comparisons[2, "p"],
cocor::cocor.dep.groups.overlap(
r.jk = mat_c$r["scale2_item1", "scale1_item1"],
r.jh = mat_c$r["scale2_item1", "scale1_item3"],
r.kh = mat_c$r["scale1_item1", "scale1_item3"],
n = mat_c$n,
return.htest = TRUE)$hotelling1940$p.value
)
expect_equal(compare_rs(mat_c,
predictors = c("scale1_item1",
"scale1_item2",
"scale1_item3"),
outcome = "scale2_item1",
test = "hotelling1940",
adjust.p = "none",
threshold = .05)$cld,
c(scale1_item1 = "a", scale1_item2 = "b", scale1_item3 = "b")
)
expect_equal(compare_rs(mat_c,
predictors = c("scale1_item1",
"scale1_item2",
"scale1_item3"),
outcome = "scale2_item1",
test = "hotelling1940",
adjust.p = "none",
threshold = -Inf)$cld,
c(scale1_item1 = "a", scale1_item2 = "a", scale1_item3 = "a")
)
expect_equal(compare_rs(mat_c,
predictors = c("scale1_item1",
"scale1_item2",
"scale1_item3"),
outcome = "scale2_item2",
adjust.p = "bonferroni",
threshold = .05)$comparisons[1, "p"],
cocor::cocor.dep.groups.overlap(
r.jk = mat_c$r["scale2_item2", "scale1_item1"],
r.jh = mat_c$r["scale2_item2", "scale1_item2"],
r.kh = mat_c$r["scale1_item1", "scale1_item2"],
n = mat_c$n,
return.htest = TRUE)$hittner2003$p.value * 3
)
expect_warning(compare_rs(mat_c,
predictors = c("scale1_item1",
"scale1_item2",
"scale1_item3"),
outcome = "scale2_item1",
test = "hotelling19401",
adjust.p = "none",
threshold = .05),
"is not a recognized test")
expect_error(compare_rs(99,
predictors = c("scale1_item1",
"scale1_item2",
"scale1_item3"),
outcome = "scale2_item1",
test = "hotelling1940",
adjust.p = "none",
threshold = .05),
"cor_mat must be of type list")
expect_error(compare_rs(list(1, 2, 3),
predictors = c("scale1_item1",
"scale1_item2",
"scale1_item3"),
outcome = "scale2_item1",
test = "hotelling1940",
adjust.p = "none",
threshold = .05),
"cor_mat must be of length 14")
expect_error(compare_rs(mat_c,
predictors = c("scale1_item1"),
outcome = "scale2_item2",
adjust.p = "none",
threshold = .05),
"The length of predictors must be between 2 and Inf"
)
expect_error(compare_rs(mat_c,
predictors = c("scale1_item1", "hello"),
outcome = "scale2_item2",
adjust.p = "none",
threshold = .05),
"predictors not found in data"
)
expect_error(compare_rs(mat_c,
predictors = 99,
outcome = "scale2_item2",
adjust.p = "none",
threshold = .05),
"predictors must be of type character"
)
expect_error(compare_rs(mat_c,
predictors = c("scale1_item1",
"scale1_item2",
"scale1_item3"),
outcome = 99,
test = "hotelling1940",
adjust.p = "none",
threshold = .05),
"outcome must be of type character")
expect_error(compare_rs(mat_c,
predictors = c("scale1_item1",
"scale1_item2",
"scale1_item3"),
outcome = c("scale2_item2",
"scale2_item3"),
test = "hotelling1940",
adjust.p = "none",
threshold = .05),
"outcome must be of length 1")
expect_error(compare_rs(mat_c,
predictors = c("scale1_item1",
"scale1_item2",
"scale1_item3"),
outcome = "scale2_item3",
test = "hotelling1940",
adjust.p = "none",
threshold = .05),
"outcome not found in data")
expect_error(compare_rs(mat_c,
predictors = c("scale1_item1",
"scale1_item2",
"scale1_item3"),
outcome = "scale2_item2",
test = 99,
adjust.p = "none",
threshold = .05),
"test must be of type character")
expect_error(compare_rs(mat_c,
predictors = c("scale1_item1",
"scale1_item2",
"scale1_item3"),
outcome = "scale2_item2",
test = c("hittner2003", "hotelling1940"),
adjust.p = "none",
threshold = .05),
"test must be of length 1")
expect_error(compare_rs(mat_c,
predictors = c("scale1_item1",
"scale1_item2",
"scale1_item3"),
outcome = "scale2_item2",
test = "hittner2003",
adjust.p = 99,
threshold = .05),
"adjust.p must be of type character")
expect_error(compare_rs(mat_c,
predictors = c("scale1_item1",
"scale1_item2",
"scale1_item3"),
outcome = "scale2_item2",
test = "hittner2003",
adjust.p = c("none", "holm"),
threshold = .05),
"adjust.p is of length 2")
expect_error(compare_rs(mat_c,
predictors = c("scale1_item1",
"scale1_item2",
"scale1_item3"),
outcome = "scale2_item2",
test = "hittner2003",
adjust.p = "none",
threshold = "hello"),
"threshold must be of type numeric")
expect_error(compare_rs(mat_c,
predictors = c("scale1_item1",
"scale1_item2",
"scale1_item3"),
outcome = "scale2_item2",
test = "hittner2003",
adjust.p = "none",
threshold = c(.001, .05)),
"threshold must be of length 1")
})
# test column_message
test_that("check column_message is producing correct messages", {
expect_message(column_message(data_example, "test"),
"test was calculated")
expect_message(column_message(data_example, "test2"),
"test2 was calculated")
expect_message(column_message(data_example, "test", verbose = FALSE),
"and 2 more.")
expect_message(column_message(data_example, "test", verbose = TRUE),
"scale2_item2")
expect_message(column_message(data_example, "test", verbose = TRUE),
"scale2_item2")
expect_error(column_message(column_find("huh",
data_example,
return = "data.frame"),
"test"),
"No columns matched the provided string.")
})
# test argument_check
test_that("check errors is producing errors", {
expect_error(argument_check(300, "x", "character", len_check = TRUE))
expect_error(argument_check(c("h", "i"), "x", "character", len_check = TRUE))
expect_error(argument_check("hello", "x", "data.frame"))
expect_error(argument_check(12, "x", "data.frame"))
expect_error(argument_check(12, "x", "character", len_check = TRUE))
expect_error(argument_check(c(12, 10), "x", "numeric", len_check = TRUE))
expect_error(argument_check(c(12, 10), "x", "numeric",
len_check = TRUE,
len_req = c(1)),
"x must be of length 1. x is of length 2.")
expect_error(argument_check(c(12, 10), "x", "numeric",
len_check = TRUE,
len_req = c(1, 2)),
NA)
expect_error(argument_check(c(12, 10, 20), "x", "numeric",
len_check = TRUE,
len_req = c(1, 2)),
paste0("The length of x must be between 1 and 2 \\(inclusive\\)",
"\\. x is of length 3\\."))
expect_error(argument_check(c(12), "x", "numeric",
len_check = TRUE,
len_req = c(2, 9)),
paste0("The length of x must be between 2 and 9 \\(inclusive\\)",
"\\. x is of length 1\\."))
})
# choice_check
test_that("check column_choice is producing correct messages", {
expect_warning(choice_check("shark", "animal", char_example),
"\"shark\" is not a recognized animal")
expect_warning(choice_check("shark", "animal", char_example),
"\"cat\" used instead.")
expect_warning(choice_check("shark", "animal", char_example),
"Other options: dog, cat, dog, giraffe.")
expect_equal(suppressWarnings(choice_check("shark",
"animal",
char_example)),
"cat")
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.