context("Correlation Matrices")
test_that("correlations between categeorical variables of design points are computed correctly", {
x = data.frame(v = c("a", "b", "a", "c", "b"))
## EC
cat.corr = getCatCorrMatrix(x, cat.type = "EC", c(0, 0.4), q = 1, design.corr = TRUE)
exp = sapply(1:5, function(i) x$v[i] == x$v)
exp[exp] = 1
exp[exp == 0] = 0.4
expect_equal(cat.corr, exp)
cat.corr = getCatCorrMatrix(x, cat.type = "EC", c(0, 0.4), q = 1, design.corr = FALSE)
exp = diag(3)
exp[exp == 0] = 0.4
expect_equal(cat.corr, exp)
## MC
cat.corr = getCatCorrMatrix(x, cat.type = "MC", c(0, log(2), log(4), log(8)), q = 1,
design.corr = TRUE)
expect_equal(cat.corr, matrix(c(1, 1/8, 1, 1/16, 1/8,
1/8, 1, 1/8, 1/32, 1,
1, 1/8, 1, 1/16, 1/8,
1/16, 1/32, 1/16, 1, 1/32,
1/8, 1, 1/8, 1/32, 1 ),
nrow = 5, byrow = TRUE))
cat.corr = getCatCorrMatrix(x, cat.type = "MC", c(0, log(2), log(4), log(8)), q = 1,
design.corr = FALSE)
expect_equal(cat.corr, matrix(c(1, 1/8, 1/16,
1/8, 1, 1/32,
1/16, 1/32, 1 ),
nrow = 3, byrow = TRUE))
## UC
cat.corr = getCatCorrMatrix(x, cat.type = "UC", c(0, 2.5, 0.3, 1.6), q = 1,
design.corr = TRUE)
expect_equal(round(cat.corr, 3), matrix(c(1, -0.801, 1, 0.955, -0.801,
-0.801, 1, -0.801, -0.771, 1,
1, -0.801, 1, 0.955, -0.801,
0.955, -0.771, 0.955, 1, -0.771,
-0.801, 1, -0.801, -0.771, 1 ),
nrow = 5, byrow = TRUE))
cat.corr = getCatCorrMatrix(x, cat.type = "UC", c(0, 2.5, 0.3, 1.6), q = 1,
design.corr = FALSE)
expect_equal(round(cat.corr, 3), matrix(c(1, -0.801, 0.955,
-0.801, 1, -0.771,
0.955, -0.771, 1 ),
nrow = 3, byrow = TRUE))
## TMC
cat.corr = getCatCorrMatrix(x, cat.type = "TMC", c(0, 4, 0.5, 2.5), q = 1,
design.corr = TRUE)
expect_equal(round(cat.corr, 3), matrix(c(1, 0.272, 1, 0.900, 0.272,
0.272, 1, 0.272, 0.272, 1,
1, 0.272, 1, 0.900, 0.272,
0.900, 0.272, 0.900, 1.000, 0.272,
0.272, 1, 0.272, 0.272, 1 ),
nrow = 5, byrow = TRUE))
cat.corr = getCatCorrMatrix(x, cat.type = "TMC", c(0, 4, 0.5, 2.5), q = 1,
design.corr = FALSE)
expect_equal(round(cat.corr, 3), matrix(c(1, 0.272, 0.900,
0.272, 1, 0.272,
0.900, 0.272, 1 ),
nrow = 3, byrow = TRUE))
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.