arviz_plots.plot_ppc_censored

arviz_plots.plot_ppc_censored#

arviz_plots.plot_ppc_censored(dt, var_names=None, filter_vars=None, group='posterior_predictive', coords=None, sample_dims=None, num_samples=100, truncation_factor=1.2, plot_collection=None, backend=None, labeller=None, aes_by_visuals=None, visuals=None, **pc_kwargs)[source]#

Plot Kaplan-Meier survival curve [1] vs predictive draws.

Instead of plotting the raw data observation and predictions, as is common in posterior predictive checks, this function computes the Kaplan-Meier survival curves for observed and for predictive data computes the truncated survival probabilities. The truncation is done as a factor of the maximum observed data to avoid extending the survival curves too far beyond the range of observed data.

Parameters:
dtxarray.DataTree

Input data containing the predictive samples and observed data. Should contain groups specified by group and “observed_data”, optionally including a censoring status variable in “constant_data”. This censoring variable should be binary where 1 indicates an event occurred and 0 indicates censoring.

var_namesstr or list of str, optional

One or more variables to be plotted.

filter_vars{None, “like”, “regex”}, optional, default=None

If None (default), interpret var_names as the real variables names. If “like”, interpret var_names as substrings of the real variables names. If “regex”, interpret var_names as regular expressions on the real variables names.

groupstr, default “posterior_predictive”

Group to be plotted. Can be “posterior_predictive” or “prior_predictive”.

coordsdict, optional

Coordinates to subset the data.

sample_dimsstr or sequence of hashable, optional

Dimensions to reduce unless mapped to an aesthetic. Defaults to rcParams["data.sample_dims"]

num_samplesint, optional

Number of samples to plot. Defaults to 100.

truncation_factorfloat, default 1.2

Factor by which to truncate the survival curves beyond the maximum observed time. Set to None to show all posterior predictive draws.

plot_collectionPlotCollection, optional

Existing plot collection to add to.

backend{“matplotlib”, “bokeh”, “plotly”}, optional

Plotting backend to use.

labellerlabeller, optional

Labeller for plot titles and axes.

aes_by_visualsmapping of {strsequence of str}, optional

Mapping of visuals to aesthetics that should use their mapping in plot_collection when plotted. Valid keys are the same as for visuals.

visualsmapping of {strmapping or bool}, optional

Valid keys are:

**pc_kwargs

Additional arguments passed to PlotCollection.

Returns:
PlotCollection

The plot collection containing the survival curve plot.

References

[1]

Kaplan, E. L., & Meier, P. Nonparametric estimation from incomplete observations. JASA, 53(282). (1958) https://doi.org/10.1080/01621459.1958.10501452

Examples

Plot Kaplan-Meier curves for posterior predictive checking:

>>> from arviz_plots import plot_ppc_censored, style
>>> style.use("arviz-variat")
>>> from arviz_base import load_arviz_data
>>> dt = load_arviz_data('censored_cats')
>>> plot_ppc_censored(dt)
../../_images/arviz_plots-plot_ppc_censored-1.png