Skip to content

Commit

Permalink
lintr
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Sep 22, 2023
1 parent a914fe5 commit 6c1279b
Showing 1 changed file with 56 additions and 49 deletions.
105 changes: 56 additions & 49 deletions tests/testthat/test-rstanarm.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,21 @@ test_that("stan_jm", {
skip_on_os("windows")
skip_on_os(c("mac", "linux", "solaris"), arch = "i386")
void <- capture.output(
m13 <- suppressMessages(
suppressWarnings(
stan_jm(
formulaLong = logBili ~ year + (1 | id),
dataLong = pbcLong,
formulaEvent = Surv(futimeYears, death) ~ sex + trt,
dataEvent = pbcSurv,
time_var = "year",
# this next line is only to keep the example small in size!
chains = 1, cores = 1, seed = 12345, iter = 1000, refresh = 0
{
m13 <- suppressMessages(
suppressWarnings(
stan_jm(
formulaLong = logBili ~ year + (1 | id),
dataLong = pbcLong,
formulaEvent = Surv(futimeYears, death) ~ sex + trt,
dataEvent = pbcSurv,
time_var = "year",
# this next line is only to keep the example small in size!
chains = 1, cores = 1, seed = 12345, iter = 1000, refresh = 0
)
)
)
)
}
)
# expect_snapshot(model_info(m13))
})
Expand All @@ -142,17 +144,19 @@ Orange$age <- Orange$age / 100
# )

invisible(capture.output(
m15 <- suppressWarnings(
stan_mvmer(
formula = list(
logBili ~ year + (1 | id),
albumin ~ sex + year + (year | id)
),
data = pbcLong,
# this next line is only to keep the example small in size!
chains = 1, cores = 1, seed = 12345, iter = 1000, refresh = 0
{
m15 <- suppressWarnings(
stan_mvmer(
formula = list(
logBili ~ year + (1 | id),
albumin ~ sex + year + (year | id)
),
data = pbcLong,
# this next line is only to keep the example small in size!
chains = 1, cores = 1, seed = 12345, iter = 1000, refresh = 0
)
)
)
}
))

test_that("model_info-stanreg-glm", {
Expand All @@ -175,7 +179,8 @@ test_that("model_info-stanreg-glm", {
is_binomtest = FALSE, is_ftest = FALSE, is_meta = FALSE,
link_function = "logit", family = "binomial", n_obs = 56L,
n_grouplevels = c(herd = 15L)
)
),
ignore_attr = TRUE
)

expect_equal(
Expand All @@ -197,7 +202,8 @@ test_that("model_info-stanreg-glm", {
is_binomtest = FALSE, is_ftest = FALSE, is_meta = FALSE,
link_function = "identity", family = "gaussian", n_obs = 150L,
n_grouplevels = NULL
)
),
ignore_attr = TRUE
)

expect_equal(
Expand All @@ -219,24 +225,25 @@ test_that("model_info-stanreg-glm", {
is_binomtest = FALSE, is_ftest = FALSE, is_meta = FALSE,
link_function = "logit", family = "binomial", n_obs = 32L,
n_grouplevels = NULL
)
),
ignore_attr = TRUE
)

## TODO add model m4 to m15
})

test_that("n_parameters", {
expect_equal(n_parameters(m1), 21)
expect_equal(n_parameters(m1, effects = "fixed"), 5)
expect_identical(n_parameters(m1), 21)
expect_identical(n_parameters(m1, effects = "fixed"), 5)
})

test_that("get_priors", {
expect_equal(
colnames(get_priors(m1)),
expect_named(
get_priors(m1),
c("Parameter", "Distribution", "Location", "Scale")
)
expect_equal(
colnames(get_priors(m2)),
expect_named(
get_priors(m2),
c(
"Parameter",
"Distribution",
Expand Down Expand Up @@ -296,27 +303,27 @@ test_that("find_predictors", {
})

test_that("find_response", {
expect_equal(
expect_identical(
find_response(m1, combine = TRUE),
"cbind(incidence, size - incidence)"
)
expect_equal(
expect_identical(
find_response(m1, combine = FALSE),
c("incidence", "size")
)
})

test_that("get_response", {
expect_equal(nrow(get_response(m1)), 56)
expect_equal(colnames(get_response(m1)), c("incidence", "size"))
expect_identical(nrow(get_response(m1)), 56L)
expect_named(get_response(m1), c("incidence", "size"))
})

test_that("find_random", {
expect_equal(find_random(m1), list(random = "herd"))
expect_identical(find_random(m1), list(random = "herd"))
})

test_that("get_random", {
expect_equal(get_random(m1), lme4::cbpp[, "herd", drop = FALSE])
expect_identical(get_random(m1), lme4::cbpp[, "herd", drop = FALSE])
})

test_that("find_terms", {
Expand Down Expand Up @@ -350,19 +357,19 @@ test_that("find_variables", {
})

test_that("n_obs", {
expect_equal(n_obs(m1), 56)
expect_equal(n_obs(m1, disaggregate = TRUE), 842)
expect_identical(n_obs(m1), 56L)
expect_identical(n_obs(m1, disaggregate = TRUE), 842L)
})

test_that("find_paramaters", {
expect_equal(
expect_identical(
find_parameters(m1),
list(
conditional = c("(Intercept)", "size", "period2", "period3", "period4"),
random = c(sprintf("b[(Intercept) herd:%i]", 1:15), "Sigma[herd:(Intercept),(Intercept)]")
)
)
expect_equal(
expect_identical(
find_parameters(m1, flatten = TRUE),
c(
"(Intercept)",
Expand All @@ -377,12 +384,12 @@ test_that("find_paramaters", {
})

test_that("find_paramaters", {
expect_equal(
colnames(get_parameters(m1)),
expect_named(
get_parameters(m1),
c("(Intercept)", "size", "period2", "period3", "period4")
)
expect_equal(
colnames(get_parameters(m1, effects = "all")),
expect_named(
get_parameters(m1, effects = "all"),
c(
"(Intercept)",
"size",
Expand All @@ -404,9 +411,9 @@ test_that("link_inverse", {
})

test_that("get_data", {
expect_equal(nrow(get_data(m1)), 56)
expect_equal(
colnames(get_data(m1)),
expect_identical(nrow(get_data(m1)), 56L)
expect_named(
get_data(m1),
c("incidence", "size", "period", "herd")
)
})
Expand Down Expand Up @@ -460,7 +467,7 @@ test_that("get_variance", {
})

test_that("find_algorithm", {
expect_equal(
expect_identical(
find_algorithm(m1),
list(
algorithm = "sampling",
Expand Down Expand Up @@ -534,7 +541,7 @@ model <- stan_glm(

test_that("flat_priors", {
p <- get_priors(model)
expect_equal(p$Distribution, c("uniform", "normal"))
expect_identical(p$Distribution, c("uniform", "normal"))
expect_equal(p$Location, c(NA, 0), tolerance = 1e-3)
})

Expand Down

0 comments on commit 6c1279b

Please sign in to comment.