Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / Final Project - Fall 2020 Due Friday December 18 by 11 pm You can do this assignment in R

Final Project - Fall 2020 Due Friday December 18 by 11 pm You can do this assignment in R

Computer Science

Final Project - Fall 2020

Due Friday December 18 by 11 pm

You can do this assignment in R. However, I did mine in R and can provide much more support if you do yours in R as well. The required function should have the exact names and order of arguments as shown in the examples. Making nice looking plots is important. Test your functions thoroughly to make sure that they work properly for all valid input. Your functions should behave gracefully if there is incorrect input (e.g. give an informative error message if input is invalid).

 

Submit a single .R file. I will run your functions in R studio.

 

There is a Final Project folder on eLC. In this folder, there is a file called USElection2020-NYT-Results- master.zip. This is a zip file containing election returns for the 2020 election. Within the data folder there are a series of folders with names consisting of dates and times. Within each folder is a spreadsheet that contains the county-level vote totals as of the time that the spreadsheet was produced. For example, “2020-11-10 00-08-35” contains vote totals updated at 8:35 AM on November

  1. The columns of the data that we are interested in are

 

FIPS: A unique geographic identifier for each county or state. Used for identifying counties and/or states.

State: State name.

Votes: total votes counted as of the update.

absentee: total absentee (mail-in) votes counted as of the update.

results_trumpd, results_bidenj: total votes counted for Trump and Biden. results_trumpd, results_bidenj: total absentee votes counted for Trump and Biden. (Note that the total vote counts are the sum of absentee and in-person votes)

last_updated: the date and time that the vote count was last updated for that county. This will be some point before the date/time that the data file was generated.

 

NOTE: YOU CANNOT CHANGE THE DATA FILES OR THE DIRECTORY STRUCTURE. I WILL TEST YOUR PROGRAM BY RUNNING IT WITH THE DATA AS IT IS ON eLC. IT MUST WORK ON THIS DATA.

 

You should make a function of the form

plot_election_results(whichday, electoral, vote_type, region)

 

This function should produce plots showing the vote totals for the given days.

 

whichday: the day after the election for which plots should be produced. A separate plot should be made for each day and the plots arranged in a grid. For example, whichday=5 means that plots should be produced for 5 days after election day (i.e. November 8).

 

electoral: Whether electoral votes or popular votes should be plotted. If electoral=T, then electoral votes should be plotted. If electoral=F, then popular votes should be plotted. The default should be electoral=F.

 

vote_type: This has possible values of “total”, “absentee”, or “in-person”. This indicates the type of vote that should be counted. The default should be “total”. This does not have any meaning if electoral=T. That is, electoral votes do not depend on the vote type.

 

region: The region of the country to show. Can either be list of states or a region as specified in the

usmap function (see below). If this argument is not specified, then it should show the whole country.

 

Here is example output

 

plot_election_results(12,electoral=T,vote_type = "total")

 

 
 
 

 

 

 

 

 

plot_election_results(5, electoral=T, vote_type=”absentee”)

 

 

 

 

 

 

 

 

 

 

plot_election_results(7,electoral=F,vote_type = "in-person",region=.south_region)

 

 

 

 

 

 

 

 

 

 

 

 

 

Notes:

    1. There are various R packages for plotting data on maps and you can use any one that you want. I used one called usmap. I will post a lecture about using this soon.
    2. You will need to deal with dates and times. There is a chapter in R for Data Science that gives everything that you need.
    3. You will need to read in different files, depending on the value of whichdays. The function list.files is useful for this. It can locate the folders within the data folder that apply to a given date.

 

    1. There are multiple vote files for each day. You should always use the last one produced in a day. I used the tail function to get the last file for each day.
    2. The directory structure of the data changes part way through the day on November 10. Before this, there are only results for the presidential race. After this, there are results for the presidential, house, and senate races. Your code must account for this. I used an if-then structure.
    3. The color scheme in my popular vote plots (see above) is not very satisfactory. Feel free to make yours better if you see a good way.
    4. You get the full popular vote for a state by summing all of the counties.
    5. A candidate gets the electoral votes for a state if he wins a majority of the popular vote. This is not true for two states (Maine and Nebraska), but you can ignore this.
    6. There is a file on eLC that has the electoral votes for each state.
    7. R has a built-in data set that gives state names.
    8. The first data set is for November 7. However, you can still plot data for earlier days by using the last_updated variable. For example, if we want the second day after the election (e.g. November 5), then we use the file for November 7 but only show results for last_updated of November 5 or earlier.
    9. If the date for the plot is November 7 or after, then you can use all of the data in that day’s file.
    10. This program has many nit-picky details that you have to figure out. I would recommend starting with the big picture things before worrying about the details. For example, I would focus on getting the plotting to work for the later (after November 6) date range first because that is easier. Once you have that working, then worry about the earlier dates.
    11. There will, of course, be partial credit. Focus on getting big picture items working, then start on the details. I would recommend choosing either state or county to work on first (i.e. not both at the same time). Get one working, then the other. They share many of the same elements, but also have separate problems to solve.
    12. I will be happy to help with the nitpicky details or anything else, but you need to start early enough to be able to answer questions.
 

Option 1

Low Cost Option
Download this past answer in few clicks

200 USD

PURCHASE SOLUTION

Already member?


Option 2

Custom new solution created by our subject matter experts

GET A QUOTE