logo Hurry, Grab up to 30% discount on the entire course
Order Now logo

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Anthonius HermanusManagement
(5/5)

895 Answers

Hire Me
expert
Claire BattershillData mining
(4/5)

621 Answers

Hire Me
expert
DaniaStatistics
(/5)

955 Answers

Hire Me
expert
Patricia JohnsonNursing
(5/5)

893 Answers

Hire Me
R Programming
(5/5)

How many races were contested between more than two candidates? Which state had the most of these races?

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Working with elections returns from US Senate elections:

The changes we make in the data are going to be cumulative, so you should assume that changes you make to the data in one question (filtering, selecting variables etc) apply to all subsequent questions. For example, in Q6 you will remove Independent candidates from the data. All subsequent questions make use of this filtered data with no Independents.

1. First, import this data using this link ( 1976-2020-senate). Download the spreadsheet as a csv and load the election results into R.

2. Remove non-substantive columns. Keep only the variables year, state, state_po, stage, candidate, party_detailed, candidatevotes, totalvotes.

3. Remove any rows that have missing data in the “candidate” or “party” columns.

4. Next, create a new variable, “party3” which recodes the “party” column into “D” for Democrats, “R” for Republicans, and “I” for all other parties. (Use the ifelse() function to recode to “R” if the row represents a Republican and otherwise stays equal to its current value.)

5. How many Democrats are in this dataset? How many Republicans? How many Independents?

6. Now let’s look at the 2-party vote in these data. First, remove the independent candidates from the data. Next, remove all the rows where “stage” is not equal to “gen”. This ensures that we only get results from the general election.

7. How many races were contested between more than two candidates? Which state had the most of these races?

8. For Democratic and Republican candidates create a figure that displays year on the xaxis and each candidate’s percent of the vote on the y-axis. Be sure to color code each candidate by their respective party. Add two lines – one for each party – that represents the trend in that parties’ support overtime.

9. Let’s take a look at the races from 2012. Filter your dataset so that it only contains the results for 2012, and only the columns year, state, party3, and the candidate percent youcalculated in the previous question. Reshape this data so that there is only one row per state, and two columns that represent the percent of the vote won by the Republican candidate and the percent of the vote won by the Democratic candidate. Note that you will not have 50 rows because not all states have a Senate election in an election year.

10. Create a variable “demwin” that records if the Democrat received a higher vote share than the Republican in each race in 2012.

11. Create a variable “demdiff” that records the difference between the Democratic and Republican share of the vote in each race in 2012.

12. Next, we’re going to do some analysis to map this data. Load in the state-level mapping data that we’ve worked with from the package mapdata

13. Join the 2012 Senate election data to this mapping data. Be cautious about the format of the state names!

14. Create a map that shows the winner of each Senate contest in 2012, with Democrats in blue and Republicans in red. If there was no Senate contest in a state (or if a party other than Democrats or Republicans won the seat), leave the state blank.

15. Create a map that shades each state by the Democratic vote difference you created above. Again, If there was no Senate contest in a state (or if a party other than Democrats or Republicans won the seat), leave the state blank.

(5/5)
Attachments:

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. Develop a program to emulate a purchase transaction at a retail store. This  program will have two classes, a LineItem class and a Transaction class

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme