Skip to content

Commit 2cc9dff

Browse files
Documentation and examples for ppc-pit-ecdf
1 parent b493f32 commit 2cc9dff

File tree

4 files changed

+82
-26
lines changed

4 files changed

+82
-26
lines changed

R/ppc-distributions.R

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#' @template args-hist
1313
#' @template args-hist-freq
1414
#' @template args-dens
15+
#' @template args-pit-ecdf
1516
#' @param size,alpha Passed to the appropriate geom to control the appearance of
1617
#' the `yrep` distributions.
1718
#' @param ... Currently unused.
@@ -48,10 +49,10 @@
4849
#' both, depending on the `y_draw` argument.
4950
#' }
5051
#' \item{`ppc_pit_ecdf()`}{
51-
#' The `100 * prob`% central simultaneous confidence intervals for the ECDF
52-
#' of the empirical PIT values of `y` computed with respect to the
53-
#' corresponding `yrep` values. If 'y' and 'yrep'. Th PIT values can also be
54-
#' provided directly as `pit`.
52+
#' The ECDF of the empirical PIT values of `y` computed with respect to the
53+
#' corresponding `yrep` values. `100 * prob`% central simultaneous confidence
54+
#' intervals are provided to asses if ´y´ and ´yrep´ originate from the same
55+
#' distribution. The PIT values can also be provided directly as `pit`.
5556
#' See Säilynoja et al. for more details.}
5657
#' }
5758
#'
@@ -71,6 +72,11 @@
7172
#' # ppc_ecdf_overlay with continuous data (set discrete=TRUE if discrete data)
7273
#' ppc_ecdf_overlay(y, yrep[sample(nrow(yrep), 25), ])
7374
#' }
75+
#' # ECDF and ECDF difference plot of the PIT values of ´y´ compared to ´yrep
76+
#' # with 99% simultaneous confidence bands.
77+
#' ppc_pit_ecdf(y, yrep, prob=0.99, plot_diff=FALSE)
78+
#' ppc_pit_ecdf(y, yrep, prob=0.99)
79+
#'
7480
#'
7581
#' # for ppc_hist,dens,freqpoly,boxplot definitely use a subset yrep rows so
7682
#' # only a few (instead of nrow(yrep)) histograms are plotted
@@ -99,6 +105,10 @@
99105
#'
100106
#' ppc_ecdf_overlay_grouped(y, yrep[1:25, ], group = group)
101107
#'
108+
#' # ECDF difference plots of the PIT values by group
109+
#' # with 99% simultaneous confidence bands.
110+
#' ppc_pit_ecdf_grouped(y, yrep, group=group, prob=0.99)
111+
#'
102112
#' # don't need to only use small number of rows for ppc_violin_grouped
103113
#' # (as it pools yrep draws within groups)
104114
#' color_scheme_set("gray")
@@ -536,15 +546,18 @@ ppc_violin_grouped <- function(y, yrep, group, ..., probs = c(0.1, 0.5, 0.9),
536546
}
537547

538548
#' @export
549+
#' @param pit An optional vector of probability integral transformed values for
550+
#' which the ECDF is to be drawn. If NULL, PIT values are computed to ´y´ with
551+
#' respect to the corresponding values in ´yrep´.
539552
#' @rdname PPC-distributions
540553
#'
541554
ppc_pit_ecdf <- function(y,
542555
yrep,
543556
...,
544557
pit = NULL,
545558
K = NULL,
546-
confidence_level = .99,
547-
difference = TRUE,
559+
prob = .99,
560+
plot_diff = TRUE,
548561
adj_method = "interpolate") {
549562
check_ignored_arguments(...)
550563

@@ -566,23 +579,23 @@ ppc_pit_ecdf <- function(y,
566579
N <- length(pit)
567580
gamma <- adjust_gamma(N,
568581
K = K,
569-
conf_level = confidence_level,
582+
conf_level = prob,
570583
adj_method = adj_method
571584
)
572585
lims <- ecdf_intervals(N, K = K, gamma = gamma)
573586
ggplot() +
574587
aes_(
575588
x = 0:K / K,
576-
y = ecdf(pit)(0:K / K) - (difference == TRUE) * 0:K / K,
589+
y = ecdf(pit)(0:K / K) - (plot_diff == TRUE) * 0:K / K,
577590
color = "y"
578591
) +
579592
geom_step(show.legend = FALSE) +
580593
geom_step(aes(
581-
y = lims$upper / N - (difference == TRUE) * 0:K / K,
594+
y = lims$upper / N - (plot_diff == TRUE) * 0:K / K,
582595
color = "yrep"
583596
), show.legend = FALSE) +
584597
geom_step(aes(
585-
y = lims$lower / N - (difference == TRUE) * 0:K / K,
598+
y = lims$lower / N - (plot_diff == TRUE) * 0:K / K,
586599
color = "yrep"
587600
), show.legend = FALSE) +
588601
yaxis_title(FALSE) +
@@ -602,9 +615,9 @@ ppc_pit_ecdf_grouped <-
602615
...,
603616
K,
604617
pit,
605-
confidence_level = .99,
606-
difference = TRUE,
607-
adj_method) {
618+
prob = .99,
619+
plot_diff = TRUE,
620+
adj_method = "interpolate") {
608621
check_ignored_arguments(...)
609622

610623
if (missing(pit)) {
@@ -626,7 +639,7 @@ ppc_pit_ecdf_grouped <-
626639
adjust_gamma(
627640
N_g,
628641
K = min(N_g, K0),
629-
conf_level = confidence_level,
642+
conf_level = prob,
630643
adj_method = adj_method
631644
)
632645
})
@@ -654,17 +667,17 @@ ppc_pit_ecdf_grouped <-
654667
ggplot(data) +
655668
aes_(
656669
x = ~x,
657-
y = ~ ecdf_value - (difference == TRUE) * x,
670+
y = ~ ecdf_value - (plot_diff == TRUE) * x,
658671
group = ~group,
659672
color = "y"
660673
) +
661674
geom_step(show.legend = FALSE) +
662675
geom_step(aes_(
663-
y = ~ lims_upper - (difference == TRUE) * x,
676+
y = ~ lims_upper - (plot_diff == TRUE) * x,
664677
color = "yrep"
665678
), show.legend = FALSE) +
666679
geom_step(aes_(
667-
y = ~ lims_lower - (difference == TRUE) * x,
680+
y = ~ lims_lower - (plot_diff == TRUE) * x,
668681
color = "yrep"
669682
), show.legend = FALSE) +
670683
xaxis_title(FALSE) +

man-roxygen/args-pit-ecdf.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#' @param K An optional integer defining the number of equally spaced evaluation
2+
#' points for the ECDF. If the
3+
#' submitted PIT values are known to be discrete, this should be the number of
4+
#' discrete cases. Defaults to the smaller of length(y) and ncol(yrep).
5+
#' @param prob The desired simultaneous coverage level of the bands around the
6+
#' ECDF. A value in (0,1).
7+
#' @param plot_diff Wether to plot the difference between the observed ECDF and
8+
#' the theoretical expectation when the PIT values are uniform.
9+
#' @param adj_method Method to obtain the simultaneous confidence bands.
10+
#' Possible values: "interpolate", "simulate", "optimize".
11+
#' Defaults to "interpolate".
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#' @references Säilynoja, T., Bürkner, P., Vehtari, A.
2+
#' (2021). Graphical Test for Discrete Uniformity and its Applications in
3+
#' Goodness of Fit Evaluation and Multiple Sample Comparison [arXiv
4+
#' preprint](https://arxiv.org/abs/2103.10522).

man/PPC-distributions.Rd

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

0 commit comments

Comments
 (0)