Skip to content

Commit cbe93de

Browse files
Improved documentation and code clarity
1 parent e5d6982 commit cbe93de

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

R/ppc-distributions.R

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
#' corresponding `yrep` values. `100 * prob`% central simultaneous confidence
5454
#' intervals are provided to asses if ´y´ and ´yrep´ originate from the same
5555
#' distribution. The PIT values can also be provided directly as `pit`.
56-
#' See Säilynoja et al. for more details.}
56+
#' See Säilynoja et al. (2021) for more details.}
5757
#' }
5858
#'
5959
#' @template reference-vis-paper
@@ -568,7 +568,10 @@ ppc_pit_ecdf <- function(y,
568568
dplyr::group_map(~ mean(.x$value[.x$is_y] >= .x$value[!.x$is_y])) %>%
569569
unlist()
570570
if (is.null(K)) {
571-
K <- min(length(unique(ppc_data(y, yrep)$rep_id)) + 1, length(pit))
571+
K <- min(
572+
length(unique(ppc_data(y, yrep)$rep_id)) + 1,
573+
length(pit)
574+
)
572575
}
573576
} else {
574577
inform("'pit' specified so ignoring 'y', and 'yrep' if specified.")
@@ -578,11 +581,11 @@ ppc_pit_ecdf <- function(y,
578581
}
579582
}
580583
N <- length(pit)
581-
gamma <- adjust_gamma(N,
584+
gamma <- adjust_gamma(N = N,
582585
K = K,
583586
prob = prob,
584587
interpolate_adj = interpolate_adj)
585-
lims <- ecdf_intervals(N, K = K, gamma = gamma)
588+
lims <- ecdf_intervals(gamma = gamma, N = N, K = K)
586589
ggplot() +
587590
aes_(
588591
x = 1:K / K,
@@ -630,15 +633,15 @@ ppc_pit_ecdf_grouped <-
630633
K <- length(unique(ppc_data(y, yrep)$rep_id)) + 1
631634
}
632635
} else {
633-
inform("'pit' specified so ignoring 'y', and 'yrep' if specified.")
636+
inform("'pit' specified so ignoring 'y' and 'yrep' if specified.")
634637
pit <- validate_pit(pit)
635638
}
636639
N <- length(pit)
637640

638641
gammas <- lapply(unique(group), function(g) {
639642
N_g <- sum(group == g)
640643
adjust_gamma(
641-
N_g,
644+
N = N_g,
642645
K = min(N_g, K),
643646
prob = prob,
644647
interpolate_adj = interpolate_adj
@@ -653,18 +656,19 @@ ppc_pit_ecdf_grouped <-
653656
seq(0, 1, length.out = min(nrow(.x), K))),
654657
group = .y[1],
655658
lims_upper = ecdf_intervals(
659+
gamma = gammas[[unlist(.y[1])]],
656660
N = nrow(.x),
657-
K = min(nrow(.x), K),
658-
gamma = gammas[[unlist(.y[1])]]
659-
)$upper[-1] / nrow(.x),
661+
K = min(nrow(.x), K)
662+
)$upper[-1] / nrow(.x),
660663
lims_lower = ecdf_intervals(
664+
gamma = gammas[[unlist(.y[1])]],
661665
N = nrow(.x),
662-
K = min(nrow(.x), K),
663-
gamma = gammas[[unlist(.y[1])]]
664-
)$lower[-1] / nrow(.x),
666+
K = min(nrow(.x), K)
667+
)$lower[-1] / nrow(.x),
665668
x = seq(0, 1, length.out = min(nrow(.x), K))
666669
)) %>%
667670
dplyr::bind_rows()
671+
668672
ggplot(data) +
669673
aes_(
670674
x = ~ x,

man-roxygen/args-pit-ecdf.R

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
#' discrete cases. Defaults to the smaller of length(y) and ncol(yrep).
55
#' @param prob The desired simultaneous coverage level of the bands around the
66
#' 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".
7+
#' @param plot_diff A boolean defining wether to plot the difference between the
8+
#' observed ECDF and the theoretical expectation for uniform PIT values.
9+
#' @param interpolate_adj A boolean defining if the simultaneous confidence
10+
#' bands should be computed or interpolated from precomputed values. Computing
11+
#' the bands may be computationally intensive and approximation gives a fast
12+
#' method for assessing the ECDF trajectory.

0 commit comments

Comments
 (0)