Over a million developers have joined DZone.

Visualizing (Censored) Lifetime Distributions

DZone's Guide to

Visualizing (Censored) Lifetime Distributions

Understanding all the R packages out there is hard, but this one's pretty interesting. Check out some standard censored lifetime data and see how to generate it into a nice visual.

· Big Data Zone ·
Free Resource

Hortonworks Sandbox for HDP and HDF is your chance to get started on learning, developing, testing and trying out new features. Each download comes preconfigured with interactive tutorials, sample data and developments from the Apache community.

There are now more than 10,000 R packages available from CRAN — and much more if you include those available only on GitHub. So, to be honest, it's difficult to know all of them. But sometimes, you discover a nice function in one of them, and that is really awesome. Consider for instance some (standard) censored lifetime data:


Yes, I will generate them here. Consider the Kaplan-Meier estimator of the survival function:

km.base = survfit( Surv(time,status) ~ 1  , data = df )

Recently, Anat (currently finishing the Data Science for Actuaries program) helped me discover a nice R function to add information to that graph (well, not that graph, since it will be a ggplot version, but the same survival distribution plot):

ggsurvplot(km.base, main = "", color = "blue" , censor = FALSE, xlim = c(0,3), risk.table = TRUE ,
risk.table.col = "blue" , risk.table.height = 0.2, risk.table.title = "" , legend.labs = "All" , legend.title = "" , break.time.by = 1, xlab = "" , ylab = "")

Image title

This is more interesting when we have different lifetimes:

km.prod = survfit( Surv(time,status) ~ product  , data = df )
ggsurvplot(km.prod, main = "", censor = FALSE, xlim = c(0,3), risk.table = TRUE , risk.table.col = "strata" , risk.table.height = 0.3, risk.table.title = "" , legend.labs = LETTERS[1:4] , legend.title = "" , break.time.by = 1, xlab = "" , ylab = "")

Image title

Or a different time granularity:

Nice, isn't it?

Hortonworks Community Connection (HCC) is an online collaboration destination for developers, DevOps, customers and partners to get answers to questions, collaborate on technical articles and share code examples from GitHub.  Join the discussion.

big data ,tutorial ,data visualizations ,r ,lifetime distributions

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}