Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


ECON 216 Problem Set 1

2022

 

Introduction

This problem set guides you through making some plots using a dataset on violent crime in US cities between 1975 and 2015 created by the Marshall Project. The source of the data is the FBI Uniform Crime Report.

 

Grading

The problem set has three parts worth a total of 68 points. It counts for 6.6% of the final grade in the class. You will be graded based on the PDF output you create from your RMarkdown file.

 

Due Date

The problem set must be completed and uploaded to Canvas by February 13 at 11:59 p.m. ET.

 

Instructions

 

General

Create a new RMarkdown document in named abc123_ps1.Rmd, where abc123 is your CWRU ID. You will submit the PDF knitted version of this document, which will be called abc123_mp1.pdf, in Canvas. Remember that the knit button  has a menu accessible via the downward triangle that

 

Delete all the material in the markdown document after the first code chunk.

Note:  If you have trouble creating a PDF, try installing the package called tinytex.  You do not need to load this package. It contains information RStudio uses to make the PDF.

 

Labeling your document

There are three numbered parts to this exercise, each with several lettered subparts.

In your RMarkdown document, please label each subpart with a heading beginning with two hash signs.

E.g. ## Part 1A. Your heading should begin the row it is on.

Note that code chunks and their output must be displayed in your knitted abc123_mp1.pdf file to get full credit! They will be by default.


Getting ready

Create a new project called PS1 in your ECON 216 folder using the File>New Project. . .  menu. Create your           abc123_PS1.Rmd document within the PS1 folder and place the data file ViolentCrimeUSCities1975_2015.RData there as well.

 

Part 1 (22 points)

A. In your document, write a code chunk that loads the tidyverse and then the data file.  (2 points)

B. Write a code chunk that uses the glimpse and View functions to examine the data. What is the unit of observation of this dataset?  (4 points)

C. Write a code chunk that creates a pipeline (see our February 1st class) which creates a dataset called homicides. The pipeline should use two dplyr verbs to modify homicides so that it 1) contains only the observations for which the variable crime_type is equal to “Homicides” and 2) does not contain the variable crime_type. Glimpse homicides What is its unit of observation?  (10 points)

D. Write a code chunk that creates a pipeline that modifies data. Create a new variable within data called num_per_capita that is the number of crimes per person.  Glimpse data. What is the unit of observation of data now?  (6 points)

 

Part 2 (24 points)

Using a pipeline write a code chunk that creates a dataset called summary_7515 from data and then applies the following steps A through E.

A. Groups the data by city.  (4 points)

B. Summarizes the data, creating the variable num7515_per_capita equal to the sum of number divided by the sum of population.  (6 points)

C. Arranges the observations in descending order of num7515_per_capita.  (6 points)

D.  Adds  the  following  line  of  code:    mutate(agency_jurisdiction=factor(agency_jurisdiction, levels=agency_jurisdiction))  %>%

E. Finally, uses rename() to rename agency_jurisdiction to city.  (4 points)

Now answer the question.

F. What is the unit of observation of summary_7515? What does num7515_per_capita measure?  (4 points)

 

Part 3 (22 points)

Write a code chunk that does the following to show a plot:

A. Invokes the ggplot function using the dataset summary_7515 and assigning num7515_per_capita to the x aesthetic and city to the y aesthetic.  (8 points)

B. Add a function to create a column graph.  (4 points)

C. Add a function to label the plot, including the axes and a title that describes what the plot shows. Use a caption to credit the creator and source of the data mentioned in the introduction.  (10 points)