Skip to content

Commit

Permalink
fixing travis-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
AnestisTouloumis committed Jul 23, 2019
1 parent 7971908 commit 0d394b9
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 43 deletions.
4 changes: 2 additions & 2 deletions R/SimCorMultRes_internals.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ check_intercepts <- function(intercepts, cluster_size, rfctn,
stop("'intercepts' must be increasing")
categories_no <- length(intercepts) + 1
if (rfctn == "rmult.clm") {
intercepts <- matrix(intercepts, cluster_size, categories_no -
1, TRUE)
intercepts <- matrix(intercepts, cluster_size,
categories_no - 1, TRUE)
intercepts <- cbind(-Inf, intercepts, Inf)
} else if (rfctn == "rmult.crm") {
intercepts <- matrix(intercepts, sample_size,
Expand Down
19 changes: 9 additions & 10 deletions tests/testthat/test_core_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ test_that("rbin constant beta_intercepts", {
as.numeric(c(t(simulated_binary_dataset$rlatent)) <=
beta_intercepts + beta_coefficients * x)
expect_equal(c(t(simulated_binary_dataset$Ysim)), simulated_responses)
})
})


test_that("rbin varying beta_intercepts", {
set.seed(1)
Expand All @@ -33,7 +34,7 @@ test_that("rbin varying beta_intercepts", {
as.numeric(c(t(simulated_binary_dataset$rlatent)) <=
beta_intercepts + beta_coefficients * x)
expect_equal(c(t(simulated_binary_dataset$Ysim)), simulated_responses)
})
})


test_that("rmult.bcl constant beta_coefficients", {
Expand All @@ -60,7 +61,7 @@ test_that("rmult.bcl constant beta_coefficients", {
lin_pred <- matrix(lin_pred, sample_size * cluster_size, categories_no, TRUE)
simulated_responses <- apply(lin_pred, 1, which.max)
expect_equal(c(t(simulated_nominal_dataset$Ysim)), simulated_responses)
})
})


test_that("rmult.bcl varying beta_coefficients", {
Expand Down Expand Up @@ -92,8 +93,7 @@ test_that("rmult.bcl varying beta_coefficients", {
lin_pred <- matrix(lin_pred, sample_size * cluster_size, categories_no, TRUE)
simulated_responses <- apply(lin_pred, 1, which.max)
expect_equal(c(t(simulated_nominal_dataset$Ysim)), simulated_responses)
})

})


test_that("rmult.clm varying beta_coefficients", {
Expand All @@ -114,8 +114,7 @@ test_that("rmult.clm varying beta_coefficients", {
simulated_responses <- cut(simulated_latent_responses, beta_intercepts,
labels = FALSE)
expect_equal(c(t(simulated_ordinal_dataset$Ysim)), simulated_responses)
})

})


test_that("rmult.clm constant beta_coefficients", {
Expand All @@ -136,7 +135,7 @@ test_that("rmult.clm constant beta_coefficients", {
simulated_responses <- cut(simulated_latent_responses, beta_intercepts,
labels = FALSE)
expect_equal(c(t(simulated_ordinal_dataset$Ysim)), simulated_responses)
})
})


test_that("rmult.acl constant beta_coefficients", {
Expand Down Expand Up @@ -168,7 +167,7 @@ test_that("rmult.acl constant beta_coefficients", {
xdata = xdata, cor.matrix = latent_correlation_matrix)
expect_equal(c(t(simulated_ordinal_dataset$Ysim)),
c(t(simulated_nominal_dataset$Ysim)))
})
})


test_that("rmult.crm constant beta_coefficients", {
Expand Down Expand Up @@ -197,4 +196,4 @@ test_that("rmult.crm constant beta_coefficients", {
ifelse(simulated_responses[, i] == 1, i, categories_no)
simulated_responses <- apply(simulated_responses, 1, min)
expect_equal(c(t(simulated_ordinal_dataset$Ysim)), simulated_responses)
})
})
102 changes: 74 additions & 28 deletions tests/testthat/test_internal_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ test_that("checking correlation matrix", {
cluster_size * categories_no)
correlation_matrix_3 <- matrix(1, cluster_size * (categories_no - 1),
cluster_size * (categories_no - 1))
correlation_matrix_4 <- diag(1, cluster_size)
correlation_matrix_5 <- diag(1, cluster_size * categories_no)
correlation_matrix_6 <- diag(1, cluster_size * (categories_no - 1))
expect_equal(check_correlation_matrix(correlation_matrix_4, cluster_size,
rfctn = "rbin"),
correlation_matrix_4)
expect_equal(check_correlation_matrix(correlation_matrix_4, cluster_size,
rfctn = "rmult.clm"),
correlation_matrix_4)
expect_equal(check_correlation_matrix(correlation_matrix_5, cluster_size,
rfctn = "rmult.bcl", categories_no),
correlation_matrix_5)
expect_equal(check_correlation_matrix(correlation_matrix_6, cluster_size,
rfctn = "rmult.crm", categories_no),
correlation_matrix_6)
expect_error(check_correlation_matrix(correlation_matrix_1, cluster_size,
rfctn = "rbin"),
"'cor_matrix' must be positive definite")
Expand All @@ -51,60 +66,91 @@ test_that("checking correlation matrix", {
expect_error(check_correlation_matrix(correlation_matrix_2, cluster_size,
rfctn = "rmult.crm", categories_no),
"'cor_matrix' must be a 10x10 matrix")
correlation_matrix_4 <- diag(1, cluster_size)
correlation_matrix_5 <- diag(1, cluster_size * categories_no)
correlation_matrix_6 <- diag(1, cluster_size * (categories_no - 1))
expect_equal(check_correlation_matrix(correlation_matrix_4, cluster_size,
rfctn = "rbin"),
correlation_matrix_4)
expect_equal(check_correlation_matrix(correlation_matrix_4, cluster_size,
rfctn = "rmult.clm"),
correlation_matrix_4)
expect_equal(check_correlation_matrix(correlation_matrix_5, cluster_size,
rfctn = "rmult.bcl", categories_no),
correlation_matrix_5)
expect_equal(check_correlation_matrix(correlation_matrix_6, cluster_size,
rfctn = "rmult.crm", categories_no),
correlation_matrix_6)
})

test_that("checking covariates formula", {
xformula <- ~ -1
expect_error(check_xformula(xformula),
"No covariates were found in 'formula'")
xformula <- ~ x1 + x2
expect_equal(check_xformula(xformula), as.formula(~ x1 + x2))
xformula <- y ~ x1 + x2
expect_equal(check_xformula(xformula), as.formula(y ~ x1 + x2))
xformula <- y ~ x1 + x2 - 1
expect_equal(check_xformula(xformula), as.formula(y ~ x1 + x2))
xformula <- ~ -1
expect_error(check_xformula(xformula),
"No covariates were found in 'formula'")
xformula <- y ~
expect_error(check_xformula(xformula),
"No covariates were found in 'formula'")
})

test_that("checking intercepts", {
cluster_size <- 5
cluster_size <- 2
rfctn <- "rbin"
intercepts <- c(-Inf, 3, Inf)
expect_error(check_intercepts(intercepts, cluster_size, rfctn),
"'intercepts' must not be Inf or -Inf")
intercepts <- c(2, 3)
expect_error(check_intercepts(intercepts, cluster_size, rfctn),
"'intercepts' must have either one or 5 elements")
intercepts <- 2
ans <- rep(intercepts, cluster_size)
ans <- cbind(-Inf, ans, Inf)
colnames(ans) <- c("","intercepts","")
colnames(ans) <- c("", "intercepts", "")
expect_equal(check_intercepts(intercepts, cluster_size, rfctn), ans)
intercepts <- 1:cluster_size
ans <- cbind(-Inf, intercepts, Inf)
colnames(ans) <- c("","intercepts","")
colnames(ans) <- c("", "intercepts", "")
expect_equal(check_intercepts(intercepts, cluster_size, rfctn), ans)
rfctn <- "rmult.clm"
intercepts <- c(-Inf, 3, Inf)
expect_error(check_intercepts(intercepts, cluster_size, rfctn),
"'intercepts' must not be Inf or -Inf")
intercepts <- c(2, 3)
expect_error(check_intercepts(intercepts, cluster_size, rfctn),
"'intercepts' must have either one or 5 elements")
rfctn <- "rmult.clm"
intercepts <- c(2, 3)
ans <- matrix(intercepts, nrow = cluster_size, ncol = 2, byrow = TRUE)
ans <- cbind(-Inf, ans, Inf)
colnames(ans) <- NULL
expect_equal(check_intercepts(intercepts, cluster_size, rfctn), ans)
intercepts <- matrix(c(2, 3), nrow = cluster_size, ncol = 2, byrow = TRUE)
ans <- cbind(-Inf, intercepts, Inf)
colnames(ans) <- NULL
expect_equal(check_intercepts(intercepts, cluster_size, rfctn), ans)
intercepts <- matrix(c(3, 2, 1, 2, 3, 4, 5, 6, 7, 8),
nrow = cluster_size, ncol = 2, byrow = TRUE)
intercepts <- c(-Inf, 3, Inf)
expect_error(check_intercepts(intercepts, cluster_size, rfctn),
"'intercepts' must not be Inf or -Inf")
intercepts <- matrix(c(3, 2, 1, 2, 3, 4, 5, 6, 7, 8),
nrow = cluster_size, ncol = 2, byrow = TRUE)
expect_error(check_intercepts(intercepts, cluster_size, rfctn),
"'intercepts' must be increasing at each row")
intercepts <- c(4, 2)
expect_error(check_intercepts(intercepts, cluster_size, rfctn),
"'intercepts' must be increasing")
intercepts <- matrix(1:10, nrow = 2, ncol = cluster_size, byrow = TRUE)
expect_error(check_intercepts(intercepts, cluster_size, rfctn))
rfctn <- "rmult.crm"
intercepts <- c(-1.5, -0.5, 0.5, 1.5)
categories_no <- 5
ans <- matrix(rep(intercepts, categories_no), categories_no,
(categories_no - 1) * cluster_size, TRUE)
colnames(ans) <- NULL
expect_equal(check_intercepts(intercepts, cluster_size, rfctn, categories_no),
ans)
rfctn <- "rmult.crm"
intercepts <- matrix(runif(cluster_size * (categories_no - 1), 0, 1),
cluster_size, categories_no - 1)
ans <- matrix(c(t(intercepts)), categories_no,
(categories_no - 1) * cluster_size, TRUE)
colnames(ans) <- NULL
expect_equal(check_intercepts(intercepts, cluster_size, rfctn, categories_no),
ans)
})


test_that("checking betas", {
cluster_size <- 2
betas <- c(1, 2)
expect_equal(check_betas(betas, cluster_size), rep(betas, cluster_size))
betas <- matrix(1:4, cluster_size, 2, TRUE)
expect_equal(check_betas(betas, cluster_size), c(1, 2, 3, 4))
betas <- matrix(1:6, 3, cluster_size, TRUE)
expect_error(check_betas(betas, cluster_size),
"The number of rows in 'betas' should be equal to 'clsize'")
})
6 changes: 3 additions & 3 deletions tests/testthat/test_utility_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test_that("rnorta", {
cor.matrix = latent_correlation_matrix)
raw_code <- qlogis(pnorm(sim_normal))
expect_equal(sim_logistic, raw_code)
})
})


test_that("rsmvnorm", {
Expand All @@ -25,7 +25,7 @@ test_that("rsmvnorm", {
raw_code <- matrix(rnorm(sample_size * p), sample_size, p) %*%
chol(correlation_matrix)
expect_equal(sim_bivariate_normal, raw_code)
})
})


test_that("rnorta sample size", {
Expand All @@ -38,4 +38,4 @@ test_that("rnorta sample size", {
sample_size <- -3
expect_true(all.equal(sample_size, as.integer(sample_size)) != TRUE |
sample_size < 1)
})
})

0 comments on commit 0d394b9

Please sign in to comment.