# Generated by roxytest: Do not edit by hand!
context("File R/qlr_functions.R: @tests")
test_that("Function random_cor_cov() @ L28", {
example_cor = random_cor_cov(size=5, cors="high", sds=c(1,2,3,4,5))
testthat::expect_true(length(names(example_cor))==3)
testthat::expect_true(example_cor$sd[1] == 1)
example_cor = random_cor_cov(size=5, cors="high")
testthat::expect_true(all(example_cor$sd^2 == diag(example_cor$cov.mat)))
})
group_correlations = data.frame(id = c(4,4,4, 3,3,3),
value = c(.1, .2, .3, .1,.1,.1),
v1 = c("a", "a", "b","a", "a", "b"),
v2 = c("b", "c", "c", "b", "c", "c"))
test_that("matrix_lists works", {
expect_equal(matrix_lists(group_correlations)[[2]][1,3], 0.2, tol=.001)
expect_equal(matrix_lists(group_correlations[1:3,])[[1]][1,3], 0.2, tol=.001)
expect_error(matrix_lists(group_correlations, id="id2"))
})
test_that("columns_to_lists works", {
expect_equal(columns_to_lists(group_correlations)[2,3], .3, tol=.001)
})
test_that("assign_correlations works", {
expect_equal(assign_correlations(x=c("a", "b"), group_correlations), .1, tol=.001)
})
#' rho = random_cor_cov(size=5, cors="high")
#' study_correlations = simulate_studies(rho, 10, .5, .5, 5, T)
#' columns = correlations_to_columns(study_correlations, fill_missing=T)
#' imputations = impute_correlations(columns)
#' testthat::expect_true(ncol(imputations)==3)
#'
#' #' example_cor = random_cor_cov(size=5, cors="high", sds=c(1,2,3,4,5))
#' testthat::expect_true(length(names(example_cor))==3)
#' testthat::expect_true(example_cor$sd[1] == 1)
#' example_cor = random_cor_cov(size=5, cors="high")
#' testthat::expect_true(all(example_cor$sd^2 == diag(example_cor$cov.mat)))
test_that("Function return_cor_limits() @ L54", {
testthat::expect_equal(return_cor_limits("high")[1], 0.5)
testthat::expect_equal(return_cor_limits("mid")[1], 0.2)
testthat::expect_equal(return_cor_limits("low")[1], 0.05)
})
test_that("Function fill_matrix() @ L86", {
example_cor = fill_matrix(size=5, cors="high")
testthat::expect_true(all(example_cor>.5))
testthat::expect_true(det(example_cor)>0)
})
test_that("Function make_matrix_symmetric() @ L116", {
testthat::expect_true(isSymmetric(make_matrix_symmetric(diag(1, nrow=3), runif(3))))
})
test_that("Function remove_some_variables() @ L145", {
cor_mat = fill_matrix(10,cors = "mid")
data = MASS::mvrnorm(100, mu=rep(0, times=10), Sigma = cor_mat)
testthat::expect_true(all(head(data)==head(remove_some_variables(data, prob_any_missing = 0))))
testthat::expect_true(ncol(remove_some_variables(data, 1, .2))==8)
})
test_that("Function map_studies() @ L162", {
# n param either TRUE or a number. If TRUE, it will randomly sample a sample size.
# If a number, it will sample with that n
testthat::expect_true(isSymmetric(map_studies(1, random_cor_cov(cors="low"), n=100)))
})
test_that("Function return_na_correlations() @ L178", {
# a function that takes a correlation, takes ALL variables, and puts NA where variables are missing
rho = random_cor_cov(size=5, cors="high")
cor_mat = simulate_a_study(rho, n=100, prob_any_missing=1, proportion_missing = .6)
variable_names = letters[1:5]
length_varnames = length(variable_names)
testthat::expect_true(ncol(return_na_correlations(cor_mat, variable_names, vechs=FALSE)) == length_varnames)
testthat::expect_true(length(return_na_correlations(cor_mat, variable_names, vechs=TRUE)) == (length_varnames*(length_varnames-1))/2)
})
test_that("Function name_vechs() @ L193", {
testthat::expect_true(name_vechs(letters[1:3])[3]=="b:c")
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.