Statistics and Statistical Programming (Fall 2020)/pset3: Difference between revisions
No edit summary |
No edit summary |
||
(9 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
<small>[[Statistics_and_Statistical_Programming_(Fall_2020)# | <small>[[Statistics_and_Statistical_Programming_(Fall_2020)#Week_5_.2810.2F13.2C_10.2F15.29|← Back to Week 5]]</small> | ||
For this problem set, the | '''Do police in the United States engage in discriminatory behavior on the basis of race and ethnicity?''' For this problem set, you will investigate the relationship between traffic stops, vehicle searches and driver attributes (especially race as recorded by police officers conducting traffic stops). Doing so will involve some more advanced data wrangling, visualization, and analysis. We'll use data from [https://openpolicing.stanford.edu The Stanford Open Policing Project] (SOPP) that looks at records of traffic stops in Illinois between 2012-2017. The full SOPP dataset for Illinois is about 12 million rows, so I've created a 1% random sample for us to work with here. Overall, the dataset is well-documented and pretty "clean," but there are still a number of features that may be confusing, weird, and/or ill-organized to help answer the questions I've asked you below. Thank goodness you know how to use R to address these issues... | ||
== Programming Challenges == | == Programming Challenges == | ||
PC1. | === PC1. Learn about the data === | ||
Review the project overview on the [https://openpolicing.stanford.edu/ SOPP homepage], the [https://openpolicing.stanford.edu/data/ overview of the data], the [https://github.com/stanford-policylab/opp/blob/master/data_readme.md#description-of-standardized-data description of the standardized data], the [https://github.com/stanford-policylab/opp/blob/master/data_readme.md#statewide-il codebook/notes for the Illinois data] from the [https://github.com/stanford-policylab/opp/blob/master/data_readme.md data_readme.md], as well as any other ancillary materials that you can find that seem likely to help you get oriented with the data. | |||
For the questions below we'll focus on the following measures recorded for each traffic stop in Illinois 2012-2017: <code>date</code>, <code>vehicle_year</code>, <code>subject_race</code>, <code>subject_sex</code>, and <code>search_conducted</code>. | |||
Record any questions or issues you might notice related to these measures as you review the information about the project and dataset. | |||
=== PC2. Import, explore, clean === | |||
As I mentioned above, the full IL SOPP dataset is over 12 million rows, so I have created a random 1% subset for us to work with in this assignment. [https://communitydata.science/~ads/teaching/2020/stats/data/week_05 That subset lives here] (and it's about 26MB). To get started, you'll want to import the data and explore its structure as well as key variables that we'll be focusing on in this analysis (<code>date</code>, <code>vehicle_year</code>, <code>subject_race</code>, <code>subject_sex</code>, and <code>search_conducted</code>). Inspect a random sample of rows to get a sense of the data. What (if anything) is missing? You may also want to clean/recode some of the key variables. Make sure to explain and justify any data cleanup and/or recoding steps you decide to take. | |||
=== PC3. Summarize outcome and predictor variables === | |||
Calculate and report appropriate summary statistics for the outcome (<code>search_conducted</code>) and each of the predictor variables we care about (<code>date</code>, <code>vehicle_year</code>, <code>subject_race</code>, and <code>subject_sex</code>). Include visual and/or tabular summaries where appropriate. Attempt, when possible, to write efficient/elegant code that avoids unnecessary repetition while also retaining clarity. | |||
=== PC4. Summarize aggregate relationships between outcome and predictor variables === | |||
The outcome variable we care about here is a dichotomous indicator for whether each traffic stop resulted in a police search (of either the driver or the vehicle) being conducted. Summarize the relationship between each of the predictor variables (<code>date</code>, <code>vehicle_year</code>, <code>subject_race</code>, and <code>subject_sex</code>) and the outcome variable (<code>search_conducted</code>). For continuous predictors, be sure to include visual summaries. For categorical predictors, focus on providing cross-tabulations that report conditional summary statistics within groups (for example, compare the numbers of searches conducted across the two categories of <code>subject_sex</code>). | |||
=== PC5. Analyze relationships between driver race/ethnicity and vehicle searches over time === | |||
Summarize the relationship between the recorded <code>subject_race</code> for each traffic stop and the <code>search_conducted</code> outcome over the time period covered by the dataset. You may do this in a variety of ways, but at minimum, you should produce the following: | |||
# A plot of the number of stops and searches across the entire sample within each month. | |||
# A plot of the number of stops within each <code>subject_race</code> category each month. | |||
# A plot of the number of searches within each <code>subject_race</code> category each month. | |||
# A plot of the proportion all searches accounted for within each <code>subject_race</code> category each month. | |||
Here's a suggestion for how you might approach this: | |||
1. Create a new data frame (or tibble) that aggregates stop and search data across sub-groups of `subject_race` per month. This object could include the following columns: | |||
* date as a month/year (should be a date or date-time object) | |||
* race/ethnicity (from the <code>subject_race</code> variable) | |||
* number of stops (within the <code>subject_race</code> group identified for the row) | |||
* number of searches (within the <code>subject_race</code> group identified for the row) | |||
* total number of searches that month/year | |||
* proportion of total searches (within the <code>subject_race</code> group identified for the row). | |||
''Note that this will result in a data frame with multiple rows per month/year (as many as one row for each <code>subject_race</code> category).'' | |||
2. Use <code>ggplot2</code> and the [https://ggplot2.tidyverse.org/reference/geom_path.html <code>geom_line</code>] layer to generate each of the plots. Note that you'll want to assign <code>subject_race</code> as an aesthetic element (<code>aes</code>) for some of the plots so that ggplot2 represents each category as a separate line (maybe distinguished by color?). Make sure to incorporate useful titles, axis labels, and legends for each plot you produce. Recall that the R tutorials include examples of using <code>aes</code> with <code>ggplot2</code>. | |||
=== PC6. Calculate baseline population proportions for relevant race/ethnicity categories === | |||
To help interpret the results of the foregoing analysis of the traffic stop data, we should calculate some baseline population proportions of the same race/ethnicity categories in the state of Illinois around the same time that the SOPP data comes from. Luckily, we have access to exactly the data we need to do this via our old friend, the <code>openintro</code> library! | |||
Use the <code>county_complete</code> dataset from the <code>openintro</code> library to calculate the proportions of the Illinois population in 2010 in each of the categories identified in the <code>subject_race</code> variable of the traffic stop dataset. You will want to use the [https://www.openintro.org/data/index.php?data=county_complete codebook] for the dataset to identify the variables you'll need. You will also need to wrangle the data a bit to produce the proportions we're looking for. Be sure to note and justify any assumptions and/or recoding decisions that you make along the way. | |||
== Statistical Questions == | |||
=== SQ1. Interpret the Illinois traffic stop analysis (PCs 3-5) === | |||
Return to the questions that motivated this analysis. Based on your results from PCs 3-5, what patterns do you observe in vehicle searches among Illinois drivers between 2012-2017? Specifically, what patterns do you note from your comparisons of stops and searches across the categories identified in the <code>subject_race</code> variable? What patterns do you observe when you compare across groups in aggregate (i.e., summed across the entire dataset)? What patterns do you observe in terms of either the numbers or proportions of stops and searches when you compare across groups over time? | |||
=== SQ2. Contextualize traffic stop data in relation to population data === | |||
Consider the results of PCs 3-5 in relation to the results of PC 6. Do the results of PC 6 impact your interpretation of PCs 3-5 in any way? How do you relate the results of the traffic stop and vehicle search analysis to the population baseline proportions? | |||
=== SQ3. Reflect on the limitations and possible extensions of your analysis === | |||
Identify and briefly explain key limitations of the data, your analysis, and the results in relation to the questions and concepts that motivated the exercise. Where possible, what additional information/data or analysis might you suggest in order to overcome these limitations and answer the questions in a more comprehensive or convincing fashion? |
Latest revision as of 16:34, 6 October 2020
Do police in the United States engage in discriminatory behavior on the basis of race and ethnicity? For this problem set, you will investigate the relationship between traffic stops, vehicle searches and driver attributes (especially race as recorded by police officers conducting traffic stops). Doing so will involve some more advanced data wrangling, visualization, and analysis. We'll use data from The Stanford Open Policing Project (SOPP) that looks at records of traffic stops in Illinois between 2012-2017. The full SOPP dataset for Illinois is about 12 million rows, so I've created a 1% random sample for us to work with here. Overall, the dataset is well-documented and pretty "clean," but there are still a number of features that may be confusing, weird, and/or ill-organized to help answer the questions I've asked you below. Thank goodness you know how to use R to address these issues...
Programming Challenges[edit]
PC1. Learn about the data[edit]
Review the project overview on the SOPP homepage, the overview of the data, the description of the standardized data, the codebook/notes for the Illinois data from the data_readme.md, as well as any other ancillary materials that you can find that seem likely to help you get oriented with the data.
For the questions below we'll focus on the following measures recorded for each traffic stop in Illinois 2012-2017: date
, vehicle_year
, subject_race
, subject_sex
, and search_conducted
.
Record any questions or issues you might notice related to these measures as you review the information about the project and dataset.
PC2. Import, explore, clean[edit]
As I mentioned above, the full IL SOPP dataset is over 12 million rows, so I have created a random 1% subset for us to work with in this assignment. That subset lives here (and it's about 26MB). To get started, you'll want to import the data and explore its structure as well as key variables that we'll be focusing on in this analysis (date
, vehicle_year
, subject_race
, subject_sex
, and search_conducted
). Inspect a random sample of rows to get a sense of the data. What (if anything) is missing? You may also want to clean/recode some of the key variables. Make sure to explain and justify any data cleanup and/or recoding steps you decide to take.
PC3. Summarize outcome and predictor variables[edit]
Calculate and report appropriate summary statistics for the outcome (search_conducted
) and each of the predictor variables we care about (date
, vehicle_year
, subject_race
, and subject_sex
). Include visual and/or tabular summaries where appropriate. Attempt, when possible, to write efficient/elegant code that avoids unnecessary repetition while also retaining clarity.
PC4. Summarize aggregate relationships between outcome and predictor variables[edit]
The outcome variable we care about here is a dichotomous indicator for whether each traffic stop resulted in a police search (of either the driver or the vehicle) being conducted. Summarize the relationship between each of the predictor variables (date
, vehicle_year
, subject_race
, and subject_sex
) and the outcome variable (search_conducted
). For continuous predictors, be sure to include visual summaries. For categorical predictors, focus on providing cross-tabulations that report conditional summary statistics within groups (for example, compare the numbers of searches conducted across the two categories of subject_sex
).
PC5. Analyze relationships between driver race/ethnicity and vehicle searches over time[edit]
Summarize the relationship between the recorded subject_race
for each traffic stop and the search_conducted
outcome over the time period covered by the dataset. You may do this in a variety of ways, but at minimum, you should produce the following:
- A plot of the number of stops and searches across the entire sample within each month.
- A plot of the number of stops within each
subject_race
category each month. - A plot of the number of searches within each
subject_race
category each month. - A plot of the proportion all searches accounted for within each
subject_race
category each month.
Here's a suggestion for how you might approach this:
1. Create a new data frame (or tibble) that aggregates stop and search data across sub-groups of `subject_race` per month. This object could include the following columns:
- date as a month/year (should be a date or date-time object)
- race/ethnicity (from the
subject_race
variable) - number of stops (within the
subject_race
group identified for the row) - number of searches (within the
subject_race
group identified for the row) - total number of searches that month/year
- proportion of total searches (within the
subject_race
group identified for the row).
Note that this will result in a data frame with multiple rows per month/year (as many as one row for each subject_race
category).
2. Use ggplot2
and the geom_line
layer to generate each of the plots. Note that you'll want to assign subject_race
as an aesthetic element (aes
) for some of the plots so that ggplot2 represents each category as a separate line (maybe distinguished by color?). Make sure to incorporate useful titles, axis labels, and legends for each plot you produce. Recall that the R tutorials include examples of using aes
with ggplot2
.
PC6. Calculate baseline population proportions for relevant race/ethnicity categories[edit]
To help interpret the results of the foregoing analysis of the traffic stop data, we should calculate some baseline population proportions of the same race/ethnicity categories in the state of Illinois around the same time that the SOPP data comes from. Luckily, we have access to exactly the data we need to do this via our old friend, the openintro
library!
Use the county_complete
dataset from the openintro
library to calculate the proportions of the Illinois population in 2010 in each of the categories identified in the subject_race
variable of the traffic stop dataset. You will want to use the codebook for the dataset to identify the variables you'll need. You will also need to wrangle the data a bit to produce the proportions we're looking for. Be sure to note and justify any assumptions and/or recoding decisions that you make along the way.
Statistical Questions[edit]
SQ1. Interpret the Illinois traffic stop analysis (PCs 3-5)[edit]
Return to the questions that motivated this analysis. Based on your results from PCs 3-5, what patterns do you observe in vehicle searches among Illinois drivers between 2012-2017? Specifically, what patterns do you note from your comparisons of stops and searches across the categories identified in the subject_race
variable? What patterns do you observe when you compare across groups in aggregate (i.e., summed across the entire dataset)? What patterns do you observe in terms of either the numbers or proportions of stops and searches when you compare across groups over time?
SQ2. Contextualize traffic stop data in relation to population data[edit]
Consider the results of PCs 3-5 in relation to the results of PC 6. Do the results of PC 6 impact your interpretation of PCs 3-5 in any way? How do you relate the results of the traffic stop and vehicle search analysis to the population baseline proportions?
SQ3. Reflect on the limitations and possible extensions of your analysis[edit]
Identify and briefly explain key limitations of the data, your analysis, and the results in relation to the questions and concepts that motivated the exercise. Where possible, what additional information/data or analysis might you suggest in order to overcome these limitations and answer the questions in a more comprehensive or convincing fashion?