Skip to content

Instantly share code, notes, and snippets.

@ssugiyama
Created April 28, 2015 01:43
Show Gist options
  • Save ssugiyama/15ed512ce1e8714664db to your computer and use it in GitHub Desktop.
Save ssugiyama/15ed512ce1e8714664db to your computer and use it in GitHub Desktop.
vote <- read.csv("~/Downloads/oota2015.csv")
plot(vote) #散布図
vote.newdata = seq(1800, 7200, 100)
vote.lm <- lm(X2011 ~ X2015, data = vote)
#95%予測。片側なので0.9
vote.pred <- as.data.frame(predict(vote.lm, data.frame(X2015 = vote.newdata), interval = "prediction", level = 0.9))
lines(cbind(vote.newdata, vote.pred$fit), type="l")
lines(cbind(vote.newdata, vote.pred$lwr), type="l", col="blue", lty=2)
#80%予測。片側なので0.6
vote.pred80 <- as.data.frame(predict(vote.lm, data.frame(X2015 = vote.newdata), interval = "prediction", level = 0.6))
lines(cbind(vote.newdata, vote.pred80$lwr), type="l", col="green", lty=2)
lines(c(2605, 2605), c(0, 10000), type="l", col="red")
lines(c(0, 10000), c(2941, 2941), type="l", col="red")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment