-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a31d363
commit 1284503
Showing
1 changed file
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# Tests for samplers | ||
|
||
# post_draws() | ||
test_that("post_draws() works for a GAM", { | ||
expect_silent(drws1 <- post_draws(m_gam, n = 20, method = "gaussian", | ||
seed = 2)) | ||
expect_silent(drws2 <- post_draws(m_gam, n = 20, method = "gaussian", | ||
seed = 2)) | ||
expect_type(drws1, "double") | ||
expect_true(is.matrix(drws1)) | ||
expect_identical(dim(drws1), c(20L, 37L)) | ||
expect_identical(drws1, drws2) | ||
}) | ||
|
||
test_that("post_draws() works for a GAM", { | ||
expect_silent(drws1 <- post_draws(m_gam, n = 20, method = "mh", | ||
burnin = 100, thin = 2, t_df = 4, rw_scale = 0.3, seed = 2)) | ||
expect_silent(drws2 <- post_draws(m_gam, n = 20, method = "mh", | ||
burnin = 100, thin = 2, t_df = 4, rw_scale = 0.3, seed = 2)) | ||
expect_type(drws1, "double") | ||
expect_true(is.matrix(drws1)) | ||
expect_identical(dim(drws1), c(20L, 37L)) | ||
expect_identical(drws1, drws2) | ||
}) | ||
|
||
test_that("post_draws() fails for INLA", { | ||
expect_error(post_draws(m_gam, method = "inla"), | ||
"'method = \"inla\"' is not yet implemented.") | ||
}) | ||
|
||
test_that("post_draws() works for a GAM with mgcv mvn()", { | ||
expect_silent(drws1 <- post_draws(m_gam, n = 20, method = "gaussian", | ||
seed = 2, mvn_method = "mgcv")) | ||
expect_silent(drws2 <- post_draws(m_gam, n = 20, method = "gaussian", | ||
seed = 2, mvn_method = "mgcv")) | ||
expect_type(drws1, "double") | ||
expect_true(is.matrix(drws1)) | ||
expect_identical(dim(drws1), c(20L, 37L)) | ||
expect_identical(drws1, drws2) | ||
}) | ||
|
||
# generate_draws() | ||
test_that("generate_draws() works for a GAM", { | ||
expect_silent(drws1 <- generate_draws(m_gam, n = 20, method = "gaussian", | ||
seed = 2)) | ||
expect_silent(drws2 <- generate_draws(m_gam, n = 20, method = "gaussian", | ||
seed = 2)) | ||
expect_type(drws1, "double") | ||
expect_true(is.matrix(drws1)) | ||
expect_identical(dim(drws1), c(20L, 37L)) | ||
expect_identical(drws1, drws2) | ||
}) | ||
|
||
test_that("generate_draws() works for a GAM with MH", { | ||
expect_silent(drws1 <- generate_draws(m_gam, n = 20, method = "mh", | ||
burnin = 100, thin = 2, t_df = 4, rw_scale = 0.3, seed = 2)) | ||
expect_silent(drws2 <- generate_draws(m_gam, n = 20, method = "mh", | ||
burnin = 100, thin = 2, t_df = 4, rw_scale = 0.3, seed = 2)) | ||
expect_type(drws1, "double") | ||
expect_true(is.matrix(drws1)) | ||
expect_identical(dim(drws1), c(20L, 37L)) | ||
expect_identical(drws1, drws2) | ||
}) | ||
|
||
test_that("generate_draws() fails for INLA", { | ||
expect_error(generate_draws(m_gam, method = "inla"), | ||
"'method = \"inla\"' is not yet implemented.") | ||
}) | ||
|
||
test_that("generate_draws() works for a GAM with mgcv mvn()", { | ||
expect_silent(drws1 <- generate_draws(m_gam, n = 20, method = "gaussian", | ||
seed = 2, mvn_method = "mgcv")) | ||
expect_silent(drws2 <- generate_draws(m_gam, n = 20, method = "gaussian", | ||
seed = 2, mvn_method = "mgcv")) | ||
expect_type(drws1, "double") | ||
expect_true(is.matrix(drws1)) | ||
expect_identical(dim(drws1), c(20L, 37L)) | ||
expect_identical(drws1, drws2) | ||
}) | ||
|
||
# user_draws() | ||
test_that("user_draws() works for a GAM", { | ||
expect_silent(drws1 <- generate_draws(m_gam, n = 20, method = "gaussian", | ||
seed = 2)) | ||
expect_silent(udrws <- user_draws(m_gam, draws = drws1)) | ||
expect_type(udrws, "double") | ||
expect_true(is.matrix(udrws)) | ||
expect_identical(dim(udrws), c(20L, 37L)) | ||
expect_identical(udrws, drws1) | ||
}) | ||
|
||
test_that("user_draws() fails for incorrect matrix of draws", { | ||
expect_error(user_draws(m_gam, draws = drws1[, 1:10]), | ||
"Supplied 'draws' doesn't match number of model coefficients. | ||
Number of model coefs: 37 | ||
Number of columns in 'draws': 10") | ||
}) |