This post will take you from a variable that shows numeric values, such as the number of days to purchase a product:
To a state where you can visualize the probability of an event at a certain time interval, such as the proportion of people who have yet to purchase at each point in time. Survival curves are also known as Kaplan-Meier curves:
You will need a numeric variable in your Data Sets tree. Numeric variables are represented by a "2" next to their name:
- From the toolbar, go to Calculation > Custom Code.
- In the object inspector, go to Properties > R CODE and paste in the following code and click Calculate.
surv.days = Surv(days)
surv.fit = survfit(surv.days~1)
plot(surv.fit, main = "Kaplan-Meier estimate with 95% confidence bounds (86% of data)",
xlab = "Days since trial started",
xlim = c(0, 180),
ylab = "Survival function")
grid(20, 10, lwd = 2)
In the code above, "surv.days = Surv(days)", days is the name of your numeric variable being used to create the density plot. This must be updated with the variable's name in your data set.