Skip to content

Commit dbeeb05

Browse files
committed
updated documentation and labeling for emphasising median choice
1 parent 8abdf26 commit dbeeb05

4 files changed

Lines changed: 138 additions & 106 deletions

File tree

R/ppc-discrete.R

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#' display counts. Setting `freq=FALSE` will put proportions on the y-axis.
2727
#' @param bound_distinct For `ppc_rootogram(style = "discrete)`,
2828
#' if `TRUE` then the observed counts will be plotted with different shapes
29-
#' depending on whether they are within the bounds of the expected quantiles.
29+
#' depending on whether they are within the bounds of the `y` quantiles.
3030
#'
3131
#' @template return-ggplot-or-data
3232
#'
@@ -47,20 +47,26 @@
4747
#' }
4848
#' \item{`ppc_rootogram()`}{
4949
#' Rootograms allow for diagnosing problems in count data models such as
50-
#' overdispersion or excess zeros. They consist of a histogram of `y` with the
51-
#' expected counts based on `yrep` overlaid as a line along with uncertainty
52-
#' intervals. The y-axis represents the square roots of the counts to
50+
#' overdispersion or excess zeros. In `standing`, `hanging`, and `suspended`
51+
#' styles, they consist of a histogram of `y` with the expected counts based on
52+
#' `yrep` overlaid as a line along with uncertainty intervals.
53+
#'
54+
#' Meanwhile, in `discrete` style, median counts based on `yrep` are laid
55+
#' as a point range with uncertainty intervals along with dots
56+
#' representing the `y`.
57+
#'
58+
#' The y-axis represents the square roots of the counts to
5359
#' approximately adjust for scale differences and thus ease comparison between
54-
#' observed and expected counts. Using the `style` argument, the histogram
55-
#' style can be adjusted to focus on different aspects of the data:
60+
#' observed and expected counts. Using the `style` argument, the rootogram
61+
#' can be adjusted to focus on different aspects of the data:
5662
#' * _Standing_: basic histogram of observed counts with curve
5763
#' showing expected counts.
5864
#' * _Hanging_: observed counts hanging from the curve
5965
#' representing expected counts.
6066
#' * _Suspended_: histogram of the differences between expected and
6167
#' observed counts.
62-
#' * _Discrete_: a dot-and-whisker plot of the expected counts and dots
63-
#' representing observed counts
68+
#' * _Discrete_: a dot-and-whisker plot of the median counts and
69+
#' dots representing observed counts.
6470
#'
6571
#' **All of the rootograms are plotted on the square root scale**. See Kleiber
6672
#' and Zeileis (2016) for advice on interpreting rootograms and selecting
@@ -290,7 +296,7 @@ ppc_rootogram <- function(y,
290296
# use a different shape for the point
291297
obs_shape <- obs_shape <- ifelse(y_count >= pred_quantile[, "lower"] & y_count <= pred_quantile[, "upper"], "In", "Out")
292298
} else {
293-
obs_shape <- rep("Observed", length(y_count)) # all points are the same shape for obsved
299+
obs_shape <- rep("y", length(y_count)) # all points are the same shape for observed
294300
}
295301

296302
data <- data.frame(
@@ -303,21 +309,21 @@ ppc_rootogram <- function(y,
303309
)
304310
# Create the graph
305311
graph <- ggplot(data, aes(x = xpos)) +
306-
geom_pointrange(aes(y = pred_median, ymin = lower, ymax = upper, color = "Expected"), fill = get_color("lh"), linewidth = size, size = size, fatten = 2, alpha = 1) +
312+
geom_pointrange(aes(y = pred_median, ymin = lower, ymax = upper, color = "y_rep"), fill = get_color("lh"), linewidth = size, size = size, fatten = 2, alpha = 1) +
307313
geom_point(aes(y = obs, shape = obs_shape), size = size * 1.5, color = get_color("d"), fill = get_color("d")) +
308314
scale_y_sqrt() +
309315
scale_fill_manual("", values = get_color("d"), guide="none") +
310-
scale_color_manual("", values = get_color("lh")) +
316+
scale_color_manual("", values = get_color("lh"), labels = yrep_label()) +
311317
labs(x = expression(italic(y)), y = "Count") +
312318
bayesplot_theme_get() +
313319
reduce_legend_spacing(0.25) +
314-
scale_shape_manual(values = c("In" = 22, "Out" = 23, "Observed" = 22), guide = "legend")
320+
scale_shape_manual(values = c("In" = 22, "Out" = 23, "y" = 22), guide = "legend")
315321
if (bound_distinct) {
316322
graph <- graph +
317-
guides(shape = guide_legend(" Observation \n within bounds"))
323+
guides(shape = guide_legend(expression(italic(y)~within~bounds)))
318324
} else {
319325
graph <- graph +
320-
guides(shape = guide_legend(""))
326+
guides(shape = guide_legend(" "))
321327
}
322328
return(graph)
323329
}

man/PPC-discrete.Rd

Lines changed: 14 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/_snaps/ppc-discrete/ppc-rootogram-style-discrete-prob-size-bound-distinct-false.svg

Lines changed: 44 additions & 40 deletions
Loading

0 commit comments

Comments
 (0)