<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/how-long-do-i-have-to-survive-without-cake/"></div></div><div><a data-url="https://www.r-bloggers.com/how-long-do-i-have-to-survive-without-cake/" data-counturl="https://www.r-bloggers.com/how-long-do-i-have-to-survive-without-cake/" data-count="horizontal" data-text="How long do I have to survive without cake?" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.mango-solutions.com/wp/2016/10/how-long-do-i-have-to-survive-without-cake/"> Mango Solutions » R Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<address>Clara Schartner</address>
<p>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!</p>
<p>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!</p>
<p>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.</p>
<p><img alt="Reasons for bringing cake" class="wp-image-6356" src="https://i1.wp.com/www.mango-solutions.com/wp/wp-content/uploads/2016/10/cake1.png?resize=456%2C365" data-recalc-dims="1"></p>
<p>A more fun example of survival analysis is to consider the time in between someone bringing cake to work.<br>
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!).</p>
<p>But first, let’s look at some simple descriptive statistics:<br>
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.</p>
<p><img alt="cake2" class="wp-image-6357" src="https://i0.wp.com/www.mango-solutions.com/wp/wp-content/uploads/2016/10/cake2.png?resize=456%2C365" data-recalc-dims="1"></p>
<p>What also has an influence is the time of the day when people bring in sweets:</p>
<p><img alt="When do people bring in sweets?" class="wp-image-6358" src="https://i1.wp.com/www.mango-solutions.com/wp/wp-content/uploads/2016/10/cake3.png?resize=456%2C365" data-recalc-dims="1"></p>
<p>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.</p>
<p>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%.</p>
<p><img alt="How long do I have to survive without cake?" class="wp-image-6359" src="https://i0.wp.com/www.mango-solutions.com/wp/wp-content/uploads/2016/10/cake4.png?resize=456%2C365" data-recalc-dims="1"></p>
<p>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…</p>
<p> </p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="https://www.r-bloggers.com/how-long-do-i-have-to-survive-without-cake/"></div></div><div><a data-url="https://www.r-bloggers.com/how-long-do-i-have-to-survive-without-cake/" data-counturl="https://www.r-bloggers.com/how-long-do-i-have-to-survive-without-cake/" data-count="vertical" data-text="How long do I have to survive without cake?" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.mango-solutions.com/wp/2016/10/how-long-do-i-have-to-survive-without-cake/"> Mango Solutions » R Blog</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/5kAgxeG0tmY"></a></div>