Skip to content

Instantly share code, notes, and snippets.

@CerebralMastication
Created March 17, 2012 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CerebralMastication/2061284 to your computer and use it in GitHub Desktop.
Save CerebralMastication/2061284 to your computer and use it in GitHub Desktop.
preschool problem
one two three four answer
8 8 0 9 6
7 1 1 1 0
2 1 7 2 0
6 6 6 6 4
1 1 1 1 0
3 2 1 3 0
7 6 6 2 2
9 3 1 3 1
0 0 0 0 4
2 2 2 2 0
3 3 3 3 0
5 5 5 5 0
8 1 9 3 3
8 0 9 6 5
7 7 7 7 0
9 9 9 9 4
7 7 5 6 1
6 8 5 5 3
9 8 8 1 5
5 5 3 1 0
## read in the training data
## more lines than it should be because of the https requirement in Github
temporaryFile <- tempfile()
download.file("https://raw.github.com/gist/2061284/44a4dc9b304249e7ab3add86bc245b6be64d2cdd/problem.csv",destfile=temporaryFile, method="curl")
series <- read.csv(temporaryFile)
## munge the data to create a frequency table
freqTable <- as.data.frame( t(apply(series[,1:4], 1, function(X) table(c(X, 0:9))-1)) )
names(freqTable) <- c("zero","one","two","three","four","five","six","seven","eight","nine")
freqTable$dep <- series[,5]
## now a simple OLS regression with no intercept
myModel <- lm(dep ~ 0 + zero + one + two + three + four + five + six + seven + eight + nine, data=freqTable)
round(myModel$coefficients)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment