Skip to content

Commit

Permalink
more cmdstanr tests, run-extended
Browse files Browse the repository at this point in the history
  • Loading branch information
santikka committed Aug 14, 2024
1 parent 53c1bf0 commit 9965c27
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions tests/testthat/test-cmdstanr.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ data.table::setDTthreads(1) # For CRAN
test_that("stanc_options argument works", {
skip_if_not(run_extended_tests)
set.seed(1)

fit <- dynamite(
dformula = obs(y ~ -1 + varying(~x), family = "gaussian") +
lags(type = "varying") +
Expand All @@ -35,7 +34,6 @@ test_that("stanc_options argument works", {
test_that("cmdstanr backend works for categorical model", {
skip_if_not(run_extended_tests)
set.seed(1)

fit_dynamite <- update(
categorical_example_fit,
stanc_options = list("O0"),
Expand Down Expand Up @@ -168,7 +166,6 @@ test_that("multivariate gaussian with threading produces a valid model", {
test_that("threading produces valid model code for other distributions", {
skip_if_not(run_extended_tests)
skip_on_os("mac")

set.seed(1)
n_id <- 50L
n_time <- 20L
Expand Down Expand Up @@ -212,7 +209,6 @@ test_that("threading produces valid model code for other distributions", {
test_that("threading produces a valid model for cumulative", {
skip_if_not(run_extended_tests)
skip_on_os("mac")

set.seed(0)

n <- 100
Expand Down Expand Up @@ -318,7 +314,6 @@ test_that("threading produces a valid model for cumulative", {
test_that("threading produces a valid model for multinomial", {
skip_if_not(run_extended_tests)
skip_on_os("mac")

set.seed(1)
n_id <- 100L
n_time <- 20L
Expand Down Expand Up @@ -454,9 +449,8 @@ test_that("syntax is correct for various models", {

test_that("latent factor syntax is correct", {
skip_if_not(run_extended_tests)
skip_on_os("mac")

set.seed(123)

N <- 40L
T_ <- 20L
D <- 10
Expand Down Expand Up @@ -513,8 +507,6 @@ test_that("latent factor syntax is correct", {

test_that("dynamice with cmdstanr backend works", {
skip_if_not(run_extended_tests)
skip_on_os("mac")

set.seed(1)
n <- 50
p <- 1000
Expand All @@ -539,12 +531,16 @@ test_that("dynamice with cmdstanr backend works", {
),
NA
)
expect_error(
print(fit_long),
NA
)
})

test_that("get_parameter_dims() works for cmdnstar models", {
skip_if_not(run_extended_tests)
skip_on_os("mac") # Seems to segfault on MacOS
set.seed(1)

f <- obs(g ~ lag(g) + lag(logp), family = "gaussian") +
obs(p ~ lag(g) + lag(logp) + lag(b), family = "poisson") +
obs(b ~ lag(b) * lag(logp) + lag(b) * lag(g), family = "bernoulli") +
Expand Down Expand Up @@ -576,3 +572,26 @@ test_that("get_parameter_dims() works for cmdnstar models", {
)
)
})

test_that("diagnostics can be obtained for cmdstanr models", {
skip_if_not(run_extended_tests)
set.seed(1)

gaussian_fit <- dynamite(
dformula =
obs(
y ~ -1 + z + varying(~ x + lag(y)) + random(~1),
family = "gaussian"
) +
random_spec() +
splines(df = 20),
data = gaussian_example,
time = "time",
group = "id",
refresh = 0,
backend = "cmdstanr"
)
expect_error(print(gaussian_fit), NA)
expect_error(hmc_diagnostics(gaussian_fit), NA)
expect_error(mcmc_diagnostics(gaussian_fit), NA)
})

0 comments on commit 9965c27

Please sign in to comment.