@@ -20,6 +20,12 @@ fit4 <- rename_pars(brms:::brmsfit_example4)
2020fit5 <- rename_pars(brms ::: brmsfit_example5 )
2121fit6 <- 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
2430test_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
139145test_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", {
457463test_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
532538test_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
538544test_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
543549test_that(" nobs has reasonable ouputs" , {
544- expect_equal(nobs(fit1 ), nrow( epilepsy ) )
550+ expect_equal(nobs(fit1 ), nobs )
545551})
546552
547553test_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
553559test_that(" pairs has reasonable outputs" , {
@@ -627,13 +633,13 @@ test_that("pp_average has reasonable outputs", {
627633
628634test_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
724733test_that(" predictive_error has reasonable outputs" , {
@@ -754,7 +763,7 @@ test_that("prior_summary has reasonable outputs", {
754763
755764test_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
769778test_that(" residuals has reasonable outputs" , {
0 commit comments