@@ -24,30 +24,6 @@ test_that("melt_mcmc does not convert integer parameter names to integers #162",
24
24
})
25
25
26
26
27
-
28
- # validate_mcmc_x ----------------------------------------------------------
29
- test_that(" validate_mcmc_x works" , {
30
- expect_identical(validate_mcmc_x(mat ), mat )
31
- expect_identical(validate_mcmc_x(mat1 ), mat1 )
32
- expect_identical(validate_mcmc_x(arr ), arr )
33
- expect_identical(validate_mcmc_x(arr1 ), arr1 )
34
- expect_identical(validate_mcmc_x(arr1chain ), arr1chain )
35
-
36
- # error if df_with_chain
37
- expect_error(validate_mcmc_x(dframe_multiple_chains ), " is_df_with_chain" )
38
-
39
- # converts regular df to matrix
40
- expect_identical(validate_mcmc_x(dframe ), as.matrix(dframe ))
41
-
42
- # NAs
43
- mat [1 , 2 ] <- NA
44
- arr [1 , 2 , 3 ] <- NA
45
- expect_error(validate_mcmc_x(mat ), " NAs not allowed" )
46
- expect_error(validate_mcmc_x(arr ), " NAs not allowed" )
47
- })
48
-
49
-
50
-
51
27
# 3-D array helpers --------------------------------------------------------
52
28
test_that(" is_mcmc_array works" , {
53
29
expect_false(is_mcmc_array(mat ))
@@ -153,7 +129,6 @@ test_that("is_chain_list works", {
153
129
})
154
130
155
131
test_that(" validate_chain_list works" , {
156
- expect_error(validate_chain_list(mat ), " is_chain_list" )
157
132
expect_identical(validate_chain_list(chainlist ), chainlist )
158
133
expect_identical(validate_chain_list(chainlist1 ), chainlist1 )
159
134
expect_identical(validate_chain_list(chainlist1chain ), chainlist1chain )
@@ -172,8 +147,6 @@ test_that("chain_list2array works", {
172
147
expect_mcmc_array(chain_list2array(chainlist ))
173
148
expect_mcmc_array(chain_list2array(chainlist1 ))
174
149
expect_mcmc_array(chain_list2array(chainlist1chain ))
175
-
176
- expect_error(chain_list2array(dframe ), " is_chain_list" )
177
150
})
178
151
179
152
@@ -231,6 +204,42 @@ test_that("transformations recycled properly if not a named list", {
231
204
})
232
205
233
206
207
+ # prepare_mcmc_array ------------------------------------------------------
208
+ test_that(" prepare_mcmc_array processes non-array input types correctly" , {
209
+ # errors are mostly covered by tests of the many internal functions above
210
+
211
+ # data frame with no Chain column (treat as 1 chain or merged chains)
212
+ a1 <- prepare_mcmc_array(dframe )
213
+ expect_s3_class(a1 , " mcmc_array" )
214
+ expect_equal(dim(a1 ), c(nrow(dframe ), 1 , ncol(dframe )))
215
+ expect_equal(parameter_names(a1 ), colnames(dframe ))
216
+
217
+ # data frame with Chain column
218
+ a2 <- prepare_mcmc_array(dframe_multiple_chains )
219
+ expect_s3_class(a2 , " mcmc_array" )
220
+ n_chain <- max(dframe_multiple_chains $ chain )
221
+ expect_equal(dim(a2 ), c(nrow(dframe ) / n_chain , n_chain , ncol(dframe )))
222
+ expect_equal(parameter_names(a2 ), colnames(dframe ))
223
+
224
+ # list of matrices with multiple chains
225
+ a3 <- prepare_mcmc_array(chainlist )
226
+ expect_s3_class(a3 , " mcmc_array" )
227
+ expect_equal(dim(a3 ), c(nrow(chainlist [[1 ]]), length(chainlist ), ncol(chainlist [[1 ]])))
228
+ expect_equal(parameter_names(a3 ), colnames(chainlist [[1 ]]))
229
+
230
+ # object with acceptable as.array method
231
+ suppressPackageStartupMessages(library(rstanarm ))
232
+ fit <- stan_glm(mpg ~ wt , data = mtcars , chains = 2 , iter = 500 , refresh = 0 )
233
+ a4 <- prepare_mcmc_array(fit )
234
+ expect_s3_class(a4 , " mcmc_array" )
235
+ expect_equal(dim(a4 ), c(250 , 2 , 3 ))
236
+ expect_equal(parameter_names(a4 ), c(" (Intercept)" , " wt" , " sigma" ))
237
+
238
+ # object with unacceptable as.array method
239
+ fit2 <- lm(mpg ~ wt , data = mtcars )
240
+ expect_error(prepare_mcmc_array(fit2 ), " Arrays should have 2 or 3 dimensions." )
241
+ })
242
+
234
243
235
244
# rhat and neff helpers ---------------------------------------------------
236
245
test_that(" diagnostic_factor.rhat works" , {
0 commit comments