|
1 | 1 | #' PPC test statistics
|
2 | 2 | #'
|
3 |
| -#' The distribution of a (test) statistic `T(yrep)`, or a pair of (test) |
4 |
| -#' statistics, over the simulated datasets in `yrep`, compared to the |
5 |
| -#' observed value `T(y)` computed from the data `y`. See the |
6 |
| -#' **Plot Descriptions** and **Details** sections, below, as |
7 |
| -#' well as [Gabry et al. (2019)](https://github.com/jgabry/bayes-vis-paper#readme). |
| 3 | +#' @description The distribution of a (test) statistic `T(yrep)`, or a pair of |
| 4 | +#' (test) statistics, over the simulated datasets in `yrep`, compared to the |
| 5 | +#' observed value `T(y)` computed from the data `y`. See the |
| 6 | +#' **Plot Descriptions** and **Details** sections, below, as |
| 7 | +#' well as Gabry et al. (2019). |
| 8 | +#' |
| 9 | +#' **NOTE:** Although the default test statistic |
| 10 | +#' is the mean, this is unlikely to detect anything interesting in most cases. |
| 11 | +#' In general we recommend using some other test statistic as discussed in |
| 12 | +#' Section 5 of Gabry et al. (2019). |
8 | 13 | #'
|
9 | 14 | #' @name PPC-test-statistics
|
10 | 15 | #' @aliases PPC-statistics
|
|
54 | 59 | #' @examples
|
55 | 60 | #' y <- example_y_data()
|
56 | 61 | #' yrep <- example_yrep_draws()
|
57 |
| -#' ppc_stat(y, yrep) |
| 62 | +#' ppc_stat(y, yrep, stat = "median") |
58 | 63 | #' ppc_stat(y, yrep, stat = "sd") + legend_none()
|
59 | 64 | #'
|
60 | 65 | #' # use your own function for the 'stat' argument
|
|
69 | 74 | #' # plots by group
|
70 | 75 | #' color_scheme_set("teal")
|
71 | 76 | #' group <- example_group_data()
|
72 |
| -#' ppc_stat_grouped(y, yrep, group) |
73 |
| -#' ppc_stat_grouped(y, yrep, group) + yaxis_text() |
| 77 | +#' ppc_stat_grouped(y, yrep, group, stat = "median") |
| 78 | +#' ppc_stat_grouped(y, yrep, group, stat = "mad") + yaxis_text() |
74 | 79 | #'
|
75 | 80 | #' # force y-axes to have same scales, allow x axis to vary
|
76 | 81 | #' ppc_stat_grouped(y, yrep, group, facet_args = list(scales = "free_x")) + yaxis_text()
|
@@ -106,6 +111,7 @@ ppc_stat <-
|
106 | 111 | breaks = NULL,
|
107 | 112 | freq = TRUE) {
|
108 | 113 | stopifnot(length(stat) == 1)
|
| 114 | + message_if_using_mean(stat) |
109 | 115 | dots <- list(...)
|
110 | 116 | if (!from_grouped(dots)) {
|
111 | 117 | check_ignored_arguments(...)
|
@@ -189,6 +195,7 @@ ppc_stat_freqpoly <-
|
189 | 195 | bins = NULL,
|
190 | 196 | freq = TRUE) {
|
191 | 197 | stopifnot(length(stat) == 1)
|
| 198 | + message_if_using_mean(stat) |
192 | 199 | dots <- list(...)
|
193 | 200 | if (!from_grouped(dots)) {
|
194 | 201 | check_ignored_arguments(...)
|
@@ -270,6 +277,8 @@ ppc_stat_2d <- function(y,
|
270 | 277 | if (length(stat) != 2) {
|
271 | 278 | abort("For ppc_stat_2d the 'stat' argument must have length 2.")
|
272 | 279 | }
|
| 280 | + message_if_using_mean(stat[1]) |
| 281 | + message_if_using_mean(stat[2]) |
273 | 282 |
|
274 | 283 | if (is.character(stat)) {
|
275 | 284 | lgnd_title <- bquote(italic(T) == (list(.(stat[1]), .(stat[2]))))
|
@@ -405,3 +414,12 @@ stat_2d_segment_data <- function(data) {
|
405 | 414 | Ty_label <- function() expression(italic(T(italic(y))))
|
406 | 415 | Tyrep_label <- function() expression(italic(T)(italic(y)[rep]))
|
407 | 416 |
|
| 417 | + |
| 418 | +message_if_using_mean <- function(stat) { |
| 419 | + if (is.character(stat) && stat == "mean") { |
| 420 | + message( |
| 421 | + "Note: in most cases the default test statistic 'mean' is ", |
| 422 | + "too weak to detect anything of interest." |
| 423 | + ) |
| 424 | + } |
| 425 | +} |
0 commit comments