Skip to content

Commit db6ddde

Browse files
committed
try to reduce brms tarball size
1 parent ffc7b4a commit db6ddde

File tree

3 files changed

+44
-34
lines changed

3 files changed

+44
-34
lines changed

R/sysdata.rda

-1.16 MB
Binary file not shown.

tests/brmsfit_examples.R

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
set.seed(1234)
2+
N <- 40
23
dat <- data.frame(
3-
count = rpois(236, lambda = 20),
4-
visit = factor(rep(1:4, each = 59)),
5-
patient = factor(rep(1:59, 4)),
6-
Age = rnorm(236),
7-
Trt = factor(sample(0:1, 236, TRUE)),
8-
AgeSD = abs(rnorm(236, 1)),
9-
Exp = factor(sample(1:5, 236, TRUE), ordered = TRUE),
10-
volume = rnorm(236),
11-
gender = factor(c(rep("m", 30), rep("f", 29)))
4+
count = rpois(N, lambda = 20),
5+
visit = factor(rep(1:4, each = N/4)),
6+
patient = factor(rep(1:(N/4), 4)),
7+
Age = rnorm(N),
8+
Trt = factor(sample(0:1, N, TRUE)),
9+
AgeSD = abs(rnorm(N, 1)),
10+
Exp = factor(sample(1:5, N, TRUE), ordered = TRUE),
11+
volume = rnorm(N),
12+
gender = factor(c(rep("m", N/8), rep("f", N/8)))
1213
)
1314

1415
dat2 <- data.frame(
15-
rating = sample(1:4, 50, TRUE),
16-
subject = rep(1:10, 5),
17-
x1 = rnorm(50),
18-
x2 = rnorm(50),
19-
x3 = rnorm(50)
16+
rating = sample(1:4, N, TRUE),
17+
subject = rep(1:(N/5), 5),
18+
x1 = rnorm(N),
19+
x2 = rnorm(N),
20+
x3 = rnorm(N)
2021
)
2122

22-
warmup <- 150
23-
iter <- 200
23+
warmup <- 50
24+
iter <- 75
2425
chains <- 1
2526
stan_model_args <- list(save_dso = FALSE)
2627

tests/testthat/tests.brmsfit-methods.R

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ fit4 <- rename_pars(brms:::brmsfit_example4)
2020
fit5 <- rename_pars(brms:::brmsfit_example5)
2121
fit6 <- rename_pars(brms:::brmsfit_example6)
2222

23+
# some high level info about the data sets
24+
nobs <- 40
25+
npatients <- 10
26+
nsubjects <- 8
27+
nvisits <- 4
28+
2329
# test S3 methods in alphabetical order
2430
test_that("as_draws and friends have resonable outputs", {
2531
draws <- as_draws(fit1, variable = "b_Intercept")
@@ -131,9 +137,9 @@ test_that("coef has reasonable ouputs", {
131137
coef1 <- SM(coef(fit1, summary = FALSE))
132138
expect_equal(dim(coef1$visit), c(ndraws(fit1), 4, 9))
133139
coef2 <- SM(coef(fit2))
134-
expect_equal(dim(coef2$patient), c(59, 4, 4))
140+
expect_equal(dim(coef2$patient), c(npatients, 4, 4))
135141
coef4 <- SM(coef(fit4))
136-
expect_equal(dim(coef4$subject), c(10, 4, 8))
142+
expect_equal(dim(coef4$subject), c(nsubjects, 4, 8))
137143
})
138144

139145
test_that("combine_models has reasonable ouputs", {
@@ -219,7 +225,7 @@ test_that("conditional_effects has reasonable ouputs", {
219225
me5 <- conditional_effects(fit5)
220226
expect_true(is(me5, "brms_conditional_effects"))
221227

222-
me6 <- conditional_effects(fit6, ndraws = 40)
228+
me6 <- conditional_effects(fit6, ndraws = 20)
223229
expect_true(is(me6, "brms_conditional_effects"))
224230
})
225231

@@ -457,9 +463,9 @@ test_that("loo has reasonable outputs", {
457463
test_that("loo_subsample has reasonable outputs", {
458464
skip_on_cran()
459465

460-
loo2 <- SW(loo_subsample(fit2, observations = 50))
466+
loo2 <- SW(loo_subsample(fit2, observations = 30))
461467
expect_true(is.numeric(loo2$estimates))
462-
expect_equal(nrow(loo2$pointwise), 50)
468+
expect_equal(nrow(loo2$pointwise), 30)
463469
expect_output(print(loo2), "looic")
464470
})
465471

@@ -530,24 +536,24 @@ test_that("model_weights has reasonable ouputs", {
530536
})
531537

532538
test_that("ndraws and friends have reasonable ouputs", {
533-
expect_equal(ndraws(fit1), 50)
539+
expect_equal(ndraws(fit1), 25)
534540
expect_equal(nchains(fit1), 1)
535-
expect_equal(niterations(fit1), 50)
541+
expect_equal(niterations(fit1), 25)
536542
})
537543

538544
test_that("ngrps has reasonable ouputs", {
539545
expect_equal(ngrps(fit1), list(visit = 4))
540-
expect_equal(ngrps(fit2), list(patient = 59))
546+
expect_equal(ngrps(fit2), list(patient = 10))
541547
})
542548

543549
test_that("nobs has reasonable ouputs", {
544-
expect_equal(nobs(fit1), nrow(epilepsy))
550+
expect_equal(nobs(fit1), nobs)
545551
})
546552

547553
test_that("nsamples has reasonable ouputs", {
548-
expect_equal(SW(nsamples(fit1)), 50)
554+
expect_equal(SW(nsamples(fit1)), 25)
549555
expect_equal(SW(nsamples(fit1, subset = 10:1)), 10)
550-
expect_equal(SW(nsamples(fit1, incl_warmup = TRUE)), 200)
556+
expect_equal(SW(nsamples(fit1, incl_warmup = TRUE)), 75)
551557
})
552558

553559
test_that("pairs has reasonable outputs", {
@@ -627,13 +633,13 @@ test_that("pp_average has reasonable outputs", {
627633

628634
test_that("pp_check has reasonable outputs", {
629635
expect_ggplot(pp_check(fit1))
630-
expect_ggplot(pp_check(fit1, newdata = fit1$data[1:100, ]))
636+
expect_ggplot(pp_check(fit1, newdata = fit1$data[1:10, ]))
631637
expect_ggplot(pp_check(fit1, "stat", ndraws = 5))
632638
expect_ggplot(pp_check(fit1, "error_binned"))
633639
pp <- pp_check(fit1, "ribbon_grouped", group = "visit", x = "Age")
634640
expect_ggplot(pp)
635641
pp <- pp_check(fit1, type = "violin_grouped",
636-
group = "visit", newdata = fit1$data[1:100, ])
642+
group = "visit", newdata = fit1$data[1:10, ])
637643
expect_ggplot(pp)
638644

639645
pp <- SW(pp_check(fit1, type = "loo_pit", cores = 1))
@@ -642,6 +648,9 @@ test_that("pp_check has reasonable outputs", {
642648
# ppd plots work
643649
expect_ggplot(pp_check(fit1, prefix = "ppd"))
644650

651+
# reduce test time on CRAN
652+
skip_on_cran()
653+
645654
expect_ggplot(pp_check(fit3))
646655
expect_ggplot(pp_check(fit2, "ribbon", x = "Age"))
647656
expect_error(pp_check(fit2, "ribbon", x = "x"),
@@ -711,14 +720,14 @@ test_that("predict has reasonable outputs", {
711720

712721
pred <- predict(fit5)
713722
expect_equal(dim(pred), c(nobs(fit5), 4))
714-
newdata <- fit5$data[1:10, ]
723+
newdata <- fit5$data[1:5, ]
715724
newdata$patient <- "a"
716725
pred <- predict(fit5, newdata, allow_new_levels = TRUE,
717726
sample_new_levels = "old_levels")
718-
expect_equal(dim(pred), c(10, 4))
727+
expect_equal(dim(pred), c(5, 4))
719728
pred <- predict(fit5, newdata, allow_new_levels = TRUE,
720729
sample_new_levels = "gaussian")
721-
expect_equal(dim(pred), c(10, 4))
730+
expect_equal(dim(pred), c(5, 4))
722731
})
723732

724733
test_that("predictive_error has reasonable outputs", {
@@ -754,7 +763,7 @@ test_that("prior_summary has reasonable outputs", {
754763

755764
test_that("ranef has reasonable outputs", {
756765
ranef1 <- SM(ranef(fit1))
757-
expect_equal(dim(ranef1$visit), c(4, 4, 2))
766+
expect_equal(dim(ranef1$visit), c(nvisits, 4, 2))
758767

759768
ranef1 <- SM(ranef(fit1, pars = "Trt1"))
760769
expect_equal(dimnames(ranef1$visit)[[3]], "Trt1")
@@ -763,7 +772,7 @@ test_that("ranef has reasonable outputs", {
763772
expect_equal(length(ranef1), 0L)
764773

765774
ranef2 <- SM(ranef(fit2, summary = FALSE))
766-
expect_equal(dim(ranef2$patient), c(ndraws(fit2), 59, 2))
775+
expect_equal(dim(ranef2$patient), c(ndraws(fit2), npatients, 2))
767776
})
768777

769778
test_that("residuals has reasonable outputs", {

0 commit comments

Comments
 (0)