Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

: Election Returns- r language needs to be used For the first question, were going to be working with 2012 and 2016 election returns. This

: Election Returns- r language needs to be used

For the first question, were going to be working with 2012 and 2016 election returns. This question focuses on data importing, data cleaning, and mapping.

  1. Comprehensive election returns have been compiled by Dave Leip, and are available on Canvas or via the Penn library at this link. In part because this data was designed for Excel, theres a bit of data cleaning we need to do before we get to work with the actual numbers.
    1. Each years Presidential election results data is included in a separate Excel file. Download the appropriate 2012 and 2016 spreadsheets, and import the county-level returns (sheet 3) into R for both 2012 and 2016. Read in the data, and then to make our lives easier, use the clean_names command from the janitor package to cleanup the name of each column.
    2. Lets do some data cleaning. We only want a subset of everything Leip includes: we want to know the state and county name, the percentage won by Obama (Clinton), Romney (Trump), and other candidates (just the Other columns, you dont have to pull in every other candidate individually), the total vote count, and the FIPS code. Use the tools youve learned to reduce both years data down to just those variables.
    3. Next, were going to remove all rows that dont contain any data (he inserts these so that theyre easier to read in Excel). Use the Total Vote column to assess if a row has data or not, and remove the ones that are missing values.
    4. Next, rename the columns to something substantive so that their labels make sense. That is, call them things like county rather than x1.
    5. Merge the 2012 and 2016 data together so that you have one set of electoral data with one line of data for each county.
    6. Now that we have our election returns clean, lets merge it with our mapping data. Import the county-level mapping dataset that we worked with in previous modules from the package mapdata. Next, join this dataset with the county-level FIPS codes in R and then join it to our electoral data.
    7. Now create two maps that show the percentage of the vote that Hillary Clinton and Barack Obama won in 2016 and 2012, respectively, using a chloropleth map with a color scale of red->purple->blue, similar to Homework 6.
    8. Create a new column showing the change in Democratic vote percentage from 2012 to 2016 (just the 2016 Democratic vote percentage minus the 2012 Democratic vote percentage) and map this change. Make areas with a decreased Democratic vote share red and those with an increased democratic vote share blue.
    9. Next, were going to attempt to explain this change. To do this, download and import the education dataset from Canvas. Join this with the presidential returns.
    10. Finally, plot the relationship between the Democratic shift 2012-2016 and the percentage of people in a county who have attained a bachelors degree (pct.bach in the education data). Put the Democratic shift on the y axis. Explain what is happening in this plot.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Spatial And Temporal Databases 8th International Symposium Sstd 2003 Santorini Island Greece July 2003 Proceedings Lncs 2750

Authors: Thanasis Hadzilacos ,Yannis Manolopoulos ,John F. Roddick ,Yannis Theodoridis

2003rd Edition

3540405356, 978-3540405351

More Books

Students also viewed these Databases questions

Question

Enhance the basic quality of your voice.

Answered: 1 week ago

Question

Describe the features of and process used by a writing team.

Answered: 1 week ago