Skip to content

Commit

Permalink
deactivate testing on windows for now
Browse files Browse the repository at this point in the history
  • Loading branch information
sbfnk committed Feb 12, 2024
1 parent ca4610f commit 6fe38f2
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ jobs:
with:
dependencies: NA
extra-packages: |
dplyr
rmarkdown
rcmdcheck
stan-dev/cmdstanr
testthat
- name: Install cmdstan
if: runner.os != 'Windows'
uses: epinowcast/actions/install-cmdstan@v1
with:
cmdstan-version: 'latest'
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-epinow.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ test_that("epinow produces expected output when run with default settings", {

test_that("epinow produces expected output when run with the
cmdstanr backend", {
skip_on_os("windows")
output <- capture.output(suppressMessages(suppressWarnings(
out <- epinow(
reported_cases = reported_cases,
Expand Down
50 changes: 27 additions & 23 deletions tests/testthat/test-estimate_secondary.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,50 @@ skip_on_cran()
# make some example secondary incidence data
cases <- example_confirmed
cases <- as.data.table(cases)[, primary := confirm]

inc_cases <- copy(cases)
# Assume that only 40 percent of cases are reported
cases[, scaling := 0.4]
inc_cases[, scaling := 0.4]
# Parameters of the assumed log normal delay distribution
cases[, meanlog := 1.8][, sdlog := 0.5]
inc_cases[, meanlog := 1.8][, sdlog := 0.5]

# Simulate secondary cases
cases <- simulate_secondary(cases, type = "incidence")
cases[
inc_cases <- simulate_secondary(inc_cases, type = "incidence")
inc_cases[
,
c("confirm", "scaling", "meanlog", "sdlog", "index", "scaled", "conv") :=
NULL
]
#
# fit model to example data specifying a weak prior for fraction reported
# with a secondary case
inc <- estimate_secondary(cases[1:60],
inc <- estimate_secondary(inc_cases[1:60],
obs = obs_opts(scale = list(mean = 0.2, sd = 0.2), week_effect = FALSE),
verbose = FALSE
)

output <- capture.output(suppressMessages(suppressWarnings(
inc_cmdstanr <- estimate_secondary(cases[1:60],
obs = obs_opts(scale = list(mean = 0.2, sd = 0.2), week_effect = FALSE),
verbose = FALSE, stan = stan_opts(backend = "cmdstanr")
)
)))

# extract posterior variables of interest
params <- c(
"meanlog" = "delay_mean[1]", "sdlog" = "delay_sd[1]",
"scaling" = "frac_obs[1]"
)

inc_posterior <- inc$posterior[variable %in% params]
inc_posterior_cmdstanr <- inc_cmdstanr$posterior[variable %in% params]

#### Prevalence data example ####

# make some example prevalence data
cases <- example_confirmed
cases <- as.data.table(cases)[, primary := confirm]
prev_cases <- copy(cases)
# Assume that only 30 percent of cases are reported
cases[, scaling := 0.3]
prev_cases[, scaling := 0.3]
# Parameters of the assumed log normal delay distribution
cases[, meanlog := 1.6][, sdlog := 0.8]
prev_cases[, meanlog := 1.6][, sdlog := 0.8]

# Simulate secondary cases
cases <- simulate_secondary(cases, type = "prevalence")
prev_cases <- simulate_secondary(prev_cases, type = "prevalence")

# fit model to example prevalence data
prev <- estimate_secondary(cases[1:100],
prev <- estimate_secondary(prev_cases[1:100],
secondary = secondary_opts(type = "prevalence"),
obs = obs_opts(
week_effect = FALSE,
Expand Down Expand Up @@ -102,6 +95,14 @@ test_that("estimate_secondary can recover simulated parameters", {

test_that("estimate_secondary can recover simulated parameters with the
cmdstanr backend", {
skip_on_os("windows")
output <- capture.output(suppressMessages(suppressWarnings(
inc_cmdstanr <- estimate_secondary(inc_cases[1:60],
obs = obs_opts(scale = list(mean = 0.2, sd = 0.2), week_effect = FALSE),
verbose = FALSE, stan = stan_opts(backend = "cmdstanr")
)
)))
inc_posterior_cmdstanr <- inc_cmdstanr$posterior[variable %in% params]
expect_equal(
inc_posterior_cmdstanr[, mean], c(1.8, 0.5, 0.4),
tolerance = 0.1
Expand All @@ -114,17 +115,20 @@ test_that("estimate_secondary can recover simulated parameters with the

test_that("forecast_secondary can return values from simulated data and plot
them", {
inc_preds <- forecast_secondary(inc, cases[seq(61, .N)][, value := primary])
inc_preds <- forecast_secondary(
inc, inc_cases[seq(61, .N)][, value := primary]
)
expect_equal(names(inc_preds), c("samples", "forecast", "predictions"))
# validation plot of observations vs estimates
expect_error(plot(inc_preds, new_obs = cases, from = "2020-05-01"), NA)
expect_error(plot(inc_preds, new_obs = inc_cases, from = "2020-05-01"), NA)
})

test_that("forecast_secondary can return values from simulated data when using
the cmdstanr backend", {
skip_on_os("windows")
capture.output(suppressMessages(suppressWarnings(
inc_preds <- forecast_secondary(
inc_cmdstanr, cases[seq(61, .N)][, value := primary], backend = "cmdstanr"
inc, inc_cases[seq(61, .N)][, value := primary], backend = "cmdstanr"
)
)))
expect_equal(names(inc_preds), c("samples", "forecast", "predictions"))
Expand All @@ -135,7 +139,7 @@ test_that("estimate_secondary works with weigh_delay_priors = TRUE", {
mean = 2.5, mean_sd = 0.5, sd = 0.47, sd_sd = 0.25, max = 30
)
inc_weigh <- estimate_secondary(
cases[1:60], delays = delay_opts(delays),
inc_cases[1:60], delays = delay_opts(delays),
obs = obs_opts(scale = list(mean = 0.2, sd = 0.2), week_effect = FALSE),
weigh_delay_priors = TRUE, verbose = FALSE
)
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-estimate_truncation.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ test_that("estimate_truncation can return values from simulated data and plot
test_that("estimate_truncation can return values from simulated data with the
cmdstanr backend", {
# fit model to example data
skip_on_os("windows")
output <- capture.output(suppressMessages(suppressWarnings(
est <- estimate_truncation(example_data,
verbose = FALSE, chains = 2, iter = 1000, warmup = 250,
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-simulate_infections.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ test_that("simulate_infections works to simulate a passed in estimate_infections

test_that("simulate_infections works to simulate a passed in estimate_infections
object when using the cmdstanr backend", {
skip_on_os("windows")
output <- capture.output(suppressMessages(suppressWarnings(
sims <- simulate_infections(out, backend = "cmdstanr")
)))
Expand Down

0 comments on commit 6fe38f2

Please sign in to comment.