Support for handling censored data in PPC plots via imputation
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 442
- Forks
- 93
- Avg merge
- 3h 11m
- Merged PRs (30d)
- 1
Description
The only plot type supporting censored data currently is ppc_km_overlay (plus _grouped), which plots overlaid Kaplan-Meier plots, which is an excellent idea. Other plots can be useful, too, and we can provide a generic approach by considering the censored data as missing data, and generate imputed y.
Here's a simple code for the imputation (which doesn't check that the sample gets a non-zero number of draws)
yrep <- posterior_predict(fit_lognormal, ndraws=4000);
yimp <- sapply(1:N, \(i) {ifelse(x$is_censored[i], sample(yrep[yrep[,i]>x$time[i],i],size=1), x$time[i])})
and then showing plots without imputation and with imputation
ppc_intervals(y=y, yrep=yrep) + scale_y_log10()
ppc_intervals(y=yimp, yrep=yrep) + scale_y_log10()
Without imputation, the plot doesn't make sense as discussed before. With imputation, the plot makes sense but also reveals there is a group of observation with similar indices (likely to be from the same sub-study).
Imputed y can be used with any plot, even with the `ppc_km_overlay´ just to illustrate that the imputation is not breaking anything (but otherwise, it's better to show km-plot without imputation)
ppc_km_overlay(y=y, yrep=yrep[seq(1,4000,length.out=20),], status_y=1-x$is_censored) + scale_x_log10()
ppc_km_overlay(y=yimp, yrep=yrep[seq(1,4000,length.out=20),], status_y=rep(1,N)) + scale_x_log10()
bayesplot functions take y and yrep as arguments, and thus the imputation would be made by the user, or by rstanarm or brms. I'm adding this issue, as we could add to bayesplot functions an argument that indicates which elements of y are imputed, and the imputed y values would be shown in a different color to help to see how much the imputation is affecting. This would work also in km and pit_ecdf plots, where the curves would have more and more imputed color when going right.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review the bayesplot functions that accept y and yrep, starting with ppc_intervals, ppc_km_overlay, and pit_ecdf. Define how an imputation indicator would be supplied and displayed across these plots, then verify that censored-data examples show imputed observations distinctly without breaking existing plots.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data-visualization
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100