Survival of the sweetest

December 12, 2012
By

[This article was first published on Robert Grant's stats blog » R, 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.

On receiving an advent calendar from one of our course directors, I suggested we could track each other’s chocolate consumption in a survival analysis and establish who was eating significantly more chocs. Strangely, everybody refused to take part, so I am n=1. Looking forward to being able to highlight some “shocks” on the graph.

So far, so smug

So far, so smug

If you really want to know:

library(jpeg)
today<-12
chocs<-c(5,5,7,7,7,10,10,10,12)
lc<-length(chocs)
choc.days<-rep(NA,25)
for (i in 1:25) {
choc.days[i]<-sum(chocs==i)
}
choc.surv<-25-cumsum(choc.days)
holly<-readJPEG("holly.jpg")
chocplot<-function(){
plot(1:today,choc.surv[1:today],type="s",lty=1,col="chocolate4",lwd=10,
ylim=c(0,25),xlim=c(0,25),
xlab="Day in December",ylab="Surviving chocolates",
main="Survival of chocolates in Robert's 2012 office advent calendar",
bty="n")
text(x=10,y=23,labels="Survival curve",col="chocolate4")
text(x=6.7,y=17,labels="One a day...")
text(x=18,y=20,labels="Restraint",col="red",font=3)
text(x=22,y=23,labels="Scrooge",col="green",font=3)
text(x=7,y=6,labels="Abandon",col="red",font=3)
text(x=3,y=2,labels="Nausea",col="green",font=3)
lines(x=c(1,25),y=c(25,1),lty=3)
rasterImage(holly,22,0,25,3)
}
windows()
chocplot()
jpeg("Advent_calendar.jpg")
chocplot()
dev.off(dev.cur())

To leave a comment for the author, please follow the link and comment on their blog: Robert Grant's stats blog » R.

R-bloggers.com 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.



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers

Sponsors

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)