How long do I have to survive without cake?

[This article was first published on Mango Solutions » R Blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Clara Schartner

As part of my summer internship at Mango I got to help out creating training materials. Learning new methods by preparing them in a teachable way is definitely my new favourite way of learning!

But once I started preparing training material for Survival Analysis I faced an issue: whilst Survival Analysis is used for many different things these days it still carries a name immediately associated with its original purpose: Analysing deaths in medical settings. This association is probably not ideal for sparking an interest for this method. Many textbook examples nowadays include time-to-repair of machines or equipment. This is an improvement but it’s still not the most positive of examples. So, why not use the time-to-event everyone is looking forward to? Like time-to-cake!

At Mango we occasionally bring in cake, sweets or treats for different reasons: birthdays, mangoversaries or holidays. My favourite reason so far has been “because it’s friday”. The barplot below shows everything brought in over the past two months. There is a clear trend for bringing in treats on a Friday.

Reasons for bringing cake

A more fun example of survival analysis is to consider the time in between someone bringing cake to work.
This example differs from normal survival analysis however: normally time to event (death, repair etc.) per unit of observation (person, equipment) is calculated. There are no real units of observation but a new unit of observation “arises” every time someone brings in cake and the time-to-event is simply the time between cakes being brought in (which can be as small as 20 minutes!).

But first, let’s look at some simple descriptive statistics:
As can be clearly seen from the barplot there were clearly less sweets being brought in during August and early September due to people being on holiday. This will affect the outcome and raise the estimated time-to-cake.


What also has an influence is the time of the day when people bring in sweets:

When do people bring in sweets?

People tend to bring in cake in the early morning or the afternoon. This means that if cake is being brought in early in the morning the time to next cake is likely to be shorter than when cake is brought in at 11am.

The Kaplan Meier Curve shows that is very unlikely that we have to endure a whole week without sweets at Mango! Even having to wait more than 8 hours has a probability below 50%.

How long do I have to survive without cake?

This model could very much be improved by factoring in time of day, weekday, month or data from past years. But being able to predict when the next treat is coming along might take some of the fun out of it…


To leave a comment for the author, please follow the link and comment on their blog: Mango Solutions » R Blog. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)