The CWCki needs help! Please consider clicking the tugboat to make a donation
CWC PSN Spending R script
From CWCki
# we should endeavor to collect as much quantitative information about chris-chan as possible. # e.g. when did she go to McDonald's, how much did she spend, etc. # I think if we all worked together, we could build a machine learning simulator of chris chan # which would allow us to predict what she is doing at any given moment. The model might even # feel more authentic than the source of the ground truth. library(lubridate) cwc.file.data <- " date, amount 2007-04-01, 25.0 2007-05-01, 35.0 2007-06-01, 10.0 2007-07-01, 25.0 2007-08-01, 65.0 2007-09-01, 35.0 2007-10-01, 55.0 2007-11-01, 30.0 2007-12-01, 25.0 2008-01-01, 75.0 2008-02-01, 20.0 2008-03-01, 20.0 2008-04-01, 16.02 2008-05-01, 90.0 2008-06-01, 30.0 2008-07-01, 120.0 2008-08-01, 85.0 2008-09-01, 90.0 2008-10-01, 90.07 2008-11-01, 110.0 2008-12-01, 150.0 2009-01-01, 90.0 2009-02-01, 125.0 2009-03-01, 210.0 2009-04-01, 225.0 2009-05-01, 135.0 2009-06-01, 170.0 2009-07-01, 80.0 2009-08-01, 50.0 2009-09-01, 132.36 2009-10-01, 268.41 2009-11-01, 215.0 2009-12-01, 234.29 2010-01-01, 90.0 2010-02-01, 130.0 " cwc <- read.csv( text = cwc.file.data, sep=",", header = TRUE) cwc$date <- as.Date(cwc$date) cwc.ts <- as.numeric(as.POSIXct(cwc$date)) cwc.fit <- lm(cwc$amount ~ poly(cwc.ts,1)) cwc.pred <- predict(cwc.fit) years1 <- year(cwc$date) years2 <- c(0, head(years1, n = -1)) xlables <- Map(function(x, y) if(x == y) "" else x, years1, years2) png("cwc.png", width=1024, height=768) plot(cwc, type = "l", xlab="date", ylab="dollars spent per month", lwd = 4, xaxt = 'n') lines(cwc$date, cwc.pred, col="red", lwd = 4) axis(1, at = cwc$date, labels = month(cwc$date)) axis(1, at = cwc$date, labels = xlables, pos=-10, tick = FALSE) dev.off()