|
1 | | -library(posterior) |
2 | 1 | source(test_path("data-for-ppc-tests.R")) |
3 | 2 | source(test_path("data-for-mcmc-tests.R")) |
4 | 3 |
|
@@ -116,51 +115,52 @@ test_that("get_interpolation_values catches impossible values", { |
116 | 115 |
|
117 | 116 | # validate_predictions with posterior::draws objects ---------------------- |
118 | 117 | test_that("validate_predictions accepts draws_matrix", { |
119 | | - dm <- posterior::as_draws_matrix(yrep) |
120 | | - result <- validate_predictions(dm, ncol(yrep)) |
| 118 | + result <- validate_predictions(posterior::as_draws_matrix(yrep), ncol(yrep)) |
121 | 119 | expect_true(is.matrix(result)) |
122 | 120 | expect_equal(dim(result), dim(yrep)) |
123 | 121 | expect_true(is.numeric(result)) |
124 | 122 | }) |
125 | 123 |
|
126 | 124 | test_that("validate_predictions accepts draws_array", { |
127 | | - da <- posterior::as_draws_array(yrep) |
128 | | - result <- validate_predictions(da) |
| 125 | + result <- validate_predictions(posterior::as_draws_array(yrep)) |
129 | 126 | expect_true(is.matrix(result)) |
130 | | - expect_true(is.numeric(result)) |
| 127 | + expect_equal(dim(result), dim(yrep)) |
131 | 128 | }) |
132 | 129 |
|
133 | 130 | test_that("validate_predictions accepts draws_df", { |
134 | | - ddf <- posterior::as_draws_df(yrep) |
135 | | - result <- validate_predictions(ddf) |
| 131 | + result <- validate_predictions(posterior::as_draws_df(yrep)) |
136 | 132 | expect_true(is.matrix(result)) |
137 | | - expect_true(is.numeric(result)) |
| 133 | + expect_equal(dim(result), dim(yrep)) |
138 | 134 | }) |
139 | 135 |
|
140 | | -test_that("validate_predictions accepts draws_rvars", { |
141 | | - dr <- posterior::as_draws_rvars(yrep) |
142 | | - result <- validate_predictions(dr) |
| 136 | +test_that("validate_predictions accepts draws_list", { |
| 137 | + result <- validate_predictions(posterior::as_draws_list(yrep)) |
143 | 138 | expect_true(is.matrix(result)) |
144 | | - expect_true(is.numeric(result)) |
| 139 | + expect_equal(dim(result), dim(yrep)) |
145 | 140 | }) |
146 | 141 |
|
147 | | -test_that("ppc_dens_overlay works with draws_matrix input", { |
148 | | - dm <- posterior::as_draws_matrix(yrep) |
149 | | - p <- ppc_dens_overlay(y, dm) |
150 | | - expect_s3_class(p, "ggplot") |
| 142 | +test_that("validate_predictions accepts draws_rvars", { |
| 143 | + result <- validate_predictions(posterior::as_draws_rvars(yrep)) |
| 144 | + expect_true(is.matrix(result)) |
| 145 | + expect_equal(dim(result), dim(yrep)) |
151 | 146 | }) |
152 | 147 |
|
153 | | -test_that("ppc_hist works with draws_matrix input", { |
154 | | - dm <- posterior::as_draws_matrix(yrep) |
155 | | - p <- ppc_hist(y, dm[1:8, ]) |
156 | | - expect_s3_class(p, "ggplot") |
| 148 | +test_that("posterior::draws input results in identical ggplot data", { |
| 149 | + p0 <- ggplot2::ggplot_build(ppc_dens_overlay(y, yrep)) |
| 150 | + p1 <- ggplot2::ggplot_build(ppc_dens_overlay(y, posterior::as_draws_matrix(yrep))) |
| 151 | + p2 <- ggplot2::ggplot_build(ppc_dens_overlay(y, posterior::as_draws_array(yrep))) |
| 152 | + p3 <- ggplot2::ggplot_build(ppc_dens_overlay(y, posterior::as_draws_df(yrep))) |
| 153 | + p4 <- ggplot2::ggplot_build(ppc_dens_overlay(y, posterior::as_draws_list(yrep))) |
| 154 | + p5 <- ggplot2::ggplot_build(ppc_dens_overlay(y, posterior::as_draws_rvars(yrep))) |
| 155 | + |
| 156 | + expect_identical(p1@data, p0@data) |
| 157 | + expect_identical(p2@data, p0@data) |
| 158 | + expect_identical(p3@data, p0@data) |
| 159 | + expect_identical(p4@data, p0@data) |
| 160 | + expect_identical(p5@data, p0@data) |
157 | 161 | }) |
158 | 162 |
|
159 | | -test_that("ppc_stat works with draws_matrix input", { |
160 | | - dm <- posterior::as_draws_matrix(yrep) |
161 | | - p <- ppc_stat(y, dm) |
162 | | - expect_s3_class(p, "ggplot") |
163 | | -}) |
| 163 | + |
164 | 164 |
|
165 | 165 | # ecdf_intervals --------------------------------------------------------- |
166 | 166 | test_that("ecdf_intervals returns right dimensions and values", { |
|
0 commit comments