Description Usage Format Details Source Examples
Election results for the 2008 U.S. Presidential race
1  | 
A data frame with 51 observations on the following 7 variables.
stateState name abbreviation
stateFullFull state name
nObamaNumber of votes for Barack Obama
pObamaProportion of votes for Barack Obama
nMcCainNumber of votes for John McCain
pMcCainProportion of votes for John McCain
elVotesNumber of electoral votes for a state
In Nebraska, 4 electoral votes went to McCain and 1 to Obama. Otherwise the electoral votes were a winner-take-all.
Presidential Election of 2008, Electoral and Popular Vote Summary, collected on April 21, 2011 from
http://www.infoplease.com/us/government/presidential-election-vote-summary.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27  | #===> Obtain 2010 US House Election Data <===#
data(houseRace10)
hr <- table(houseRace10[,c("abbr", "party1")])
nr <- apply(hr, 1, sum)
#===> Obtain 2008 President Election Data <===#
data(prRace08)
pr   <- prRace08[prRace08$state != "DC",c("state", "pObama")]
hr   <- hr[as.character(pr$state),]
(fit <- glm(hr ~ pr$pObama, family=binomial))
#===> Visualizing Binomial outcomes <===#
x  <- pr$pObama[pr$state != "DC"]
nr <- apply(hr, 1, sum)
plot(x, hr[,"Democrat"]/nr, pch=19, cex=sqrt(nr), col="#22558844",
    xlim=c(20, 80), ylim=c(0, 1), xlab="Percent vote for Obama in 2008",
    ylab="Probability of Democrat winning House seat")
#===> Logistic Regression <===#
x1 <- pr$pObama[match(houseRace10$abbr, pr$state)]
y1 <- (houseRace10$party1 == "Democrat")+0
g  <- glm(y1 ~ x1, family=binomial)
X  <- seq(0, 100, 0.1)
lo <- -5.6079 + 0.1009*X
p  <- exp(lo)/(1+exp(lo))
lines(X, p)
abline(h=0:1, lty=2, col="#888888")
 | 
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.