Reference no: EM132389475
Assignment
This assignment is about how the U.S. president is elected by the electoral college -- 538 electors corresponding to 435 members of congress, 100 senators, and 3 additional electors allocated to Washington D.C.. The number of electoral votes allocated to each state is equal to the size of its congressional delegation. And most states cast all their electoral votes for the candidate receiving a plurality of the state's votes in the general election (the *winner-takes-all* rule).
Nebraska and Maine are the only two exceptions. These states allocate two electoral votes to the candidate receiving a plurality of the state's votes, and each of their remaining electoral votes go to the candidate receiving a plurality of votes within each of the states' congressional districts. But these are small and relatively homogeneous states. Maine has never actually split its electoral votes and Nebraska did it only once, casting a vote for Obama in 2008.
A candidate must receive a simple majority of electoral college votes (270 votes) to be elected. But, as in 2000, it is possible for a candidate to win the election without receiving a plurality of the popular vote. Analyze state-level polls downloaded from the Huffington Post's Pollster and 3 additional polls for Washington D.C. available to predict the outcomes of the 2016 presidential election. Predict the distribution of electoral college votes according to the *winner-takes-all* rule and using only the 3 most recent polls in each state and examine how this distribution changed over time, starting at 90 days before the election.
The dataset (`polls2016.csv`) has 905 observations, each representing a different poll, and includes the following 7 variables:
-----------------------------------------------------------------------------
Name Description
--------------- ---------------------------------------------------------
`id` Poll ID
`state` U.S. state where poll was fielded
`Clinton` The poll's estimated level of support for Hillary Clinton(in percentage points)
`Trump` The poll's estimated level of support for Donald Trump (in percentage points)
`days_to_election` Number of days before November 4, 2016.
`electoral_votes` Number of electoral votes allocated to the state where the poll was fielded (a state-level variable)
`population` The poll's target population, which may be `Adults`, `Registered Voters`, or `Likely Voters`
--------------------------------------------------------------------------------
Question 1
Begin by restricting poll data to the 3 most recent polls in each state and computing the average support for each candidate by state. Create a scatterplot showing support for Clinton vs. support for Trump. Use state abbreviations to plot the results. Briefly interpret the results.
To do this sort the polls by the `days_to_election` variable within each state. Use the `sort()` function to sort the polls from the latest to the oldest. When the `index.return` argument is set to `TRUE`, this function will return the ordering index vector, which can be used to extract the 3 most recent polls for each state. Calculate the predicted margin between the candidates, because the question asks to plot the average support for each.
Question 2
Based on the average support calculated for Clinton and Trump, predict the winner of each state and allocate the corresponding electoral college votes to the predicted winner. While two states, Maine and Nebraska, do not apply the *winner-takes-all* rule to allocate their electoral votes, for the sake of simplicity, apply this rule uniformly across these states as well. If the support for the two candidates in a given state is identical, split the state's electoral votes. Who would be predicted to win the election based on these polls? How many electoral college votes would be predicted for each candidate to receive? Use a loop and conditional statements (`if ... else if ... else`).
Attachment:- Polls Data 2016.rar