library("SimMultiCorrData")
context("Simulate using correlation method 2")
skip_on_cran()
options(scipen = 999)
tol <- 1e-5
set.seed(1234)
n <- 25
cstart1 <- runif(n, min = -2, max = 2)
cstart2 <- runif(n, min = -1, max = 1)
cstart3 <- runif(n, min = -0.5, max = 0.5)
cstartF <- cbind(cstart1, cstart2, cstart3)
set.seed(1234)
cstart1 <- runif(n, min = -2, max = 2)
cstart2 <- runif(n, min = -1, max = 1)
cstart3 <- runif(n, min = -1, max = 1)
cstart4 <- runif(n, min = -0.025, max = 0.025)
cstart5 <- runif(n, min = -0.025, max = 0.025)
cstartP <- cbind(cstart1, cstart2, cstart3, cstart4, cstart5)
L <- calc_theory("Logistic", c(0, 1))
Six <- list(seq(1.7, 1.8, 0.01))
marginal <- list(0.3)
lam <- 0.5
pois_eps <- 0.0001
size <- 2
prob <- 0.75
mu <- size * (1 - prob)/prob
nb_eps <- 0.0001
Rey <- matrix(0.4, 4, 4)
diag(Rey) <- 1
test_that("works for 0 continuous, 1 ordinal, 1 Poisson, 1 NB", {
expect_equal(all.equal(rcorrvar2(k_cat = 1, k_pois = 1, k_nb = 1,
marginal = marginal, support = list(c(0, 1)), lam = lam,
pois_eps = pois_eps, size = size, nb_eps = nb_eps,
prob = prob, rho = Rey[1:3, 1:3])$maxerr, 0.007967684,
tolerance = tol, check.attributes = FALSE), TRUE)
expect_equal(all.equal(rcorrvar2(k_cat = 1, k_pois = 1, k_nb = 1,
marginal = marginal, support = list(c(0, 1)), lam = lam,
pois_eps = pois_eps, size = size, nb_eps = nb_eps,
mu = mu, rho = Rey[1:3, 1:3])$maxerr, 0.007967684,
tolerance = tol, check.attributes = FALSE), TRUE)
expect_equal(all.equal(rcorrvar2(k_cat = 1, k_pois = 1, k_nb = 1,
marginal = marginal, support = list(c(0, 1)), lam = lam,
pois_eps = pois_eps, size = size, nb_eps = nb_eps,
prob = prob, rho = Rey[1:3, 1:3], errorloop = TRUE)$maxerr, 0.0009919255,
tolerance = tol, check.attributes = FALSE), TRUE)
})
test_that("works for Fleishman method: 1 continuous, 1 ordinal, 1 Poisson,
1 NB", {
expect_equal(all.equal(rcorrvar2(k_cont = 1, k_cat = 1, k_pois = 1, k_nb = 1,
method = "Fleishman", means = L[1], vars = L[2]^2, skews = L[3],
skurts = L[4], marginal = marginal, support = list(c(0, 1)),
lam = lam, pois_eps = pois_eps, size = size, nb_eps = nb_eps,
prob = prob, rho = Rey)$constants[1, "c3"], 0.03605955,
tolerance = tol, check.attributes = FALSE), TRUE)
expect_equal(all.equal(rcorrvar2(k_cont = 1, k_cat = 1, k_pois = 1, k_nb = 1,
method = "Fleishman", means = L[1], vars = L[2]^2, skews = L[3],
skurts = L[4], marginal = marginal, support = list(c(0, 1)),
lam = lam, pois_eps = pois_eps, size = size, nb_eps = nb_eps, mu = mu,
rho = Rey, cstart = list(cstartF))$constants[1, "c3"], 0.03605955,
tolerance = tol, check.attributes = FALSE), TRUE)
expect_equal(all.equal(rcorrvar2(k_cont = 1, k_cat = 1, k_pois = 1, k_nb = 1,
method = "Fleishman", means = L[1], vars = L[2]^2, skews = L[3],
skurts = L[4], marginal = marginal, support = list(c(0, 1)),
lam = lam, pois_eps = pois_eps, size = size, nb_eps = nb_eps, prob = prob,
rho = Rey, errorloop = TRUE)$constants[1, "c3"], 0.03605955,
tolerance = tol, check.attributes = FALSE), TRUE)
})
test_that("works for Fleishman method: 1 continuous, 0 ordinal, 1 Poisson,
1 NB", {
expect_equal(all.equal(rcorrvar2(k_cont = 1, k_cat = 0, k_pois = 1, k_nb = 1,
method = "Fleishman", means = L[1], vars = L[2]^2, skews = L[3],
skurts = L[4], lam = lam, pois_eps = pois_eps, size = size,
nb_eps = nb_eps, prob = prob, rho = Rey[1:3, 1:3])$constants[1, "c3"],
0.03605955, tolerance = tol, check.attributes = FALSE), TRUE)
expect_equal(all.equal(rcorrvar2(k_cont = 1, k_cat = 0, k_pois = 1, k_nb = 1,
method = "Fleishman", means = L[1], vars = L[2]^2, skews = L[3],
skurts = L[4], lam = lam, pois_eps = pois_eps, size = size,
nb_eps = nb_eps, mu = mu, rho = Rey[1:3, 1:3])$constants[1, "c3"],
0.03605955, tolerance = tol, check.attributes = FALSE), TRUE)
expect_equal(all.equal(rcorrvar2(k_cont = 1, k_cat = 0, k_pois = 1, k_nb = 1,
method = "Fleishman", means = L[1], vars = L[2]^2, skews = L[3],
skurts = L[4], lam = lam, pois_eps = pois_eps, size = size,
nb_eps = nb_eps, prob = prob, rho = Rey[1:3, 1:3],
errorloop = TRUE)$constants[1, "c3"], 0.03605955,
tolerance = tol, check.attributes = FALSE), TRUE)
})
test_that("works for Fleishman method: 1 continuous, 1 ordinal, 0 Poisson,
1 NB", {
expect_equal(all.equal(rcorrvar2(k_cont = 1, k_cat = 1, k_pois = 0, k_nb = 1,
method = "Fleishman", means = L[1], vars = L[2]^2, skews = L[3],
skurts = L[4], marginal = marginal, support = list(c(0, 1)),
size = size, nb_eps = nb_eps, prob = prob,
rho = Rey[1:3, 1:3])$constants[1, "c3"], 0.03605955,
tolerance = tol, check.attributes = FALSE), TRUE)
expect_equal(all.equal(rcorrvar2(k_cont = 1, k_cat = 1, k_pois = 0, k_nb = 1,
method = "Fleishman", means = L[1], vars = L[2]^2, skews = L[3],
skurts = L[4], marginal = marginal, support = list(c(0, 1)),
size = size, nb_eps = nb_eps, mu = mu,
rho = Rey[1:3, 1:3])$constants[1, "c3"], 0.03605955,
tolerance = tol, check.attributes = FALSE), TRUE)
expect_equal(all.equal(rcorrvar2(k_cont = 1, k_cat = 1, k_pois = 0, k_nb = 1,
method = "Fleishman", means = L[1], vars = L[2]^2, skews = L[3],
skurts = L[4], marginal = marginal, support = list(c(0, 1)),
size = size, nb_eps = nb_eps, prob = prob, rho = Rey[1:3, 1:3],
errorloop = TRUE)$constants[1, "c3"], 0.03605955,
tolerance = tol, check.attributes = FALSE), TRUE)
})
test_that("works for Fleishman method: 1 continuous, 1 ordinal, 1 Poisson,
0 NB", {
expect_equal(all.equal(rcorrvar2(k_cont = 1, k_cat = 1, k_pois = 1, k_nb = 0,
method = "Fleishman", means = L[1], vars = L[2]^2, skews = L[3],
skurts = L[4], marginal = marginal, support = list(c(0, 1)),
lam = lam, pois_eps = pois_eps, rho = Rey[1:3, 1:3])$constants[1, "c3"],
0.03605955, tolerance = tol, check.attributes = FALSE), TRUE)
expect_equal(all.equal(rcorrvar2(k_cont = 1, k_cat = 1, k_pois = 1, k_nb = 0,
method = "Fleishman", means = L[1], vars = L[2]^2, skews = L[3],
skurts = L[4], marginal = marginal, support = list(c(0, 1)),
lam = lam, pois_eps = pois_eps, rho = Rey[1:3, 1:3],
errorloop = TRUE)$constants[1, "c3"], 0.03605955,
tolerance = tol, check.attributes = FALSE), TRUE)
})
test_that("works for Polynomial method: 1 continuous, 1 ordinal, 1 Poisson,
1 NB", {
expect_equal(all.equal(rcorrvar2(k_cont = 1, k_cat = 1, k_pois = 1, k_nb = 1,
method = "Polynomial", means = L[1], vars = L[2]^2, skews = L[3],
skurts = L[4], fifths = L[5], sixths = L[6], Six = Six,
marginal = marginal, support = list(c(0, 1)), lam = lam,
pois_eps = pois_eps, size = size, prob = prob, nb_eps = nb_eps,
rho = Rey)$constants[1, "c5"], 0.0000006124845,
tolerance = tol, check.attributes = FALSE), TRUE)
expect_equal(all.equal(rcorrvar2(k_cont = 1, k_cat = 1, k_pois = 1, k_nb = 1,
method = "Polynomial", means = L[1], vars = L[2]^2, skews = L[3],
skurts = L[4], fifths = L[5], sixths = L[6], Six = Six,
cstart = list(cstartP), marginal = marginal, support = list(c(0, 1)),
lam = lam, pois_eps = pois_eps, size = size, nb_eps = nb_eps,
mu = mu, rho = Rey)$constants[1, "c5"], 0.0000006125703,
tolerance = tol, check.attributes = FALSE), TRUE)
expect_equal(all.equal(rcorrvar2(k_cont = 1, k_cat = 1, k_pois = 1, k_nb = 1,
method = "Polynomial", means = L[1], vars = L[2]^2, skews = L[3],
skurts = L[4], fifths = L[5], sixths = L[6], Six = Six,
marginal = marginal, support = list(c(0, 1)), lam = lam,
pois_eps = pois_eps, size = size, prob = prob, nb_eps = nb_eps,
rho = Rey, errorloop = TRUE)$constants[1, "c5"],
0.0000006124845, tolerance = tol, check.attributes = FALSE), TRUE)
})
test_that("works for Polynomial method: 1 continuous, 0 ordinal, 1 Poisson,
1 NB", {
expect_equal(all.equal(rcorrvar2(k_cont = 1, k_cat = 0, k_pois = 1, k_nb = 1,
method = "Polynomial", means = L[1], vars = L[2]^2, skews = L[3],
skurts = L[4], fifths = L[5], sixths = L[6], Six = Six,
lam = lam, pois_eps = pois_eps, size = size, nb_eps = nb_eps, prob = prob,
rho = Rey[1:3, 1:3])$constants[1, "c5"], 0.0000006124845,
tolerance = tol, check.attributes = FALSE), TRUE)
expect_equal(all.equal(rcorrvar2(k_cont = 1, k_cat = 0, k_pois = 1, k_nb = 1,
method = "Polynomial", means = L[1], vars = L[2]^2, skews = L[3],
skurts = L[4], fifths = L[5], sixths = L[6], Six = Six,
lam = lam, pois_eps = pois_eps, size = size, nb_eps = nb_eps, mu = mu,
rho = Rey[1:3, 1:3])$constants[1, "c5"], 0.0000006124845,
tolerance = tol, check.attributes = FALSE), TRUE)
expect_equal(all.equal(rcorrvar2(k_cont = 1, k_cat = 0, k_pois = 1, k_nb = 1,
method = "Polynomial", means = L[1], vars = L[2]^2, skews = L[3],
skurts = L[4], fifths = L[5], sixths = L[6], Six = Six,
lam = lam, pois_eps = pois_eps, size = size, nb_eps = nb_eps,
prob = prob, rho = Rey[1:3, 1:3], errorloop = TRUE)$constants[1, "c5"],
0.0000006124845, tolerance = tol, check.attributes = FALSE), TRUE)
})
test_that("works for Polynomial method: 1 continuous, 1 ordinal, 0 Poisson,
1 NB", {
expect_equal(all.equal(rcorrvar2(k_cont = 1, k_cat = 1, k_pois = 0, k_nb = 1,
method = "Polynomial", means = L[1], vars = L[2]^2, skews = L[3],
skurts = L[4], fifths = L[5], sixths = L[6], Six = Six,
marginal = marginal, support = list(c(0, 1)), size = size, nb_eps = nb_eps,
prob = prob, rho = Rey[1:3, 1:3])$constants[1, "c5"], 0.0000006124845,
tolerance = tol, check.attributes = FALSE), TRUE)
expect_equal(all.equal(rcorrvar2(k_cont = 1, k_cat = 1, k_pois = 0, k_nb = 1,
method = "Polynomial", means = L[1], vars = L[2]^2, skews = L[3],
skurts = L[4], fifths = L[5], sixths = L[6], Six = Six,
marginal = marginal, support = list(c(0, 1)), size = size,
nb_eps = nb_eps, mu = mu, rho = Rey[1:3, 1:3])$constants[1, "c5"],
0.0000006124845, tolerance = tol, check.attributes = FALSE), TRUE)
expect_equal(all.equal(rcorrvar2(k_cont = 1, k_cat = 1, k_pois = 0, k_nb = 1,
method = "Polynomial", means = L[1], vars = L[2]^2, skews = L[3],
skurts = L[4], fifths = L[5], sixths = L[6], Six = Six,
marginal = marginal, support = list(c(0, 1)), size = size,
nb_eps = nb_eps, prob = prob, rho = Rey[1:3, 1:3],
errorloop = TRUE)$constants[1, "c5"], 0.0000006124845,
tolerance = tol, check.attributes = FALSE), TRUE)
})
test_that("works for Polynomial method: 1 continuous, 1 ordinal, 1 Poisson,
0 NB", {
expect_equal(all.equal(rcorrvar2(k_cont = 1, k_cat = 1, k_pois = 1, k_nb = 0,
method = "Polynomial", means = L[1], vars = L[2]^2, skews = L[3],
skurts = L[4], fifths = L[5], sixths = L[6], Six = Six,
marginal = marginal, support = list(c(0, 1)), lam = lam,
pois_eps = pois_eps, rho = Rey[1:3, 1:3])$constants[1, "c5"],
0.0000006124845, tolerance = tol, check.attributes = FALSE), TRUE)
expect_equal(all.equal(rcorrvar2(k_cont = 1, k_cat = 1, k_pois = 1, k_nb = 0,
method = "Polynomial", means = L[1], vars = L[2]^2, skews = L[3],
skurts = L[4], fifths = L[5], sixths = L[6], Six = Six,
marginal = marginal, support = list(c(0, 1)), lam = lam,
pois_eps = pois_eps, rho = Rey[1:3, 1:3],
errorloop = TRUE)$constants[1, "c5"], 0.0000006124845,
tolerance = tol, check.attributes = FALSE), TRUE)
})
Rey2 <- matrix(0.4, 5, 5)
diag(Rey2) <- 1
test_that("works for Polynomial method: same continuous distribution", {
expect_equal(all.equal(rcorrvar2(k_cont = 2, k_cat = 1, k_pois = 1, k_nb = 1,
method = "Polynomial", means = rep(L[1], 2), vars = rep(L[2]^2, 2),
skews = rep(L[3], 2), skurts = rep(L[4], 2), fifths = rep(L[5], 2),
sixths = rep(L[6], 2), Six = list(1.75, 1.75),
marginal = marginal, support = list(c(0, 1)), lam = lam,
pois_eps = pois_eps, size = size, prob = prob, nb_eps = nb_eps,
rho = Rey2)$constants[1, "c5"], 0.0000006124845,
tolerance = tol, check.attributes = FALSE), TRUE)
expect_equal(all.equal(rcorrvar2(k_cont = 2, k_cat = 1, k_pois = 1, k_nb = 1,
method = "Polynomial", means = rep(L[1], 2), vars = rep(L[2]^2, 2),
skews = rep(L[3], 2), skurts = rep(L[4], 2), fifths = rep(L[5], 2),
sixths = rep(L[6], 2), Six = list(1.75, 1.75), marginal = marginal,
support = list(c(0, 1)), lam = lam, pois_eps = pois_eps, size = size,
prob = prob, nb_eps = nb_eps, rho = Rey2,
errorloop = TRUE)$constants[1, "c5"], 0.0000006124845,
tolerance = tol, check.attributes = FALSE), TRUE)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.