@@ -64,22 +64,10 @@ test_that("as.shinystan stanfit helpers work", {
6464 expect_identical(.rstan_sampler_params(stanfit1 ), list (NA ))
6565
6666 stanfit1 @ stan_args [[1 ]]$ control $ max_treedepth <- NULL
67- expect_equal(.rstan_max_treedepth(stanfit1 ), 11 )
67+ expect_equal(.rstan_max_treedepth(stanfit1 ), 10 )
6868})
6969
7070
71- test_that(" deprecation of burnin works properly" , {
72- expect_error(as.shinystan(array1 , warmup = 2 , burnin = 3 ),
73- " can't both be specified" )
74- expect_warning(x <- as.shinystan(array1 , burnin = 8 ),
75- " Use the 'warmup' argument instead" )
76- expect_equal(x @ n_warmup , 8 )
77- expect_silent(x <- as.shinystan(array1 , warmup = 7 ))
78- expect_equal(x @ n_warmup , 7 )
79- })
80-
81-
82-
8371# as.shinystan ------------------------------------------------------------
8472test_that(" as.shinystan (array) creates sso" , {
8573 expect_s4_class(x <- as.shinystan(array1 , model_name = " test" , note = " test" ), " shinystan" )
@@ -91,7 +79,7 @@ test_that("as.shinystan (array) creates sso", {
9179 samp <- sso @ posterior_sample
9280 sp <- sso @ sampler_params
9381 x <- as.shinystan(samp , sampler_params = sp , warmup = 759 ,
94- max_treedepth = 14 , algorithm = " NUTS" )
82+ max_treedepth = 14 , stan_algorithm = " NUTS" )
9583 expect_s4_class(x , " shinystan" )
9684 expect_equal(x @ n_warmup , 759 )
9785 expect_equal(x @ n_chain , dim(samp )[2 ])
@@ -119,22 +107,21 @@ test_that("as.shinystan (list of matrices) creates sso", {
119107 for (j in 1 : ncol(samp )) samp_list [[j ]] <- samp [, j , ]
120108 sp <- sso @ sampler_params
121109 x <- as.shinystan(samp_list , sampler_params = sp , warmup = 1000 ,
122- max_treedepth = 11 , algorithm = " NUTS" )
110+ max_treedepth = 11 , stan_algorithm = " NUTS" )
123111 expect_s4_class(x , " shinystan" )
124112})
125113test_that(" as.shinystan (stanreg) creates sso" , {
126- expect_message(x <- as.shinystan(stanreg1 , model_name = " test" ),
127- " preparing graphical posterior predictive checks" )
114+ x <- as.shinystan(stanreg1 , model_name = " test" )
128115 expect_is(x , " shinystan" )
129116
130117 # check that ppc plots created
131- ppc <- x @ misc $ pp_check_plots
132- expect_type(ppc , " list" )
133- expect_s3_class(ppc [[1 ]], " ggplot" )
134-
135- # without ppd
136- x <- as.shinystan(stanreg1 , ppd = FALSE )
137- expect_null(x @ misc $ pp_check_plots )
118+ # ppc <- x@misc$pp_check_plots
119+ # expect_type(ppc, "list")
120+ # expect_s3_class(ppc[[1]], "ggplot")
121+ #
122+ # # without ppd
123+ # x <- as.shinystan(stanreg1, ppd = FALSE)
124+ # expect_null(x@misc$pp_check_plots)
138125})
139126test_that(" as.shinystan (stanfit) creates sso" , {
140127 expect_is(x <- as.shinystan(stanfit1 , model_name = " test" , note = " test" ), " shinystan" )
@@ -151,33 +138,6 @@ test_that("as.shinystan arguments works with rstanarm example", {
151138 sso2 <- as.shinystan(stanreg1 , ppd = FALSE )
152139 expect_is(sso1 , " shinystan" )
153140 expect_is(sso2 , " shinystan" )
154- expect_false(is.null(sso1 @ misc $ pp_check_plots ))
155- expect_null(sso2 @ misc $ pp_check_plots )
156- })
157-
158- test_that(" as.shinystan 'pars' argument works with rstan example" , {
159- # load 'stanfit2' saved stanfit object
160- load(" stanfit2_for_tests.rda" )
161-
162- expect_error(as.shinystan(stanfit2 , pars = c(" alpha[1,1]" , " lp__" )),
163- " elements of non-scalar parameters not allowed" )
164-
165- sso0 <- as.shinystan(stanfit2 )
166- sso1 <- as.shinystan(stanfit2 , pars = " alpha" )
167- sso2 <- as.shinystan(stanfit2 , pars = " beta" )
168- sso3 <- as.shinystan(stanfit2 , pars = c(" alpha" , " beta" ))
169-
170- expect_identical(sso0 , sso3 )
171-
172- sso1names <- c(" alpha[1,1]" , " alpha[2,1]" , " alpha[1,2]" , " alpha[2,2]" ,
173- " alpha[1,3]" , " alpha[2,3]" , " log-posterior" )
174- expect_identical(sso1 @ param_names , sso1names )
175- expect_identical(rownames(sso1 @ summary ), sort(sso1names ))
176- expect_identical(sso2 @ param_names , c(" beta" , " log-posterior" ))
177- expect_identical(rownames(sso2 @ summary ), c(" beta" , " log-posterior" ))
178-
179- expect_equal(dim(sso1 @ posterior_sample ), c(200 , 2 , 7 ))
180- expect_equal(dim(sso2 @ posterior_sample ), c(200 , 2 , 2 ))
181141})
182142
183143
@@ -195,3 +155,17 @@ test_that("as.shinystan works with CmdStanMCMC objects", {
195155 }
196156})
197157
158+
159+ test_that(" as.shinystan works with CmdStanVB objects" , {
160+ skip_on_cran()
161+ skip_if_not_installed(" cmdstanr" )
162+ fit <- try(cmdstanr :: cmdstanr_example(" logistic" , method = " variational" ))
163+ if (! inherits(fit , " try-error" )) {
164+ sso <- as.shinystan(fit )
165+ expect_s4_class(sso , " shinystan" )
166+ expect_equal(sso @ model_name , " logistic" )
167+ expect_equal(sso @ n_chain , 1 )
168+ expect_equal(sso @ n_warmup , 0 )
169+ }
170+ })
171+
0 commit comments