05:00
Lecture 19
Cornell University
INFO 2950 - Spring 2024
March 28, 2024
ae-17
ae-17
(repo name will be suffixed with your GitHub name).---
title: "Gun deaths"
author: Your name
date: today
format: html
---
```{r}
#| label: setup
#| include: false
library(tidyverse)
library(rcis)
data("gun_deaths")
```
```{r}
#| label: youth
youth <- gun_deaths |>
filter(age <= 65)
```
# Gun deaths by age
We have data about `r nrow(gun_deaths)` individuals killed by guns. Only `r nrow(gun_deaths) - nrow(youth)` are older than 65. The distribution of the remainder is shown below:
```{r}
#| label: youth-dist
#| echo: false
ggplot(data = youth, mapping = aes(x = age)) +
geom_freqpoly(binwidth = 1)
```
# Gun deaths by race
```{r}
#| label: race-dist
youth |>
mutate(race = fct_infreq(race) |> fct_rev()) |>
ggplot(mapping = aes(y = race)) +
geom_bar() +
labs(y = "Victim race")
```
---
s```
gun-deaths.qmd
as an HTML document05:00
eval: true
include: true
echo: true
message: true
or warning: true
cache: true
```{r}
#| cache: true
scdb_clean <- scdb_case |>
mutate(one_vote = majVotes - minVotes == 1)
scdb_clean
```
# A tibble: 9,299 × 53
caseId docketId caseIssuesId dateDecision decisionType usCite sctCite ledCite
<chr> <chr> <chr> <chr> <dbl> <chr> <chr> <chr>
1 1945-… 1945-00… 1945-001-01… 12/10/1945 1 326 U… 66 S. … 90 L. …
2 1945-… 1945-00… 1945-002-01… 12/3/1945 1 326 U… 66 S. … 90 L. …
3 1945-… 1945-00… 1945-003-01… 11/13/1945 1 326 U… 66 S. … 90 L. …
4 1945-… 1945-00… 1945-004-01… 11/13/1945 1 326 U… 66 S. … 90 L. …
5 1945-… 1945-00… 1945-005-01… 11/5/1945 1 326 U… 66 S. … 90 L. …
6 1945-… 1945-00… 1945-006-01… 11/5/1945 1 326 U… 66 S. … 90 L. …
7 1945-… 1945-00… 1945-007-01… 11/5/1945 2 326 U… 66 S. … 90 L. …
8 1945-… 1945-00… 1945-008-01… 11/5/1945 1 326 U… 66 S. … 90 L. …
9 1945-… 1945-00… 1945-009-01… 11/5/1945 1 326 U… 66 S. … 90 L. …
10 1945-… 1945-01… 1945-010-01… 12/10/1945 1 326 U… 66 S. … 90 L. …
# ℹ 9,289 more rows
# ℹ 45 more variables: lexisCite <chr>, term <dbl>, naturalCourt <dbl>,
# chief <chr>, docket <chr>, caseName <chr>, dateArgument <chr>,
# dateRearg <chr>, petitioner <dbl>, petitionerState <dbl>, respondent <dbl>,
# respondentState <dbl>, jurisdiction <dbl>, adminAction <dbl>,
# adminActionState <dbl>, threeJudgeFdc <dbl>, caseOrigin <dbl>,
# caseOriginState <dbl>, caseSource <dbl>, caseSourceState <dbl>, …
```{r}
#| cache: true
scdb_clean <- scdb_case |>
mutate(one_vote = majVotes - minVotes == 1)
scdb_clean
```
# A tibble: 9,299 × 53
caseId docketId caseIssuesId dateDecision decisionType usCite sctCite ledCite
<chr> <chr> <chr> <chr> <dbl> <chr> <chr> <chr>
1 1945-… 1945-00… 1945-001-01… 12/10/1945 1 326 U… 66 S. … 90 L. …
2 1945-… 1945-00… 1945-002-01… 12/3/1945 1 326 U… 66 S. … 90 L. …
3 1945-… 1945-00… 1945-003-01… 11/13/1945 1 326 U… 66 S. … 90 L. …
4 1945-… 1945-00… 1945-004-01… 11/13/1945 1 326 U… 66 S. … 90 L. …
5 1945-… 1945-00… 1945-005-01… 11/5/1945 1 326 U… 66 S. … 90 L. …
6 1945-… 1945-00… 1945-006-01… 11/5/1945 1 326 U… 66 S. … 90 L. …
7 1945-… 1945-00… 1945-007-01… 11/5/1945 2 326 U… 66 S. … 90 L. …
8 1945-… 1945-00… 1945-008-01… 11/5/1945 1 326 U… 66 S. … 90 L. …
9 1945-… 1945-00… 1945-009-01… 11/5/1945 1 326 U… 66 S. … 90 L. …
10 1945-… 1945-01… 1945-010-01… 12/10/1945 1 326 U… 66 S. … 90 L. …
# ℹ 9,289 more rows
# ℹ 45 more variables: lexisCite <chr>, term <dbl>, naturalCourt <dbl>,
# chief <chr>, docket <chr>, caseName <chr>, dateArgument <chr>,
# dateRearg <chr>, petitioner <dbl>, petitionerState <dbl>, respondent <dbl>,
# respondentState <dbl>, jurisdiction <dbl>, adminAction <dbl>,
# adminActionState <dbl>, threeJudgeFdc <dbl>, caseOrigin <dbl>,
# caseOriginState <dbl>, caseSource <dbl>, caseSourceState <dbl>, …
```{r}
#| label: processed-data-cache
#| cache: true
#| dependson: raw-data-cache
scdb_clean <- scdb_case |>
mutate(one_vote = majVotes - minVotes == 1)
scdb_clean
```
# A tibble: 29,021 × 53
caseId docketId caseIssuesId dateDecision decisionType usCite sctCite ledCite
<chr> <chr> <chr> <chr> <dbl> <chr> <chr> <chr>
1 1791-… 1791-00… 1791-001-01… 8/3/1791 6 2 U.S… <NA> 1 L. E…
2 1791-… 1791-00… 1791-002-01… 8/3/1791 2 2 U.S… <NA> 1 L. E…
3 1792-… 1792-00… 1792-001-01… 2/14/1792 2 2 U.S… <NA> 1 L. E…
4 1792-… 1792-00… 1792-002-01… 8/7/1792 2 2 U.S… <NA> 1 L. E…
5 1792-… 1792-00… 1792-003-01… 8/11/1792 8 2 U.S… <NA> 1 L. E…
6 1792-… 1792-00… 1792-004-01… 8/11/1792 6 2 U.S… <NA> 1 L. E…
7 1793-… 1793-00… 1793-001-01… 2/19/1793 8 2 U.S… <NA> 1 L. E…
8 1793-… 1793-00… 1793-002-01… 2/20/1793 2 2 U.S… <NA> 1 L. E…
9 1793-… 1793-00… 1793-003-01… 2/20/1793 8 2 U.S… <NA> 1 L. E…
10 1794-… 1794-00… 1794-001-01… 2/7/1794 NA 3 U.S… <NA> 1 L. E…
# ℹ 29,011 more rows
# ℹ 45 more variables: lexisCite <chr>, term <dbl>, naturalCourt <dbl>,
# chief <chr>, docket <chr>, caseName <chr>, dateArgument <chr>,
# dateRearg <chr>, petitioner <dbl>, petitionerState <dbl>, respondent <dbl>,
# respondentState <dbl>, jurisdiction <dbl>, adminAction <dbl>,
# adminActionState <dbl>, threeJudgeFdc <dbl>, caseOrigin <dbl>,
# caseOriginState <dbl>, caseSource <dbl>, caseSourceState <dbl>, …
We have data about `r nrow(gun_deaths)` individuals killed by guns.
Only `r nrow(gun_deaths) - nrow(youth)` are older than 65. The distribution of the remainder is shown below:
We have data about 100798 individuals killed by guns.
Only 15687 are older than 65.
echo: false
for each code chunk07:00
quarto
renders your .qmd
file07:00
Quarto supports multiple presentation formats
revealjs
(HTML)pptx
(PowerPoint)beamer
(\(\LaTeX\)/PDF)# gun-deaths.R
# 2022-04-18
# Examine the distribution of age of victims in gun_deaths
# load packages
library(tidyverse)
library(rcis)
# filter data for under 65
youth <- gun_deaths |>
filter(age <= 65)
# number of individuals under 65 killed
nrow(gun_deaths) - nrow(youth)
# graph the distribution of youth
ggplot(data = youth, mapping = aes(x = age)) +
geom_freqpoly(binwidth = 1)
# graph the distribution of youth, by race
youth |>
mutate(race = fct_infreq(race) |> fct_rev()) |>
ggplot(mapping = aes(y = race)) +
geom_bar() +
labs(y = "Victim race")
source()