Overview (from R-Bloggers)
Nate Silver's departure to relaunch FiveThirtyEight.com left a bit of a hole at the New York Times, which The Upshot — the new data journalism practice at the Times — seeks to fill. And they've gotten off to a great start with the newSenate forecasting model, called Leo. Leo was created by Amanda Cox(longtime graphics editor at the NYT) and Josh Katz (creator of the Dialect Quiz), and uses a similar poll-aggregation methodology to that used by Silver. The model itself is implemented in the R language, and the R code is available for inspection at GitHub.
What is shown here
This is basically my newbie journey in accessing the New York Times' GIT-based code. Added a couple of lines to visualize the data. Also pulled various links into one place below.
Links for Context
- NY Times uses R For Election Forecasts: http://www.r-bloggers.com/nyt-uses-r-to-forecast-senate-elections/
- LEO the NYT MOdel (FAQ:) http://www.nytimes.com/2014/04/23/upshot/meet-leo-our-senate-model.html?hpw&rref=&_r=0
- NYT Article post data: http://www.nytimes.com/newsgraphics/2014/senate-model/index.html
- Instructions - https://github.com/TheUpshot/leo-senate-model/blob/master/README.md
Get Source Code & Data:
This model, created by Amanda Cox and Josh Katz, combines polls with other information to predict how many Senate races Democrats and Republicans will win this year --
Please make sure the following R packages have been installed:
Change directory to the top-level working directory of this Git repository.
Prediction output can then be found in the
Basic Code (after you pull down GIT Zip):
setwd("C:/Users/Home/Documents/DTL Data Viz Community/leo-senate-model2/")
workingDir <- getwd()
dataDir <- paste(workingDir, "data-publisher/", sep = "/")
modelDir <- paste(workingDir, "model", sep = "/")
fundyDir <- paste(workingDir, "fundamentals", sep = "/")
### run the model (make sure install all the packages above)
n.days <- 30 # number of days to sim. set to "all" to run all days.
just.today <- T # if T, overrides n.days
n.sims <- 50000
if (just.today) source("combine-data.R")
## OK, let's fire this into a quick viz
setwd("C:/Users/Home/Documents/DTL Data Viz Community/leo-senate-model2/data-publisher/public/_big_assets/")
hist <- read.delim("histogram.tsv", header = TRUE, sep = "\t")
barplot(hist$chance, names.arg=hist$dem, border=NA, main="April 27 Prediction - US Senate result", las=2)
About this blog
Description is...<br/>Data Analytics & Visualization Blog - Generating insights from Data since 2013
Created: July 25, 2014Englishfrançais