-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathobamaelection.r
25 lines (19 loc) · 881 Bytes
/
obamaelection.r
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
# Adapted for ISTA 116 at the University of Arizona's School of Information Science
# from a script written for this article:
# http://simplystatistics.org/post/34635539704/on-weather-forecasts-nate-silver-and-the
# This is a highly simplified simulation that does not account for the electoral college.
# Set the estimated percent for Obama
# based on the average of several national polls
proportionObama = ?
# Set the standard deviation
# this measures the variability between the different polls.
sdObama = ?
# Function to simulate a single election
simulateElection <- function(prop,sd){
return(rnorm(1,mean=prop,sd=sd))
}t
# Simulate the percent Obama in 1000 elections
simulatedProportionObama = replicate(1000, simulateElection(proportionObama,sdObama))
# Calculate the percent of times Obama wins
percentObamaWin = mean(simulatedPercentObama > 0.5)
percentObamaWin