From f37a86b06137a6d15e0f81cff070caeafd4415d3 Mon Sep 17 00:00:00 2001 From: fweber144 Date: Wed, 12 Aug 2020 10:59:31 +0200 Subject: [PATCH 01/36] Created ppc_km_overlay(), a function for performing a PPC on right-censored data using the Kaplan-Meier estimator. Note that for the replicated data (which is always uncensored), the Kaplan-Meier estimator reduces to "1 - ECDF" with ECDF denoting the ordinary empirical cumulative distribution function. --- R/ppc-distributions.R | 73 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/R/ppc-distributions.R b/R/ppc-distributions.R index 7f9a5ffd..2e86acce 100644 --- a/R/ppc-distributions.R +++ b/R/ppc-distributions.R @@ -370,6 +370,79 @@ ppc_ecdf_overlay <- bayesplot_theme_get() } +#' @export +#' @rdname PPC-distributions +#' @param status_y The status indicator for the observations from `y` (1 = +#' event, 0 = right censored). +ppc_km_overlay <- + function(y, + yrep, + ..., + status_y, + size = 0.25, + alpha = 0.7) { + check_ignored_arguments(...) + + # Checks for 'status_y': + stopifnot(is.numeric(status_y)) + stopifnot(all(status_y %in% c(0, 1))) + + # Create basic PPC dataset: + data <- ppc_data(y, yrep, group = status_y) + + # Modify the status indicator: + # * For the observed data ("y"), convert the status indicator back to + # a numeric. + # * For the replicated data ("yrep"), set the status indicator + # to 1 ("event"). This way, the Kaplan-Meier estimator reduces + # to "1 - ECDF" with ECDF denoting the ordinary empirical cumulative + # distribution function. + data <- data %>% + dplyr::mutate(group = ifelse(is_y, as.numeric(as.character(group)), 1)) + + # Create 'survfit' object: + sf <- survival::survfit( + survival::Surv(value, group) ~ rep_label, + data = data + ) + + # "Fortify" the 'survfit' object: + if(!requireNamespace("ggfortify", quietly = TRUE)){ + abort("Package 'ggfortify' required.") + } + fsf <- fortify(sf) + + # Add variables specifying color, size, and alpha: + fsf$is_y_color <- as.factor(sub("\\[rep\\] \\(.*$", "rep", sub("^italic\\(y\\)", "y", fsf$strata))) + fsf$is_y_size <- ifelse(fsf$is_y_color == "yrep", size, 1) + fsf$is_y_alpha <- ifelse(fsf$is_y_color == "yrep", alpha, 1) + + # Plot: + ggplot(data = fsf, + mapping = aes(x = time, + y = surv, + color = is_y_color, + group = strata, + size = is_y_size, + alpha = is_y_alpha)) + + geom_step() + + scale_size_identity() + + scale_alpha_identity() + + hline_at( + c(0, 0.5, 1), + size = c(0.2, 0.1, 0.2), + linetype = 2, + color = get_color("dh") + ) + + scale_color_ppc_dist() + + xlab(y_label()) + + scale_y_continuous(breaks = c(0, 0.5, 1)) + + yaxis_title(FALSE) + + xaxis_title(FALSE) + + yaxis_ticks(FALSE) + + bayesplot_theme_get() + } + #' @export #' @rdname PPC-distributions #' @param probs A numeric vector passed to [ggplot2::geom_violin()]'s From 149b2f10f078756775fc62e8f40a4d706791a412 Mon Sep 17 00:00:00 2001 From: fweber144 Date: Wed, 12 Aug 2020 11:08:57 +0200 Subject: [PATCH 02/36] Added a check for package "survival" in ppc_km_overlay(). --- R/ppc-distributions.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/ppc-distributions.R b/R/ppc-distributions.R index 2e86acce..96ff949c 100644 --- a/R/ppc-distributions.R +++ b/R/ppc-distributions.R @@ -401,6 +401,9 @@ ppc_km_overlay <- dplyr::mutate(group = ifelse(is_y, as.numeric(as.character(group)), 1)) # Create 'survfit' object: + if(!requireNamespace("survival", quietly = TRUE)){ + abort("Package 'survival' required.") + } sf <- survival::survfit( survival::Surv(value, group) ~ rep_label, data = data From d4433ff34beddda963fc6f9174e9b42a8bb8aef3 Mon Sep 17 00:00:00 2001 From: fweber144 Date: Wed, 12 Aug 2020 11:11:40 +0200 Subject: [PATCH 03/36] DESCRIPTION file: Added packages "survival" and "ggfortify" to "Suggests" list. --- DESCRIPTION | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1b7edaf8..241ad3a4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -48,7 +48,9 @@ Suggests: scales, shinystan (>= 2.3.0), testthat (>= 2.0.0), - vdiffr + vdiffr, + survival, + ggfortify RoxygenNote: 7.1.1 VignetteBuilder: knitr Encoding: UTF-8 From 029f5e03bfc1a7883570051529c26f78c5cccd64 Mon Sep 17 00:00:00 2001 From: fweber144 Date: Wed, 12 Aug 2020 11:22:21 +0200 Subject: [PATCH 04/36] Added a description of ppc_km_overlay() to the roxygen2 documentation. --- R/ppc-distributions.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/R/ppc-distributions.R b/R/ppc-distributions.R index 96ff949c..a317b515 100644 --- a/R/ppc-distributions.R +++ b/R/ppc-distributions.R @@ -40,6 +40,11 @@ #' data, set the `discrete` argument to `TRUE` for better results. #' For an example of `ppc_dens_overlay()` also see Gabry et al. (2019). #' } +#' \item{`ppc_km_overlay()`}{ +#' Empirical CCDF estimates of each dataset (row) in `yrep` are overlaid, +#' with the Kaplan-Meier estimate of `y` itself on top (and in a darker +#' shade). This is a PPC suitable for right-censored data. +#' } #' \item{`ppc_violin_grouped()`}{ #' The density estimate of `yrep` within each level of a grouping #' variable is plotted as a violin with horizontal lines at notable From 0837f9933cf102bfe3b5295795a852853f1cee8b Mon Sep 17 00:00:00 2001 From: fweber144 Date: Wed, 12 Aug 2020 11:28:13 +0200 Subject: [PATCH 05/36] Minor improvement in the roxygen2 documentation of ppc_km_overlay(). --- R/ppc-distributions.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/ppc-distributions.R b/R/ppc-distributions.R index a317b515..b60dd49f 100644 --- a/R/ppc-distributions.R +++ b/R/ppc-distributions.R @@ -43,7 +43,7 @@ #' \item{`ppc_km_overlay()`}{ #' Empirical CCDF estimates of each dataset (row) in `yrep` are overlaid, #' with the Kaplan-Meier estimate of `y` itself on top (and in a darker -#' shade). This is a PPC suitable for right-censored data. +#' shade). This is a PPC suitable for right-censored `y`. #' } #' \item{`ppc_violin_grouped()`}{ #' The density estimate of `yrep` within each level of a grouping From 5f9acd7e983086def68b76e3d6c9be2f87f3ddc5 Mon Sep 17 00:00:00 2001 From: fweber144 Date: Wed, 12 Aug 2020 11:38:01 +0200 Subject: [PATCH 06/36] Another minor improvement in the roxygen2 documentation of ppc_km_overlay(). --- R/ppc-distributions.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/ppc-distributions.R b/R/ppc-distributions.R index b60dd49f..b037db69 100644 --- a/R/ppc-distributions.R +++ b/R/ppc-distributions.R @@ -43,7 +43,8 @@ #' \item{`ppc_km_overlay()`}{ #' Empirical CCDF estimates of each dataset (row) in `yrep` are overlaid, #' with the Kaplan-Meier estimate of `y` itself on top (and in a darker -#' shade). This is a PPC suitable for right-censored `y`. +#' shade). This is a PPC suitable for right-censored `y`. Note that the +#' replicated data from `yrep` is assumed to be uncensored. #' } #' \item{`ppc_violin_grouped()`}{ #' The density estimate of `yrep` within each level of a grouping From 552a37ac479e68ccb624b839e3cf5ccc4f50d329 Mon Sep 17 00:00:00 2001 From: fweber144 Date: Wed, 12 Aug 2020 11:41:12 +0200 Subject: [PATCH 07/36] Updated the documentation using devtools::document(). --- NAMESPACE | 1 + man/PPC-distributions.Rd | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index 5bf2b8bd..3c3eae7d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -117,6 +117,7 @@ export(ppc_hist) export(ppc_intervals) export(ppc_intervals_data) export(ppc_intervals_grouped) +export(ppc_km_overlay) export(ppc_loo_intervals) export(ppc_loo_pit) export(ppc_loo_pit_overlay) diff --git a/man/PPC-distributions.Rd b/man/PPC-distributions.Rd index 525999c6..a53cad01 100644 --- a/man/PPC-distributions.Rd +++ b/man/PPC-distributions.Rd @@ -10,6 +10,7 @@ \alias{ppc_dens} \alias{ppc_dens_overlay} \alias{ppc_ecdf_overlay} +\alias{ppc_km_overlay} \alias{ppc_violin_grouped} \title{PPC distributions} \usage{ @@ -65,6 +66,8 @@ ppc_ecdf_overlay( alpha = 0.7 ) +ppc_km_overlay(y, yrep, ..., status_y, size = 0.25, alpha = 0.7) + ppc_violin_grouped( y, yrep, @@ -126,6 +129,9 @@ passed to \code{\link[ggplot2:stat_ecdf]{ggplot2::stat_ecdf()}}. If \code{discre \item{pad}{A logical scalar passed to \code{\link[ggplot2:stat_ecdf]{ggplot2::stat_ecdf()}}.} +\item{status_y}{The status indicator for the observations from \code{y} (1 = +event, 0 = right censored).} + \item{probs}{A numeric vector passed to \code{\link[ggplot2:geom_violin]{ggplot2::geom_violin()}}'s \code{draw_quantiles} argument to specify at which quantiles to draw horizontal lines. Set to \code{NULL} to remove the lines.} @@ -178,6 +184,12 @@ Kernel density or empirical CDF estimates of each dataset (row) in data, set the \code{discrete} argument to \code{TRUE} for better results. For an example of \code{ppc_dens_overlay()} also see Gabry et al. (2019). } +\item{\code{ppc_km_overlay()}}{ +Empirical CCDF estimates of each dataset (row) in \code{yrep} are overlaid, +with the Kaplan-Meier estimate of \code{y} itself on top (and in a darker +shade). This is a PPC suitable for right-censored \code{y}. Note that the +replicated data from \code{yrep} is assumed to be uncensored. +} \item{\code{ppc_violin_grouped()}}{ The density estimate of \code{yrep} within each level of a grouping variable is plotted as a violin with horizontal lines at notable From e4ed9e350cf5d23d6231e32ebdd1c3ae37f5cb56 Mon Sep 17 00:00:00 2001 From: fweber144 Date: Wed, 12 Aug 2020 11:50:49 +0200 Subject: [PATCH 08/36] Another minor improvement in the roxygen2 documentation of ppc_km_overlay(), this time concerning argument 'status_y'. Updated the documentation using devtools::document(). --- R/ppc-distributions.R | 5 +++-- man/PPC-distributions.Rd | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/R/ppc-distributions.R b/R/ppc-distributions.R index b037db69..7eed7b16 100644 --- a/R/ppc-distributions.R +++ b/R/ppc-distributions.R @@ -378,8 +378,9 @@ ppc_ecdf_overlay <- #' @export #' @rdname PPC-distributions -#' @param status_y The status indicator for the observations from `y` (1 = -#' event, 0 = right censored). +#' @param status_y The status indicator for the observations from `y`. This must +#' be a numeric vector of the same length as `y` with values in \{0, 1\} (0 = +#' right censored, 1 = event). ppc_km_overlay <- function(y, yrep, diff --git a/man/PPC-distributions.Rd b/man/PPC-distributions.Rd index a53cad01..1de4154c 100644 --- a/man/PPC-distributions.Rd +++ b/man/PPC-distributions.Rd @@ -129,8 +129,9 @@ passed to \code{\link[ggplot2:stat_ecdf]{ggplot2::stat_ecdf()}}. If \code{discre \item{pad}{A logical scalar passed to \code{\link[ggplot2:stat_ecdf]{ggplot2::stat_ecdf()}}.} -\item{status_y}{The status indicator for the observations from \code{y} (1 = -event, 0 = right censored).} +\item{status_y}{The status indicator for the observations from \code{y}. This must +be a numeric vector of the same length as \code{y} with values in \{0, 1\} (0 = +right censored, 1 = event).} \item{probs}{A numeric vector passed to \code{\link[ggplot2:geom_violin]{ggplot2::geom_violin()}}'s \code{draw_quantiles} argument to specify at which quantiles to draw From 606cabc6588b171f4d13bf535e289a9aa6b02b97 Mon Sep 17 00:00:00 2001 From: fweber144 Date: Wed, 12 Aug 2020 13:44:32 +0200 Subject: [PATCH 09/36] Added unit tests for ppc_km_overlay(). --- tests/testthat/test-ppc-distributions.R | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/testthat/test-ppc-distributions.R b/tests/testthat/test-ppc-distributions.R index b5504bc0..81bca682 100644 --- a/tests/testthat/test-ppc-distributions.R +++ b/tests/testthat/test-ppc-distributions.R @@ -13,6 +13,11 @@ test_that("ppc_ecdf_overlay returns a ggplot object", { expect_gg(ppc_ecdf_overlay(y2, yrep2)) }) +test_that("ppc_km_overlay returns a ggplot object", { + expect_gg(ppc_km_overlay(y, yrep, size = 0.5, alpha = 0.2)) + expect_gg(ppc_km_overlay(y2, yrep2)) +}) + test_that("ppc_dens,pp_hist,ppc_freqpoly,ppc_boxplot return ggplot objects", { expect_gg(ppc_hist(y, yrep[1,, drop = FALSE])) expect_gg(ppc_hist(y, yrep[1:8, ])) @@ -127,6 +132,21 @@ test_that("ppc_ecdf_overlay renders correctly", { vdiffr::expect_doppelganger("ppc_ecdf_overlay (discrete, size, alpha)", p_custom) }) +test_that("ppc_km_overlay renders correctly", { + testthat::skip_on_cran() + testthat::skip_if_not_installed("vdiffr") + + p_base <- ppc_km_overlay(vdiff_y2, vdiff_yrep2) + vdiffr::expect_doppelganger("ppc_km_overlay (default)", p_base) + + p_custom <- ppc_km_overlay( + vdiff_y2, + vdiff_yrep2, + size = 2, + alpha = .2) + vdiffr::expect_doppelganger("ppc_km_overlay (size, alpha)", p_custom) +}) + test_that("ppc_dens renders correctly", { testthat::skip_on_cran() testthat::skip_if_not_installed("vdiffr") From d9e5759cf94029c0e7a71fc81dcbb4df5aefcaf6 Mon Sep 17 00:00:00 2001 From: fweber144 Date: Wed, 12 Aug 2020 13:52:48 +0200 Subject: [PATCH 10/36] Fixed a bug in the unit tests for ppc_km_overlay() (had to add 'status_y'). --- tests/testthat/data-for-ppc-tests.R | 4 ++++ tests/testthat/test-ppc-distributions.R | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/testthat/data-for-ppc-tests.R b/tests/testthat/data-for-ppc-tests.R index 57a9991d..752b10f8 100644 --- a/tests/testthat/data-for-ppc-tests.R +++ b/tests/testthat/data-for-ppc-tests.R @@ -2,10 +2,12 @@ set.seed(8420) y <- rnorm(100) yrep <- matrix(rnorm(2500), ncol = 100) group <- gl(4, 25, labels = LETTERS[1:4]) +status_y <- rep_len(0:1, length.out = length(y)) y2 <- rpois(30, 1) yrep2 <- matrix(rpois(30, 1), ncol = 30) group2 <- rep(1, 30) +status_y2 <- rep_len(0:1, length.out = length(y2)) # for vdiffr visual tests @@ -13,8 +15,10 @@ set.seed(11172017) vdiff_y <- rnorm(100) vdiff_yrep <- matrix(rnorm(2500), ncol = 100) vdiff_group <- gl(4, 25, labels = LETTERS[1:4]) +vdiff_status_y <- rep_len(0:1, length.out = length(vdiff_y)) vdiff_y2 <- rpois(30, 1) vdiff_yrep2 <- matrix(rpois(30 * 10, 1), ncol = 30, nrow = 10) vdiff_group2 <- rep_len(c(1,2), length.out = 30) +vdiff_status_y2 <- rep_len(0:1, length.out = length(vdiff_y2)) set.seed(seed = NULL) diff --git a/tests/testthat/test-ppc-distributions.R b/tests/testthat/test-ppc-distributions.R index 81bca682..2a587edf 100644 --- a/tests/testthat/test-ppc-distributions.R +++ b/tests/testthat/test-ppc-distributions.R @@ -14,8 +14,8 @@ test_that("ppc_ecdf_overlay returns a ggplot object", { }) test_that("ppc_km_overlay returns a ggplot object", { - expect_gg(ppc_km_overlay(y, yrep, size = 0.5, alpha = 0.2)) - expect_gg(ppc_km_overlay(y2, yrep2)) + expect_gg(ppc_km_overlay(y, yrep, status_y, size = 0.5, alpha = 0.2)) + expect_gg(ppc_km_overlay(y2, yrep2, status_y2)) }) test_that("ppc_dens,pp_hist,ppc_freqpoly,ppc_boxplot return ggplot objects", { @@ -136,12 +136,13 @@ test_that("ppc_km_overlay renders correctly", { testthat::skip_on_cran() testthat::skip_if_not_installed("vdiffr") - p_base <- ppc_km_overlay(vdiff_y2, vdiff_yrep2) + p_base <- ppc_km_overlay(vdiff_y2, vdiff_yrep2, vdiff_status_y2) vdiffr::expect_doppelganger("ppc_km_overlay (default)", p_base) p_custom <- ppc_km_overlay( vdiff_y2, vdiff_yrep2, + vdiff_status_y2, size = 2, alpha = .2) vdiffr::expect_doppelganger("ppc_km_overlay (size, alpha)", p_custom) From 70c0e0e5c97087f3e2de8984416c9c5b06495ace Mon Sep 17 00:00:00 2001 From: fweber144 Date: Wed, 12 Aug 2020 14:00:14 +0200 Subject: [PATCH 11/36] Fixed a bug in the unit tests for ppc_km_overlay() (had to name argument 'status_y' explicitly). --- tests/testthat/test-ppc-distributions.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-ppc-distributions.R b/tests/testthat/test-ppc-distributions.R index 2a587edf..0d4eacd7 100644 --- a/tests/testthat/test-ppc-distributions.R +++ b/tests/testthat/test-ppc-distributions.R @@ -14,8 +14,8 @@ test_that("ppc_ecdf_overlay returns a ggplot object", { }) test_that("ppc_km_overlay returns a ggplot object", { - expect_gg(ppc_km_overlay(y, yrep, status_y, size = 0.5, alpha = 0.2)) - expect_gg(ppc_km_overlay(y2, yrep2, status_y2)) + expect_gg(ppc_km_overlay(y, yrep, status_y = status_y, size = 0.5, alpha = 0.2)) + expect_gg(ppc_km_overlay(y2, yrep2, status_y = status_y2)) }) test_that("ppc_dens,pp_hist,ppc_freqpoly,ppc_boxplot return ggplot objects", { @@ -136,13 +136,13 @@ test_that("ppc_km_overlay renders correctly", { testthat::skip_on_cran() testthat::skip_if_not_installed("vdiffr") - p_base <- ppc_km_overlay(vdiff_y2, vdiff_yrep2, vdiff_status_y2) + p_base <- ppc_km_overlay(vdiff_y2, vdiff_yrep2, status_y = vdiff_status_y2) vdiffr::expect_doppelganger("ppc_km_overlay (default)", p_base) p_custom <- ppc_km_overlay( vdiff_y2, vdiff_yrep2, - vdiff_status_y2, + status_y = vdiff_status_y2, size = 2, alpha = .2) vdiffr::expect_doppelganger("ppc_km_overlay (size, alpha)", p_custom) From c0116ebb6b5c12e88ca3a4802f8c8a2bdcdff569 Mon Sep 17 00:00:00 2001 From: fweber144 Date: Wed, 12 Aug 2020 14:08:00 +0200 Subject: [PATCH 12/36] Ran vdiffr::manage_cases() to validate the ppc_km_overlay() figures for the unit tests. --- .../ppc-km-overlay-default.svg | 67 +++++++++++++++++++ .../ppc-km-overlay-size-alpha.svg | 67 +++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 tests/figs/ppc-distributions/ppc-km-overlay-default.svg create mode 100644 tests/figs/ppc-distributions/ppc-km-overlay-size-alpha.svg diff --git a/tests/figs/ppc-distributions/ppc-km-overlay-default.svg b/tests/figs/ppc-distributions/ppc-km-overlay-default.svg new file mode 100644 index 00000000..27212f37 --- /dev/null +++ b/tests/figs/ppc-distributions/ppc-km-overlay-default.svg @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.0 +0.5 +1.0 + + + + + + + + + + +0 +1 +2 +3 +4 +5 + + +y +y +r +e +p +ppc_km_overlay (default) + diff --git a/tests/figs/ppc-distributions/ppc-km-overlay-size-alpha.svg b/tests/figs/ppc-distributions/ppc-km-overlay-size-alpha.svg new file mode 100644 index 00000000..6891e6ec --- /dev/null +++ b/tests/figs/ppc-distributions/ppc-km-overlay-size-alpha.svg @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.0 +0.5 +1.0 + + + + + + + + + + +0 +1 +2 +3 +4 +5 + + +y +y +r +e +p +ppc_km_overlay (size, alpha) + From d518368e099e8e20ef2ac7b95cdf50866aa6c777 Mon Sep 17 00:00:00 2001 From: fweber144 Date: Wed, 12 Aug 2020 14:23:43 +0200 Subject: [PATCH 13/36] In ppc_km_overlay(): Use aes_() instead of aes() for two reasons: - consistency with the existing code, - to prevent the NOTE "no visible binding for global variable" when running R CMD CHECK. --- R/ppc-distributions.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/R/ppc-distributions.R b/R/ppc-distributions.R index 7eed7b16..e0d02335 100644 --- a/R/ppc-distributions.R +++ b/R/ppc-distributions.R @@ -429,12 +429,12 @@ ppc_km_overlay <- # Plot: ggplot(data = fsf, - mapping = aes(x = time, - y = surv, - color = is_y_color, - group = strata, - size = is_y_size, - alpha = is_y_alpha)) + + mapping = aes_(x = ~ time, + y = ~ surv, + color = ~ is_y_color, + group = ~ strata, + size = ~ is_y_size, + alpha = ~ is_y_alpha)) + geom_step() + scale_size_identity() + scale_alpha_identity() + From a02442e7966317644968c456afdbdbb1ffeba883 Mon Sep 17 00:00:00 2001 From: fweber144 Date: Wed, 12 Aug 2020 14:56:26 +0200 Subject: [PATCH 14/36] In ppc_km_overlay(): Use '.data$' in the call to dplyr::mutate() to prevent the NOTE "no visible binding for global variable" when running R CMD CHECK. --- R/ppc-distributions.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/ppc-distributions.R b/R/ppc-distributions.R index e0d02335..d03c74a2 100644 --- a/R/ppc-distributions.R +++ b/R/ppc-distributions.R @@ -405,7 +405,7 @@ ppc_km_overlay <- # to "1 - ECDF" with ECDF denoting the ordinary empirical cumulative # distribution function. data <- data %>% - dplyr::mutate(group = ifelse(is_y, as.numeric(as.character(group)), 1)) + dplyr::mutate(group = ifelse(.data$is_y, as.numeric(as.character(.data$group)), 1)) # Create 'survfit' object: if(!requireNamespace("survival", quietly = TRUE)){ From 4d6ae9d6dced41ce38f49f2519b9ce273026b225 Mon Sep 17 00:00:00 2001 From: fweber144 Date: Wed, 12 Aug 2020 14:57:58 +0200 Subject: [PATCH 15/36] In ppc_km_overlay(): Indent the call to dplyr::mutate(). --- R/ppc-distributions.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/ppc-distributions.R b/R/ppc-distributions.R index d03c74a2..e9358c67 100644 --- a/R/ppc-distributions.R +++ b/R/ppc-distributions.R @@ -405,7 +405,9 @@ ppc_km_overlay <- # to "1 - ECDF" with ECDF denoting the ordinary empirical cumulative # distribution function. data <- data %>% - dplyr::mutate(group = ifelse(.data$is_y, as.numeric(as.character(.data$group)), 1)) + dplyr::mutate(group = ifelse(.data$is_y, + as.numeric(as.character(.data$group)), + 1)) # Create 'survfit' object: if(!requireNamespace("survival", quietly = TRUE)){ From ce5df552572686b239cf1e2599dd5d889966b1f3 Mon Sep 17 00:00:00 2001 From: fweber144 Date: Wed, 26 Aug 2020 14:52:24 +0200 Subject: [PATCH 16/36] Fix the NOTE "release_questions: missing arguments not allowed in calls to 'c'" thrown by devtools::check(). --- R/bayesplot-package.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/bayesplot-package.R b/R/bayesplot-package.R index a0697fbd..a886f7c0 100644 --- a/R/bayesplot-package.R +++ b/R/bayesplot-package.R @@ -98,6 +98,6 @@ NULL # release reminders (for devtools) release_questions <- function() { # nocov start c( - "Have you reduced the size of the vignettes for CRAN?", + "Have you reduced the size of the vignettes for CRAN?" ) } # nocov end From b9d53c550367b907985ef30d4473d24c52bac7c7 Mon Sep 17 00:00:00 2001 From: fweber144 Date: Wed, 26 Aug 2020 15:00:44 +0200 Subject: [PATCH 17/36] Add argument "check_unq" to validate_group() telling it whether or not to error if there is only one unique value. --- R/helpers-ppc.R | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/R/helpers-ppc.R b/R/helpers-ppc.R index 5abebbc6..40220029 100644 --- a/R/helpers-ppc.R +++ b/R/helpers-ppc.R @@ -71,9 +71,11 @@ validate_yrep <- function(yrep, y) { #' factor variable. #' #' @param group,y The user's `group` object and the `y` object returned by `validate_y()`. +#' @param check_unq A logical flag indicating whether or not to error if there is only one +#' unique value in `group`. #' @return Either throws an error or returns `group` (coerced to a factor). #' @noRd -validate_group <- function(group, y) { +validate_group <- function(group, y, check_unq = TRUE) { stopifnot(is.vector(group) || is.factor(group)) if (!is.factor(group)) { @@ -88,8 +90,10 @@ validate_group <- function(group, y) { abort("length(group) must be equal to length(y).") } - if (length(unique(group)) == 1) { - abort("'group' must have more than one unique value.") + if (isTRUE(check_unq)) { + if (length(unique(group)) == 1) { + abort("'group' must have more than one unique value.") + } } unname(group) From 52036c89051eef494544cfc2b1f561718eac63ea Mon Sep 17 00:00:00 2001 From: fweber144 Date: Wed, 26 Aug 2020 15:01:51 +0200 Subject: [PATCH 18/36] Use the new argument "check_unq" of validate_group() in ppc_km_overlay(). --- R/ppc-distributions.R | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/R/ppc-distributions.R b/R/ppc-distributions.R index e9358c67..03212d37 100644 --- a/R/ppc-distributions.R +++ b/R/ppc-distributions.R @@ -14,7 +14,7 @@ #' @template args-dens #' @param size,alpha Passed to the appropriate geom to control the appearance of #' the `yrep` distributions. -#' @param ... Currently unused. +#' @param ... Mainly unused and if used, then only relevant for internal usage. #' #' @template details-binomial #' @template return-ggplot-or-data @@ -109,13 +109,14 @@ NULL #' @rdname PPC-distributions #' @export -ppc_data <- function(y, yrep, group = NULL) { +ppc_data <- function(y, yrep, group = NULL, ...) { + check_ignored_arguments(..., ok_args = "check_unq") y <- validate_y(y) yrep <- validate_yrep(yrep, y) data <- melt_and_stack(y, yrep) if (!is.null(group)) { - group <- validate_group(group, y) + group <- validate_group(group, y, ...) group_indices <- tibble::tibble(group, y_id = seq_along(group)) data <- data %>% left_join(group_indices, by = "y_id") %>% @@ -395,7 +396,7 @@ ppc_km_overlay <- stopifnot(all(status_y %in% c(0, 1))) # Create basic PPC dataset: - data <- ppc_data(y, yrep, group = status_y) + data <- ppc_data(y, yrep, group = status_y, check_unq = FALSE) # Modify the status indicator: # * For the observed data ("y"), convert the status indicator back to From 6bdc102ba6835820c5fdff9bd2c8dee7e5f6975c Mon Sep 17 00:00:00 2001 From: fweber144 Date: Wed, 26 Aug 2020 15:08:37 +0200 Subject: [PATCH 19/36] Re-ran roxygen2 to update the documentation. --- man/PPC-distributions.Rd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/man/PPC-distributions.Rd b/man/PPC-distributions.Rd index 1de4154c..8b066bdc 100644 --- a/man/PPC-distributions.Rd +++ b/man/PPC-distributions.Rd @@ -14,7 +14,7 @@ \alias{ppc_violin_grouped} \title{PPC distributions} \usage{ -ppc_data(y, yrep, group = NULL) +ppc_data(y, yrep, group = NULL, ...) ppc_hist(y, yrep, ..., binwidth = NULL, breaks = NULL, freq = TRUE) @@ -96,7 +96,7 @@ sense. See \strong{Details} for additional instructions.} \code{y}. Each value in \code{group} is interpreted as the group level pertaining to the corresponding value of \code{y}.} -\item{...}{Currently unused.} +\item{...}{Mainly unused and if used, then only relevant for internal usage.} \item{binwidth}{Passed to \code{\link[ggplot2:geom_histogram]{ggplot2::geom_histogram()}} to override the default binwidth.} From b9345af7049af5ce5365baecfcb6684603341cfb Mon Sep 17 00:00:00 2001 From: jgabry Date: Thu, 10 Sep 2020 10:21:16 -0600 Subject: [PATCH 20/36] remove check for unique group values --- R/helpers-ppc.R | 13 +++---------- R/ppc-distributions.R | 9 ++++----- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/R/helpers-ppc.R b/R/helpers-ppc.R index 40220029..1f8ee245 100644 --- a/R/helpers-ppc.R +++ b/R/helpers-ppc.R @@ -70,12 +70,11 @@ validate_yrep <- function(yrep, y) { #' Checks that grouping variable has same length as `y` and is either a vector or #' factor variable. #' -#' @param group,y The user's `group` object and the `y` object returned by `validate_y()`. -#' @param check_unq A logical flag indicating whether or not to error if there is only one -#' unique value in `group`. +#' @param group,y The user's `group` object and the `y` object returned by +#' `validate_y()`. #' @return Either throws an error or returns `group` (coerced to a factor). #' @noRd -validate_group <- function(group, y, check_unq = TRUE) { +validate_group <- function(group, y) { stopifnot(is.vector(group) || is.factor(group)) if (!is.factor(group)) { @@ -90,12 +89,6 @@ validate_group <- function(group, y, check_unq = TRUE) { abort("length(group) must be equal to length(y).") } - if (isTRUE(check_unq)) { - if (length(unique(group)) == 1) { - abort("'group' must have more than one unique value.") - } - } - unname(group) } diff --git a/R/ppc-distributions.R b/R/ppc-distributions.R index 03212d37..e9358c67 100644 --- a/R/ppc-distributions.R +++ b/R/ppc-distributions.R @@ -14,7 +14,7 @@ #' @template args-dens #' @param size,alpha Passed to the appropriate geom to control the appearance of #' the `yrep` distributions. -#' @param ... Mainly unused and if used, then only relevant for internal usage. +#' @param ... Currently unused. #' #' @template details-binomial #' @template return-ggplot-or-data @@ -109,14 +109,13 @@ NULL #' @rdname PPC-distributions #' @export -ppc_data <- function(y, yrep, group = NULL, ...) { - check_ignored_arguments(..., ok_args = "check_unq") +ppc_data <- function(y, yrep, group = NULL) { y <- validate_y(y) yrep <- validate_yrep(yrep, y) data <- melt_and_stack(y, yrep) if (!is.null(group)) { - group <- validate_group(group, y, ...) + group <- validate_group(group, y) group_indices <- tibble::tibble(group, y_id = seq_along(group)) data <- data %>% left_join(group_indices, by = "y_id") %>% @@ -396,7 +395,7 @@ ppc_km_overlay <- stopifnot(all(status_y %in% c(0, 1))) # Create basic PPC dataset: - data <- ppc_data(y, yrep, group = status_y, check_unq = FALSE) + data <- ppc_data(y, yrep, group = status_y) # Modify the status indicator: # * For the observed data ("y"), convert the status indicator back to From c7cb255e9ba8aae4b69ae3e2bd4a84cdb74861bd Mon Sep 17 00:00:00 2001 From: jgabry Date: Thu, 10 Sep 2020 10:21:35 -0600 Subject: [PATCH 21/36] move suggested package checks to top this way we error before doing any computations --- R/ppc-distributions.R | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/R/ppc-distributions.R b/R/ppc-distributions.R index e9358c67..1ab8db14 100644 --- a/R/ppc-distributions.R +++ b/R/ppc-distributions.R @@ -390,6 +390,13 @@ ppc_km_overlay <- alpha = 0.7) { check_ignored_arguments(...) + if(!requireNamespace("survival", quietly = TRUE)){ + abort("Package 'survival' required.") + } + if(!requireNamespace("ggfortify", quietly = TRUE)){ + abort("Package 'ggfortify' required.") + } + # Checks for 'status_y': stopifnot(is.numeric(status_y)) stopifnot(all(status_y %in% c(0, 1))) @@ -409,19 +416,11 @@ ppc_km_overlay <- as.numeric(as.character(.data$group)), 1)) - # Create 'survfit' object: - if(!requireNamespace("survival", quietly = TRUE)){ - abort("Package 'survival' required.") - } + # Create 'survfit' object and 'fortify' it sf <- survival::survfit( survival::Surv(value, group) ~ rep_label, data = data ) - - # "Fortify" the 'survfit' object: - if(!requireNamespace("ggfortify", quietly = TRUE)){ - abort("Package 'ggfortify' required.") - } fsf <- fortify(sf) # Add variables specifying color, size, and alpha: From 34a445eea556862fa20368f4c3f6025a219c45aa Mon Sep 17 00:00:00 2001 From: fweber144 Date: Fri, 18 Sep 2020 10:06:22 +0200 Subject: [PATCH 22/36] In ppc_km_overlay(): Ensure that the observed data gets plotted last by reordering the levels of the factor "strata". --- R/ppc-distributions.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/ppc-distributions.R b/R/ppc-distributions.R index 1ab8db14..f9d87e80 100644 --- a/R/ppc-distributions.R +++ b/R/ppc-distributions.R @@ -428,6 +428,10 @@ ppc_km_overlay <- fsf$is_y_size <- ifelse(fsf$is_y_color == "yrep", size, 1) fsf$is_y_alpha <- ifelse(fsf$is_y_color == "yrep", alpha, 1) + # Ensure that the observed data gets plotted last by reordering the + # levels of the factor "strata": + fsf$strata <- factor(fsf$strata, levels = rev(levels(fsf$strata))) + # Plot: ggplot(data = fsf, mapping = aes_(x = ~ time, From 72cea0e9f13f07dde66c2b2f80dd06b6738d6e9f Mon Sep 17 00:00:00 2001 From: fweber144 Date: Fri, 18 Sep 2020 10:07:07 +0200 Subject: [PATCH 23/36] Re-ran roxygen2 to update the documentation. --- man/PPC-distributions.Rd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/man/PPC-distributions.Rd b/man/PPC-distributions.Rd index 8b066bdc..1de4154c 100644 --- a/man/PPC-distributions.Rd +++ b/man/PPC-distributions.Rd @@ -14,7 +14,7 @@ \alias{ppc_violin_grouped} \title{PPC distributions} \usage{ -ppc_data(y, yrep, group = NULL, ...) +ppc_data(y, yrep, group = NULL) ppc_hist(y, yrep, ..., binwidth = NULL, breaks = NULL, freq = TRUE) @@ -96,7 +96,7 @@ sense. See \strong{Details} for additional instructions.} \code{y}. Each value in \code{group} is interpreted as the group level pertaining to the corresponding value of \code{y}.} -\item{...}{Mainly unused and if used, then only relevant for internal usage.} +\item{...}{Currently unused.} \item{binwidth}{Passed to \code{\link[ggplot2:geom_histogram]{ggplot2::geom_histogram()}} to override the default binwidth.} From 5323a1dc97a7147a6e9d1eef47eb8edffe7f11f4 Mon Sep 17 00:00:00 2001 From: fweber144 Date: Fri, 18 Sep 2020 10:29:30 +0200 Subject: [PATCH 24/36] Update the tests Simply remove those tests which are not up-to-date anymore since argument "group" of validate_group() is now allowed to have a single unique value. --- tests/testthat/test-ppc-distributions.R | 6 ------ tests/testthat/test-ppc-errors.R | 2 -- tests/testthat/test-ppc-input-validation.R | 2 -- tests/testthat/test-ppc-scatterplots.R | 3 --- tests/testthat/test-ppc-test-statistics.R | 3 --- 5 files changed, 16 deletions(-) diff --git a/tests/testthat/test-ppc-distributions.R b/tests/testthat/test-ppc-distributions.R index 0d4eacd7..469fb603 100644 --- a/tests/testthat/test-ppc-distributions.R +++ b/tests/testthat/test-ppc-distributions.R @@ -44,9 +44,6 @@ test_that("ppc_freqpoly_grouped returns a ggplot object", { expect_gg(ppc_freqpoly_grouped(y, yrep[1:4, ], group)) expect_gg(ppc_freqpoly_grouped(y, yrep[1:4, ], group, freq = TRUE, alpha = 0.5)) - - expect_error(ppc_freqpoly_grouped(y2, yrep2, group2), - "'group' must have more than one unique value") }) test_that("ppc_violin_grouped returns a ggplot object", { @@ -54,9 +51,6 @@ test_that("ppc_violin_grouped returns a ggplot object", { expect_gg(ppc_violin_grouped(y, yrep, as.numeric(group))) expect_gg(ppc_violin_grouped(y, yrep, as.integer(group))) expect_gg(ppc_violin_grouped(y, yrep, group, y_draw = "both", y_jitter = 0.3)) - - expect_error(ppc_violin_grouped(y2, yrep2, group2), - "'group' must have more than one unique value") }) diff --git a/tests/testthat/test-ppc-errors.R b/tests/testthat/test-ppc-errors.R index 253c9709..008569d4 100644 --- a/tests/testthat/test-ppc-errors.R +++ b/tests/testthat/test-ppc-errors.R @@ -18,8 +18,6 @@ test_that("ppc_error_hist_grouped returns ggplot object", { expect_gg(ppc_error_hist_grouped(y, yrep[1:5, ], group)) expect_gg(ppc_error_hist_grouped(y, yrep[1,, drop = FALSE], group, freq = FALSE, binwidth = 1)) - expect_error(ppc_error_hist_grouped(y2, yrep2, group2), - "'group' must have more than one unique value") }) test_that("ppc_error_scatter_avg returns ggplot2 object", { diff --git a/tests/testthat/test-ppc-input-validation.R b/tests/testthat/test-ppc-input-validation.R index 6d4246cf..93bbbd77 100644 --- a/tests/testthat/test-ppc-input-validation.R +++ b/tests/testthat/test-ppc-input-validation.R @@ -46,8 +46,6 @@ test_that("validate_group throws errors", { expect_error(validate_group(array(1:3), y = 1:3), "vector") expect_error(validate_group(c(1,2,NA), y = 1:3), "NAs not allowed") expect_error(validate_group(1:4, y = 1:3), "must be equal to") - expect_error(validate_group(rep(1,3), y = 1:3), - "must have more than one unique value") }) diff --git a/tests/testthat/test-ppc-scatterplots.R b/tests/testthat/test-ppc-scatterplots.R index d4b7b7c3..7669d1c5 100644 --- a/tests/testthat/test-ppc-scatterplots.R +++ b/tests/testthat/test-ppc-scatterplots.R @@ -25,9 +25,6 @@ test_that("ppc_scatter_avg_grouped returns a ggplot object", { expect_gg(ppc_scatter_avg_grouped(y, yrep, group)) expect_gg(ppc_scatter_avg_grouped(y, yrep, as.numeric(group))) expect_gg(ppc_scatter_avg_grouped(y, yrep, as.integer(group))) - - expect_error(ppc_scatter_avg_grouped(y2, yrep2, group2), - "'group' must have more than one unique value") }) diff --git a/tests/testthat/test-ppc-test-statistics.R b/tests/testthat/test-ppc-test-statistics.R index d2756c87..6da5c6c2 100644 --- a/tests/testthat/test-ppc-test-statistics.R +++ b/tests/testthat/test-ppc-test-statistics.R @@ -48,9 +48,6 @@ test_that("ppc_stat_grouped returns ggplot object", { expect_gg(ppc_stat_grouped(y, yrep, group)) expect_gg(ppc_stat_grouped(y, yrep, as.numeric(group), stat = function(z) var(z))) expect_gg(ppc_stat_grouped(y, yrep, as.integer(group), stat = "sd")) - - expect_error(ppc_stat_grouped(y2, yrep2, group2), - "'group' must have more than one unique value") }) test_that("ppc_stat_freqpoly_grouped returns ggplot object", { expect_gg(ppc_stat_freqpoly_grouped(y, yrep, group, stat = "sd", freq = FALSE)) From 43fe549d95a836a2408a4b8aa72ea1585865c2f4 Mon Sep 17 00:00:00 2001 From: fweber144 Date: Fri, 18 Sep 2020 10:30:58 +0200 Subject: [PATCH 25/36] Update the expected results for the visual ppc_km_overlay() tests. --- .../ppc-km-overlay-default.svg | 20 +++++++++---------- .../ppc-km-overlay-size-alpha.svg | 20 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/figs/ppc-distributions/ppc-km-overlay-default.svg b/tests/figs/ppc-distributions/ppc-km-overlay-default.svg index 27212f37..c9a18e10 100644 --- a/tests/figs/ppc-distributions/ppc-km-overlay-default.svg +++ b/tests/figs/ppc-distributions/ppc-km-overlay-default.svg @@ -17,17 +17,17 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/tests/figs/ppc-distributions/ppc-km-overlay-size-alpha.svg b/tests/figs/ppc-distributions/ppc-km-overlay-size-alpha.svg index 6891e6ec..0284d7e1 100644 --- a/tests/figs/ppc-distributions/ppc-km-overlay-size-alpha.svg +++ b/tests/figs/ppc-distributions/ppc-km-overlay-size-alpha.svg @@ -17,17 +17,17 @@ - - - - - - - - - - + + + + + + + + + + From 079617e1b07f131bd941a211afda7d09b3097967 Mon Sep 17 00:00:00 2001 From: jgabry Date: Mon, 28 Sep 2020 17:01:55 -0600 Subject: [PATCH 26/36] Update NEWS and add Frank Weber as contributor --- DESCRIPTION | 9 +++++---- NEWS.md | 6 ++++++ R/ppc-distributions.R | 6 +++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 241ad3a4..b8bace3d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -7,7 +7,8 @@ Authors@R: c(person("Jonah", "Gabry", role = c("aut", "cre"), email = "jsg2201@c person("Tristan", "Mahr", role = "aut"), person("Paul-Christian", "Bürkner", role = "ctb"), person("Martin", "Modrák", role = "ctb"), - person("Malcolm", "Barrett", role = "ctb")) + person("Malcolm", "Barrett", role = "ctb"), + person("Frank", "Weber", role = "ctb")) Maintainer: Jonah Gabry Description: Plotting functions for posterior analysis, MCMC diagnostics, prior and posterior predictive checks, and other visualizations @@ -36,6 +37,7 @@ Imports: tidyselect, utils Suggests: + ggfortify gridExtra (>= 2.2.1), hexbin, knitr (>= 1.16), @@ -47,10 +49,9 @@ Suggests: rstantools (>= 1.5.0), scales, shinystan (>= 2.3.0), - testthat (>= 2.0.0), - vdiffr, survival, - ggfortify + testthat (>= 2.0.0), + vdiffr RoxygenNote: 7.1.1 VignetteBuilder: knitr Encoding: UTF-8 diff --git a/NEWS.md b/NEWS.md index 46c528e1..720d1d33 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,13 +8,19 @@ * Items for next release go here --> +* New plotting function `ppc_km_overlay()` for outcome variables that are + right-censored. Empirical CCDF estimates of `yrep` are compared with the + Kaplan-Meier estimate of `y`. (#233, #234, @fweber144) + * CmdStanMCMC objects (from CmdStanR) can now be used with extractor functions `nuts_params()`, `log_posterior()`, `rhat()`, and `neff_ratio()`. (#227) * Added missing `facet_args` argument to `mcmc_rank_overlay()`. (#221, @hhau) + * Size of points and interval lines can set in `mcmc_intervals(..., outer_size, inner_size, point_size)`. (#215, #228, #229) + * `mcmc_areas()` tries to use less blank vertical blank space. (#218, #230) diff --git a/R/ppc-distributions.R b/R/ppc-distributions.R index f9d87e80..eb14a24a 100644 --- a/R/ppc-distributions.R +++ b/R/ppc-distributions.R @@ -441,17 +441,17 @@ ppc_km_overlay <- size = ~ is_y_size, alpha = ~ is_y_alpha)) + geom_step() + - scale_size_identity() + - scale_alpha_identity() + hline_at( c(0, 0.5, 1), size = c(0.2, 0.1, 0.2), linetype = 2, color = get_color("dh") ) + + scale_size_identity() + + scale_alpha_identity() + scale_color_ppc_dist() + - xlab(y_label()) + scale_y_continuous(breaks = c(0, 0.5, 1)) + + xlab(y_label()) + yaxis_title(FALSE) + xaxis_title(FALSE) + yaxis_ticks(FALSE) + From 7cd815d6ab95266b6e2212fc833d7e7616d3dc3c Mon Sep 17 00:00:00 2001 From: jgabry Date: Mon, 28 Sep 2020 17:06:43 -0600 Subject: [PATCH 27/36] add missing comma in Suggests --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index b8bace3d..8241c261 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -37,7 +37,7 @@ Imports: tidyselect, utils Suggests: - ggfortify + ggfortify, gridExtra (>= 2.2.1), hexbin, knitr (>= 1.16), From d50b7ddd2f7b6c8ce3d1b9a2d9d3777bedb2820b Mon Sep 17 00:00:00 2001 From: fweber144 Date: Wed, 30 Sep 2020 15:12:09 +0200 Subject: [PATCH 28/36] Moved ppc_km_overlay() from ppc-distributions.R to ppc-censoring.R to create a new documentation page "PPC-censoring". --- R/ppc-censoring.R | 121 ++++++++++++++++++++++++++++++++++++++++++ R/ppc-distributions.R | 88 ------------------------------ 2 files changed, 121 insertions(+), 88 deletions(-) create mode 100644 R/ppc-censoring.R diff --git a/R/ppc-censoring.R b/R/ppc-censoring.R new file mode 100644 index 00000000..8090b748 --- /dev/null +++ b/R/ppc-censoring.R @@ -0,0 +1,121 @@ +#' PPC censoring +#' +#' Compare the empirical distribution of censored data `y` to the distributions +#' of simulated/replicated data `yrep` from the posterior predictive +#' distribution. See the **Plot Descriptions** section, below, +#' for details. +#' +#' @name PPC-censoring +#' @family PPCs +#' +#' @template args-y-yrep +#' @param size,alpha Passed to the appropriate geom to control the appearance of +#' the `yrep` distributions. +#' @param ... Currently unused. +#' +#' @template return-ggplot +#' +#' @section Plot Descriptions: +#' \describe{ +#' \item{`ppc_km_overlay()`}{ +#' Empirical CCDF estimates of each dataset (row) in `yrep` are overlaid, +#' with the Kaplan-Meier estimate for `y` itself on top (and in a darker +#' shade). This is a PPC suitable for right-censored `y`. Note that the +#' replicated data from `yrep` is assumed to be uncensored. +#' } +#' } +#' +#' @templateVar bdaRef (Ch. 6) +#' @template reference-bda +#' +#' @examples +#' color_scheme_set("brightblue") +#' y <- example_y_data() +#' yrep <- example_yrep_draws() +#' dim(yrep) +#' \donttest{ +#' ppc_km_overlay(y, yrep[1:25, ]) +#' } +NULL + +#' @export +#' @rdname PPC-censoring +#' @param status_y The status indicator for the observations from `y`. This must +#' be a numeric vector of the same length as `y` with values in \{0, 1\} (0 = +#' right censored, 1 = event). +ppc_km_overlay <- + function(y, + yrep, + ..., + status_y, + size = 0.25, + alpha = 0.7) { + check_ignored_arguments(...) + + if(!requireNamespace("survival", quietly = TRUE)){ + abort("Package 'survival' required.") + } + if(!requireNamespace("ggfortify", quietly = TRUE)){ + abort("Package 'ggfortify' required.") + } + + # Checks for 'status_y': + stopifnot(is.numeric(status_y)) + stopifnot(all(status_y %in% c(0, 1))) + + # Create basic PPC dataset: + data <- ppc_data(y, yrep, group = status_y) + + # Modify the status indicator: + # * For the observed data ("y"), convert the status indicator back to + # a numeric. + # * For the replicated data ("yrep"), set the status indicator + # to 1 ("event"). This way, the Kaplan-Meier estimator reduces + # to "1 - ECDF" with ECDF denoting the ordinary empirical cumulative + # distribution function. + data <- data %>% + dplyr::mutate(group = ifelse(.data$is_y, + as.numeric(as.character(.data$group)), + 1)) + + # Create 'survfit' object and 'fortify' it + sf <- survival::survfit( + survival::Surv(value, group) ~ rep_label, + data = data + ) + fsf <- fortify(sf) + + # Add variables specifying color, size, and alpha: + fsf$is_y_color <- as.factor(sub("\\[rep\\] \\(.*$", "rep", sub("^italic\\(y\\)", "y", fsf$strata))) + fsf$is_y_size <- ifelse(fsf$is_y_color == "yrep", size, 1) + fsf$is_y_alpha <- ifelse(fsf$is_y_color == "yrep", alpha, 1) + + # Ensure that the observed data gets plotted last by reordering the + # levels of the factor "strata": + fsf$strata <- factor(fsf$strata, levels = rev(levels(fsf$strata))) + + # Plot: + ggplot(data = fsf, + mapping = aes_(x = ~ time, + y = ~ surv, + color = ~ is_y_color, + group = ~ strata, + size = ~ is_y_size, + alpha = ~ is_y_alpha)) + + geom_step() + + hline_at( + c(0, 0.5, 1), + size = c(0.2, 0.1, 0.2), + linetype = 2, + color = get_color("dh") + ) + + scale_size_identity() + + scale_alpha_identity() + + scale_color_ppc_dist() + + scale_y_continuous(breaks = c(0, 0.5, 1)) + + xlab(y_label()) + + yaxis_title(FALSE) + + xaxis_title(FALSE) + + yaxis_ticks(FALSE) + + bayesplot_theme_get() + } diff --git a/R/ppc-distributions.R b/R/ppc-distributions.R index eb14a24a..7f9a5ffd 100644 --- a/R/ppc-distributions.R +++ b/R/ppc-distributions.R @@ -40,12 +40,6 @@ #' data, set the `discrete` argument to `TRUE` for better results. #' For an example of `ppc_dens_overlay()` also see Gabry et al. (2019). #' } -#' \item{`ppc_km_overlay()`}{ -#' Empirical CCDF estimates of each dataset (row) in `yrep` are overlaid, -#' with the Kaplan-Meier estimate of `y` itself on top (and in a darker -#' shade). This is a PPC suitable for right-censored `y`. Note that the -#' replicated data from `yrep` is assumed to be uncensored. -#' } #' \item{`ppc_violin_grouped()`}{ #' The density estimate of `yrep` within each level of a grouping #' variable is plotted as a violin with horizontal lines at notable @@ -376,88 +370,6 @@ ppc_ecdf_overlay <- bayesplot_theme_get() } -#' @export -#' @rdname PPC-distributions -#' @param status_y The status indicator for the observations from `y`. This must -#' be a numeric vector of the same length as `y` with values in \{0, 1\} (0 = -#' right censored, 1 = event). -ppc_km_overlay <- - function(y, - yrep, - ..., - status_y, - size = 0.25, - alpha = 0.7) { - check_ignored_arguments(...) - - if(!requireNamespace("survival", quietly = TRUE)){ - abort("Package 'survival' required.") - } - if(!requireNamespace("ggfortify", quietly = TRUE)){ - abort("Package 'ggfortify' required.") - } - - # Checks for 'status_y': - stopifnot(is.numeric(status_y)) - stopifnot(all(status_y %in% c(0, 1))) - - # Create basic PPC dataset: - data <- ppc_data(y, yrep, group = status_y) - - # Modify the status indicator: - # * For the observed data ("y"), convert the status indicator back to - # a numeric. - # * For the replicated data ("yrep"), set the status indicator - # to 1 ("event"). This way, the Kaplan-Meier estimator reduces - # to "1 - ECDF" with ECDF denoting the ordinary empirical cumulative - # distribution function. - data <- data %>% - dplyr::mutate(group = ifelse(.data$is_y, - as.numeric(as.character(.data$group)), - 1)) - - # Create 'survfit' object and 'fortify' it - sf <- survival::survfit( - survival::Surv(value, group) ~ rep_label, - data = data - ) - fsf <- fortify(sf) - - # Add variables specifying color, size, and alpha: - fsf$is_y_color <- as.factor(sub("\\[rep\\] \\(.*$", "rep", sub("^italic\\(y\\)", "y", fsf$strata))) - fsf$is_y_size <- ifelse(fsf$is_y_color == "yrep", size, 1) - fsf$is_y_alpha <- ifelse(fsf$is_y_color == "yrep", alpha, 1) - - # Ensure that the observed data gets plotted last by reordering the - # levels of the factor "strata": - fsf$strata <- factor(fsf$strata, levels = rev(levels(fsf$strata))) - - # Plot: - ggplot(data = fsf, - mapping = aes_(x = ~ time, - y = ~ surv, - color = ~ is_y_color, - group = ~ strata, - size = ~ is_y_size, - alpha = ~ is_y_alpha)) + - geom_step() + - hline_at( - c(0, 0.5, 1), - size = c(0.2, 0.1, 0.2), - linetype = 2, - color = get_color("dh") - ) + - scale_size_identity() + - scale_alpha_identity() + - scale_color_ppc_dist() + - scale_y_continuous(breaks = c(0, 0.5, 1)) + - xlab(y_label()) + - yaxis_title(FALSE) + - xaxis_title(FALSE) + - yaxis_ticks(FALSE) + - bayesplot_theme_get() - } - #' @export #' @rdname PPC-distributions #' @param probs A numeric vector passed to [ggplot2::geom_violin()]'s From 33d54321f84d0e75334f0a8d403ef593093ed4da Mon Sep 17 00:00:00 2001 From: fweber144 Date: Wed, 30 Sep 2020 15:41:43 +0200 Subject: [PATCH 29/36] Adopt the example for censored data. --- R/ppc-censoring.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/R/ppc-censoring.R b/R/ppc-censoring.R index 8090b748..c1660ebe 100644 --- a/R/ppc-censoring.R +++ b/R/ppc-censoring.R @@ -31,10 +31,16 @@ #' @examples #' color_scheme_set("brightblue") #' y <- example_y_data() +#' # For illustrative purposes, (right-)censor values y > 110: +#' status_y <- as.numeric(y <= 110) +#' y <- pmin(y, 110) +#' # In reality, the replicated data (yrep) would be obtained from a +#' # model which takes the censoring of y properly into account. Here, +#' # for illustrative purposes, we simply use example_yrep_draws(): #' yrep <- example_yrep_draws() #' dim(yrep) #' \donttest{ -#' ppc_km_overlay(y, yrep[1:25, ]) +#' ppc_km_overlay(y, yrep[1:25, ], status_y = status_y) #' } NULL From fe6eb2b60241408823ce1309def6b746e8de6443 Mon Sep 17 00:00:00 2001 From: fweber144 Date: Wed, 30 Sep 2020 15:57:33 +0200 Subject: [PATCH 30/36] Add a reference for Kaplan and Meier (1958). --- R/ppc-censoring.R | 8 +++++--- man-roxygen/reference-km.R | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 man-roxygen/reference-km.R diff --git a/R/ppc-censoring.R b/R/ppc-censoring.R index c1660ebe..31f661fa 100644 --- a/R/ppc-censoring.R +++ b/R/ppc-censoring.R @@ -19,14 +19,16 @@ #' \describe{ #' \item{`ppc_km_overlay()`}{ #' Empirical CCDF estimates of each dataset (row) in `yrep` are overlaid, -#' with the Kaplan-Meier estimate for `y` itself on top (and in a darker -#' shade). This is a PPC suitable for right-censored `y`. Note that the -#' replicated data from `yrep` is assumed to be uncensored. +#' with the Kaplan-Meier estimate (Kaplan and Meier, 1958) for `y` itself +#' on top (and in a darker shade). This is a PPC suitable for +#' right-censored `y`. Note that the replicated data from `yrep` is assumed +#' to be uncensored. #' } #' } #' #' @templateVar bdaRef (Ch. 6) #' @template reference-bda +#' @template reference-km #' #' @examples #' color_scheme_set("brightblue") diff --git a/man-roxygen/reference-km.R b/man-roxygen/reference-km.R new file mode 100644 index 00000000..340be1d1 --- /dev/null +++ b/man-roxygen/reference-km.R @@ -0,0 +1,3 @@ +#' @references Kaplan, E. L. and Meier, P. (1958), Nonparametric estimation +#' from incomplete observations. *J. Am. Stat. Assoc.*, 53(282): 457-481. +#' doi:10.1080/01621459.1958.10501452. From 3836da1216c3423767fb8f31f194bd9b0d9eb5b0 Mon Sep 17 00:00:00 2001 From: fweber144 Date: Wed, 30 Sep 2020 16:07:18 +0200 Subject: [PATCH 31/36] For Kaplan and Meier (1958), follow the citation style from "reference-loo.R". --- man-roxygen/reference-km.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/man-roxygen/reference-km.R b/man-roxygen/reference-km.R index 340be1d1..48f72212 100644 --- a/man-roxygen/reference-km.R +++ b/man-roxygen/reference-km.R @@ -1,3 +1,4 @@ -#' @references Kaplan, E. L. and Meier, P. (1958), Nonparametric estimation -#' from incomplete observations. *J. Am. Stat. Assoc.*, 53(282): 457-481. +#' @references Kaplan, E. L. and Meier, P. (1958). Nonparametric estimation +#' from incomplete observations. +#' *Journal of the American Statistical Association*. 53(282), 457--481. #' doi:10.1080/01621459.1958.10501452. From 14bfa1a95af325035a62668f371ef87b271ffe55 Mon Sep 17 00:00:00 2001 From: fweber144 Date: Wed, 30 Sep 2020 16:08:53 +0200 Subject: [PATCH 32/36] Re-ran roxygen2 to update the documentation. --- man/PPC-censoring.Rd | 87 ++++++++++++++++++++++++++++++++++++++ man/PPC-discrete.Rd | 1 + man/PPC-distributions.Rd | 14 +----- man/PPC-errors.Rd | 1 + man/PPC-intervals.Rd | 1 + man/PPC-loo.Rd | 1 + man/PPC-overview.Rd | 1 + man/PPC-scatterplots.Rd | 1 + man/PPC-test-statistics.Rd | 1 + 9 files changed, 95 insertions(+), 13 deletions(-) create mode 100644 man/PPC-censoring.Rd diff --git a/man/PPC-censoring.Rd b/man/PPC-censoring.Rd new file mode 100644 index 00000000..2a2a5331 --- /dev/null +++ b/man/PPC-censoring.Rd @@ -0,0 +1,87 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ppc-censoring.R +\name{PPC-censoring} +\alias{PPC-censoring} +\alias{ppc_km_overlay} +\title{PPC censoring} +\usage{ +ppc_km_overlay(y, yrep, ..., status_y, size = 0.25, alpha = 0.7) +} +\arguments{ +\item{y}{A vector of observations. See \strong{Details}.} + +\item{yrep}{An \eqn{S} by \eqn{N} matrix of draws from the posterior +predictive distribution, where \eqn{S} is the size of the posterior sample +(or subset of the posterior sample used to generate \code{yrep}) and \eqn{N} is +the number of observations (the length of \code{y}). The columns of \code{yrep} +should be in the same order as the data points in \code{y} for the plots to make +sense. See \strong{Details} for additional instructions.} + +\item{...}{Currently unused.} + +\item{status_y}{The status indicator for the observations from \code{y}. This must +be a numeric vector of the same length as \code{y} with values in \{0, 1\} (0 = +right censored, 1 = event).} + +\item{size, alpha}{Passed to the appropriate geom to control the appearance of +the \code{yrep} distributions.} +} +\value{ +A ggplot object that can be further customized using the \strong{ggplot2} package. +} +\description{ +Compare the empirical distribution of censored data \code{y} to the distributions +of simulated/replicated data \code{yrep} from the posterior predictive +distribution. See the \strong{Plot Descriptions} section, below, +for details. +} +\section{Plot Descriptions}{ + +\describe{ +\item{\code{ppc_km_overlay()}}{ +Empirical CCDF estimates of each dataset (row) in \code{yrep} are overlaid, +with the Kaplan-Meier estimate (Kaplan and Meier, 1958) for \code{y} itself +on top (and in a darker shade). This is a PPC suitable for +right-censored \code{y}. Note that the replicated data from \code{yrep} is assumed +to be uncensored. +} +} +} + +\examples{ +color_scheme_set("brightblue") +y <- example_y_data() +# For illustrative purposes, (right-)censor values y > 110: +status_y <- as.numeric(y <= 110) +y <- pmin(y, 110) +# In reality, the replicated data (yrep) would be obtained from a +# model which takes the censoring of y properly into account. Here, +# for illustrative purposes, we simply use example_yrep_draws(): +yrep <- example_yrep_draws() +dim(yrep) +\donttest{ +ppc_km_overlay(y, yrep[1:25, ], status_y = status_y) +} +} +\references{ +Gelman, A., Carlin, J. B., Stern, H. S., Dunson, D. B., Vehtari, +A., and Rubin, D. B. (2013). \emph{Bayesian Data Analysis.} Chapman & Hall/CRC +Press, London, third edition. (Ch. 6) + +Kaplan, E. L. and Meier, P. (1958). Nonparametric estimation +from incomplete observations. +\emph{Journal of the American Statistical Association}. 53(282), 457--481. +doi:10.1080/01621459.1958.10501452. +} +\seealso{ +Other PPCs: +\code{\link{PPC-discrete}}, +\code{\link{PPC-distributions}}, +\code{\link{PPC-errors}}, +\code{\link{PPC-intervals}}, +\code{\link{PPC-loo}}, +\code{\link{PPC-overview}}, +\code{\link{PPC-scatterplots}}, +\code{\link{PPC-test-statistics}} +} +\concept{PPCs} diff --git a/man/PPC-discrete.Rd b/man/PPC-discrete.Rd index d3df4b62..e8e8d753 100644 --- a/man/PPC-discrete.Rd +++ b/man/PPC-discrete.Rd @@ -173,6 +173,7 @@ Visualizing count data regressions using rootograms. } \seealso{ Other PPCs: +\code{\link{PPC-censoring}}, \code{\link{PPC-distributions}}, \code{\link{PPC-errors}}, \code{\link{PPC-intervals}}, diff --git a/man/PPC-distributions.Rd b/man/PPC-distributions.Rd index 1de4154c..ab203a13 100644 --- a/man/PPC-distributions.Rd +++ b/man/PPC-distributions.Rd @@ -10,7 +10,6 @@ \alias{ppc_dens} \alias{ppc_dens_overlay} \alias{ppc_ecdf_overlay} -\alias{ppc_km_overlay} \alias{ppc_violin_grouped} \title{PPC distributions} \usage{ @@ -66,8 +65,6 @@ ppc_ecdf_overlay( alpha = 0.7 ) -ppc_km_overlay(y, yrep, ..., status_y, size = 0.25, alpha = 0.7) - ppc_violin_grouped( y, yrep, @@ -129,10 +126,6 @@ passed to \code{\link[ggplot2:stat_ecdf]{ggplot2::stat_ecdf()}}. If \code{discre \item{pad}{A logical scalar passed to \code{\link[ggplot2:stat_ecdf]{ggplot2::stat_ecdf()}}.} -\item{status_y}{The status indicator for the observations from \code{y}. This must -be a numeric vector of the same length as \code{y} with values in \{0, 1\} (0 = -right censored, 1 = event).} - \item{probs}{A numeric vector passed to \code{\link[ggplot2:geom_violin]{ggplot2::geom_violin()}}'s \code{draw_quantiles} argument to specify at which quantiles to draw horizontal lines. Set to \code{NULL} to remove the lines.} @@ -185,12 +178,6 @@ Kernel density or empirical CDF estimates of each dataset (row) in data, set the \code{discrete} argument to \code{TRUE} for better results. For an example of \code{ppc_dens_overlay()} also see Gabry et al. (2019). } -\item{\code{ppc_km_overlay()}}{ -Empirical CCDF estimates of each dataset (row) in \code{yrep} are overlaid, -with the Kaplan-Meier estimate of \code{y} itself on top (and in a darker -shade). This is a PPC suitable for right-censored \code{y}. Note that the -replicated data from \code{yrep} is assumed to be uncensored. -} \item{\code{ppc_violin_grouped()}}{ The density estimate of \code{yrep} within each level of a grouping variable is plotted as a violin with horizontal lines at notable @@ -260,6 +247,7 @@ Press, London, third edition. (Ch. 6) } \seealso{ Other PPCs: +\code{\link{PPC-censoring}}, \code{\link{PPC-discrete}}, \code{\link{PPC-errors}}, \code{\link{PPC-intervals}}, diff --git a/man/PPC-errors.Rd b/man/PPC-errors.Rd index 61aeabda..079d2fd1 100644 --- a/man/PPC-errors.Rd +++ b/man/PPC-errors.Rd @@ -174,6 +174,7 @@ Press, London, third edition. (Ch. 6) } \seealso{ Other PPCs: +\code{\link{PPC-censoring}}, \code{\link{PPC-discrete}}, \code{\link{PPC-distributions}}, \code{\link{PPC-intervals}}, diff --git a/man/PPC-intervals.Rd b/man/PPC-intervals.Rd index 9e8b6cd9..552ae7be 100644 --- a/man/PPC-intervals.Rd +++ b/man/PPC-intervals.Rd @@ -211,6 +211,7 @@ Press, London, third edition. (Ch. 6) } \seealso{ Other PPCs: +\code{\link{PPC-censoring}}, \code{\link{PPC-discrete}}, \code{\link{PPC-distributions}}, \code{\link{PPC-errors}}, diff --git a/man/PPC-loo.Rd b/man/PPC-loo.Rd index a59f9cab..75f2f131 100644 --- a/man/PPC-loo.Rd +++ b/man/PPC-loo.Rd @@ -256,6 +256,7 @@ doi:10.1007/s11222-016-9696-4. arXiv preprint: } \seealso{ Other PPCs: +\code{\link{PPC-censoring}}, \code{\link{PPC-discrete}}, \code{\link{PPC-distributions}}, \code{\link{PPC-errors}}, diff --git a/man/PPC-overview.Rd b/man/PPC-overview.Rd index ce184709..290dba4a 100644 --- a/man/PPC-overview.Rd +++ b/man/PPC-overview.Rd @@ -117,6 +117,7 @@ Press, London, third edition. (Ch. 6) } \seealso{ Other PPCs: +\code{\link{PPC-censoring}}, \code{\link{PPC-discrete}}, \code{\link{PPC-distributions}}, \code{\link{PPC-errors}}, diff --git a/man/PPC-scatterplots.Rd b/man/PPC-scatterplots.Rd index b591e8e6..a21e6da7 100644 --- a/man/PPC-scatterplots.Rd +++ b/man/PPC-scatterplots.Rd @@ -89,6 +89,7 @@ Press, London, third edition. (Ch. 6) } \seealso{ Other PPCs: +\code{\link{PPC-censoring}}, \code{\link{PPC-discrete}}, \code{\link{PPC-distributions}}, \code{\link{PPC-errors}}, diff --git a/man/PPC-test-statistics.Rd b/man/PPC-test-statistics.Rd index ab11a0bf..0f8968de 100644 --- a/man/PPC-test-statistics.Rd +++ b/man/PPC-test-statistics.Rd @@ -163,6 +163,7 @@ Press, London, third edition. (Ch. 6) } \seealso{ Other PPCs: +\code{\link{PPC-censoring}}, \code{\link{PPC-discrete}}, \code{\link{PPC-distributions}}, \code{\link{PPC-errors}}, From fdd5d470f17aade1b4550e9bbab72b83f8eb05c5 Mon Sep 17 00:00:00 2001 From: fweber144 Date: Thu, 1 Oct 2020 09:06:18 +0200 Subject: [PATCH 33/36] PPC-overview: Add a link to PPC-censoring. --- R/ppc-overview.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/ppc-overview.R b/R/ppc-overview.R index e2c61b37..b06e70e6 100644 --- a/R/ppc-overview.R +++ b/R/ppc-overview.R @@ -87,6 +87,9 @@ #' multinomial outcomes. #' * [LOO predictive checks][PPC-loo]: PPC functions for predictive checks #' based on (approximate) leave-one-out (LOO) cross-validation. +#' * [Censoring][PPC-censoring]: PPC functions comparing the empirical +#' distribution of censored data `y` to the distributions of individual +#' simulated datasets (rows) in `yrep`. #' #' @section Providing an interface for predictive checking from another package: #' From 6e06cc7ab81d451bae5e0a2c61b90fcfef94545a Mon Sep 17 00:00:00 2001 From: fweber144 Date: Thu, 1 Oct 2020 09:09:47 +0200 Subject: [PATCH 34/36] PPC-overview: Improve the label for the link to page PPC-censoring. --- R/ppc-overview.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/ppc-overview.R b/R/ppc-overview.R index b06e70e6..051ee691 100644 --- a/R/ppc-overview.R +++ b/R/ppc-overview.R @@ -87,7 +87,7 @@ #' multinomial outcomes. #' * [LOO predictive checks][PPC-loo]: PPC functions for predictive checks #' based on (approximate) leave-one-out (LOO) cross-validation. -#' * [Censoring][PPC-censoring]: PPC functions comparing the empirical +#' * [Censored data][PPC-censoring]: PPC functions comparing the empirical #' distribution of censored data `y` to the distributions of individual #' simulated datasets (rows) in `yrep`. #' From b639113420a805c010e002775f6c49b1551301fc Mon Sep 17 00:00:00 2001 From: fweber144 Date: Thu, 1 Oct 2020 09:10:26 +0200 Subject: [PATCH 35/36] Re-ran roxygen2 to update the documentation. --- man/PPC-overview.Rd | 3 +++ 1 file changed, 3 insertions(+) diff --git a/man/PPC-overview.Rd b/man/PPC-overview.Rd index 290dba4a..b982f127 100644 --- a/man/PPC-overview.Rd +++ b/man/PPC-overview.Rd @@ -89,6 +89,9 @@ count outcomes and bar plots for ordinal, categorical, and multinomial outcomes. \item \link[=PPC-loo]{LOO predictive checks}: PPC functions for predictive checks based on (approximate) leave-one-out (LOO) cross-validation. +\item \link[=PPC-censoring]{Censored data}: PPC functions comparing the empirical +distribution of censored data \code{y} to the distributions of individual +simulated datasets (rows) in \code{yrep}. } } From bbd7767532d8ec1704722d0016c12f2c05b0fd56 Mon Sep 17 00:00:00 2001 From: jgabry Date: Thu, 1 Oct 2020 13:44:39 -0600 Subject: [PATCH 36/36] Add a note requesting suggestions of additional plots for censored data I think to use two paragraphs here we need to add the `@description` tag, otherwise it treats the second paragraph as if it had the `@details` tag. --- R/ppc-censoring.R | 15 +++++++++++---- man/PPC-censoring.Rd | 13 +++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/R/ppc-censoring.R b/R/ppc-censoring.R index 31f661fa..d7c3ecae 100644 --- a/R/ppc-censoring.R +++ b/R/ppc-censoring.R @@ -1,9 +1,16 @@ #' PPC censoring #' -#' Compare the empirical distribution of censored data `y` to the distributions -#' of simulated/replicated data `yrep` from the posterior predictive -#' distribution. See the **Plot Descriptions** section, below, -#' for details. +#' @description Compare the empirical distribution of censored data `y` to the +#' distributions of simulated/replicated data `yrep` from the posterior +#' predictive distribution. See the **Plot Descriptions** section, below, for +#' details. +#' +#' Although some of the other plots can be used with censored data, +#' `ppc_km_overlay()` is currently the only plotting function designed +#' *specifically* for censored data. We encourage you to suggest or contribute +#' additional plots at [https://github.com/stan-dev/bayesplot](github.com/stan-dev/bayesplot). +#' +#' #' #' @name PPC-censoring #' @family PPCs diff --git a/man/PPC-censoring.Rd b/man/PPC-censoring.Rd index 2a2a5331..fdec5202 100644 --- a/man/PPC-censoring.Rd +++ b/man/PPC-censoring.Rd @@ -30,10 +30,15 @@ the \code{yrep} distributions.} A ggplot object that can be further customized using the \strong{ggplot2} package. } \description{ -Compare the empirical distribution of censored data \code{y} to the distributions -of simulated/replicated data \code{yrep} from the posterior predictive -distribution. See the \strong{Plot Descriptions} section, below, -for details. +Compare the empirical distribution of censored data \code{y} to the +distributions of simulated/replicated data \code{yrep} from the posterior +predictive distribution. See the \strong{Plot Descriptions} section, below, for +details. + +Although some of the other plots can be used with censored data, +\code{ppc_km_overlay()} is currently the only plotting function designed +\emph{specifically} for censored data. We encourage you to suggest or contribute +additional plots at \href{github.com/stan-dev/bayesplot}{https://github.com/stan-dev/bayesplot}. } \section{Plot Descriptions}{