The rate of firearm mortality varies tremendously between states. Several factors have been proposed to explain this public health disparity, from regulations in the given state, socioeconomic conditions like poverty, or cultural factors surrounding gun ownership. Your task in this data story is to make visualizations that investigate these potential explanations, and try to answer the question: “To what extent to gun-laws versus other factors explain the differences in firearm mortality between states?”
For this assignment I have provided several datasets, each of which you can chose to use as it suits your needs.
The first is a firearm mortality dataset from the CDC, which reports total firearm mortality for each state per 100,000 persons: CDC Firearm Mortality in 2022 The second is a dataset describing the presence or absence of 157 different types of firearm laws in each set. The data was compiled by the Institute for Social Research at the University of Michigan, who tracked the data from 1991 to 2019. I am just uploading a dataset with the information in 2019: Firearm Laws in 2019. If you want to read a description of the variables, you can find it in this codebook The third is a dataset breaking down the fraction of gun deaths from homicide, suicide, or other, also from the CDC: Firearm Death Breakdown The fourth is a survey based estimate of household firearm ownership rates per state, estimated from a variety of polling sources: Gun Ownershp By State The fifth looks at burglary rates per state, from the FBI UCR database: State Burglary Rates per 100k For this assignment you will need to:
Create a combination of maps and other visualizations, using the techniques discussed during weeks 5 and 6 as well as prior modules, to tell a story about the causes of disparities in firearm mortality. Notes:
I recommend submitting your visualizations as a quarto presentation or report, using either python or R to create the visualizations and submitting your qmd file to guarantee reproducibility.
If you use color in your visuals you must use an accessible color palette.
The chunk bellow systematically processes and analyzes firearm-related data by cleaning and merging multiple datasets, it begins by loading relevant libraries and the datasets like firearm mortality rates, laws, gun ownership, burglary statistics, and state shapefiles, and standardizing column names to ensure consistency.
Each dataset is cleaned by renaming columns, selecting only necessary variables, and removing irrelevant ones, then the cleaned datasets are then merged into a single unified dataset (merged_data) using state names as the key, integrating geographic information from the state shapefile.
This section produces visualizations to explore trends and relationships in the data. A choropleth map highlights firearm mortality rates geographically, with darker colors indicating higher rates. Additionally, scatter plots reveal potential correlations between firearm mortality rates and variables like gun ownership and burglary rates. These visualizations, complemented by regression trends, provide insights into the factors contributing to firearm-related deaths across states. The use of a clean aesthetic (theme_minimal) ensures readability and clarity in the outputs.
# Load necessary libraries
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.4.2
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.4.2
library(sf)
## Warning: package 'sf' was built under R version 4.4.2
## Linking to GEOS 3.12.2, GDAL 3.9.3, PROJ 9.4.1; sf_use_s2() is TRUE
library(readr)
## Warning: package 'readr' was built under R version 4.4.2
library(viridis)
## Loading required package: viridisLite
# Load the datasets
firearm_mortality <- read_csv('C:/Users/Dell/Downloads/firearm_mortality2022.csv')
## Rows: 501 Columns: 5
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): STATE, URL
## dbl (2): YEAR, RATE
## num (1): DEATHS
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
firearm_laws <- read_csv('C:/Users/Dell/Downloads/firearm_laws.csv')
## Rows: 50 Columns: 137
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): STATE
## dbl (136): YEAR, FELONY, INVCOMMITMENT, INVOUTPATIENT, DANGER, DRUGMISDEMEAN...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
mortality_breakdown <- read_csv('C:/Users/Dell/Downloads/mortality_breakdown.csv')
## Rows: 51 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): State
## dbl (2): suicide_rate, homicide_rate
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
gun_ownership <- read_csv('C:/Users/Dell/Downloads/gun-ownership-by-state.csv')
## Rows: 51 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): state
## dbl (2): GunOwnershipPercentage, GunOwnershipLicensesIn2022
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
burglary <- read_csv('C:/Users/Dell/Downloads/burglary.csv')
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
## dat <- vroom(...)
## problems(dat)
## Rows: 51 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): State
## dbl (2): Rank, Burglary_100k
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# Load state shapefile
states <- st_read('C:/Users/Dell/Downloads/tl_2024_us_state.shp')
## Reading layer `tl_2024_us_state' from data source
## `C:\Users\Dell\Downloads\tl_2024_us_state.shp' using driver `ESRI Shapefile'
## Simple feature collection with 56 features and 15 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -179.2311 ymin: -14.60181 xmax: 179.8597 ymax: 71.43979
## Geodetic CRS: NAD83
# Inspect column names in the states shapefile
print(names(states))
## [1] "REGION" "DIVISION" "STATEFP" "STATENS" "GEOID" "GEOIDFQ"
## [7] "STUSPS" "NAME" "LSAD" "MTFCC" "FUNCSTAT" "ALAND"
## [13] "AWATER" "INTPTLAT" "INTPTLON" "geometry"
# Clean firearm_mortality dataset
firearm_mortality <- firearm_mortality %>%
rename(State = STATE) %>% # Rename STATE to State for consistency
select(State, RATE) %>% # Keep only relevant columns
rename(Mortality_Rate = RATE) # Rename RATE to Mortality_Rate for clarity
# Clean firearm_laws dataset
firearm_laws <- firearm_laws %>%
rename(State = STATE) %>% # Rename STATE to State for consistency
select(-YEAR) # Drop YEAR column if not needed
# Clean mortality_breakdown dataset
mortality_breakdown <- mortality_breakdown %>%
rename(State = State) # Ensure State column name is consistent
# Clean gun_ownership dataset
gun_ownership <- gun_ownership %>%
rename(State = state, GunOwnershipPercentage = GunOwnershipPercentage) # Ensure consistent column names
# Clean burglary dataset
burglary <- burglary %>%
rename(State = State, Burglary_100k = Burglary_100k) %>% # Ensure consistent column names
select(State, Burglary_100k) # Keep only relevant columns
# Clean states shapefile
# Check the correct column name for state names
# For example, if the column is named "NAME", rename it to "State"
states <- states %>%
rename(State = NAME) # Replace NAME with the correct column name
# Merge datasets
merged_data <- states %>%
left_join(firearm_mortality, by = "State") %>%
left_join(mortality_breakdown, by = "State") %>%
left_join(gun_ownership, by = "State") %>%
left_join(burglary, by = "State")
# Check the merged data
head(merged_data)
## Simple feature collection with 6 features and 21 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -97.23909 ymin: 24.39631 xmax: -71.08857 ymax: 49.38448
## Geodetic CRS: NAD83
## REGION DIVISION STATEFP STATENS GEOID GEOIDFQ STUSPS State LSAD
## 1 3 5 54 01779805 54 0400000US54 WV West Virginia 00
## 2 3 5 12 00294478 12 0400000US12 FL Florida 00
## 3 2 3 17 01779784 17 0400000US17 IL Illinois 00
## 4 2 4 27 00662849 27 0400000US27 MN Minnesota 00
## 5 3 5 24 01714934 24 0400000US24 MD Maryland 00
## 6 1 1 44 01219835 44 0400000US44 RI Rhode Island 00
## MTFCC FUNCSTAT ALAND AWATER INTPTLAT INTPTLON
## 1 G4000 A 62266513826 488918898 +38.6472854 -080.6183274
## 2 G4000 A 138965379385 45968913048 +28.3989775 -082.5143005
## 3 G4000 A 143778206717 6216848695 +40.1028754 -089.1526108
## 4 G4000 A 206244791203 18937236061 +46.3159573 -094.1996043
## 5 G4000 A 25151223822 6979843236 +38.9466584 -076.6744939
## 6 G4000 A 2677768885 1323681453 +41.5964850 -071.5264901
## Mortality_Rate suicide_rate homicide_rate GunOwnershipPercentage
## 1 NA NA NA 58.5
## 2 NA NA NA 35.3
## 3 NA NA NA 27.8
## 4 NA NA NA 42.8
## 5 NA NA NA 30.2
## 6 NA NA NA 14.8
## GunOwnershipLicensesIn2022 Burglary_100k geometry
## 1 50963 200.6 MULTIPOLYGON (((-77.75438 3...
## 2 518725 180.6 MULTIPOLYGON (((-83.10874 2...
## 3 144749 210.3 MULTIPOLYGON (((-87.89243 3...
## 4 129825 215.4 MULTIPOLYGON (((-95.31991 4...
## 5 136257 199.8 MULTIPOLYGON (((-75.756 39....
## 6 4887 128.5 MULTIPOLYGON (((-71.67881 4...
# Choropleth map for firearm mortality rates
ggplot(data = merged_data) +
geom_sf(aes(fill = Mortality_Rate), color = "white", size = 0.2) +
scale_fill_viridis_c(option = "plasma", name = "Mortality Rate per 100,000") +
labs(title = "Firearm Mortality Rates by State (2022)",
subtitle = "Higher rates are shown in darker colors") +
theme_minimal() +
theme(legend.position = "bottom")
# Scatter plot: Gun ownership vs firearm mortality rates
ggplot(data = merged_data, aes(x = GunOwnershipPercentage, y = Mortality_Rate)) +
geom_point(color = 'blue', alpha = 0.7, size = 3) +
geom_smooth(method = 'lm', color = 'red', se = FALSE) +
labs(title = 'Gun Ownership vs Firearm Mortality Rates',
x = 'Gun Ownership Percentage',
y = 'Firearm Mortality Rate per 100,000',
caption = "Source: CDC and survey data") +
theme_minimal() +
theme(plot.title = element_text(size = 14, face = "bold"))
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 56 rows containing non-finite outside the scale range
## (`stat_smooth()`).
## Warning: Removed 56 rows containing missing values or values outside the scale range
## (`geom_point()`).
# Scatter plot: Burglary rates vs firearm mortality rates
ggplot(data = merged_data, aes(x = Burglary_100k, y = Mortality_Rate)) +
geom_point(color = 'green', alpha = 0.7, size = 3) +
geom_smooth(method = 'lm', color = 'red', se = FALSE) +
labs(title = 'Burglary Rates vs Firearm Mortality Rates',
x = 'Burglary Rate per 100,000',
y = 'Firearm Mortality Rate per 100,000',
caption = "Source: FBI UCR and CDC data") +
theme_minimal() +
theme(plot.title = element_text(size = 14, face = "bold"))
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 55 rows containing non-finite outside the scale range
## (`stat_smooth()`).
## Warning: Removed 55 rows containing missing values or values outside the scale range
## (`geom_point()`).
#More data cleaning
This code cleans and integrates multiple datasets—firearm mortality rates, gun ownership percentages, burglary rates, and geographic state boundaries. It begins by standardizing column names for consistency and selecting relevant variables, such as Mortality_Rate, GunOwnershipPercentage, and Burglary_100k. The datasets are then merged step-by-step using state names as the key identifier, aligning the geographic shapefile with the cleaned data. After merging, the code removes rows with missing values in critical columns to ensure data integrity. Finally, the cleaned dataset is prepared for further analysis, and initial summaries and previews are printed to verify the results.
# Load necessary libraries
library(dplyr)
library(ggplot2)
library(sf)
library(readr)
library(viridis)
library(patchwork) # For arranging plots
library(tidyr)
## Warning: package 'tidyr' was built under R version 4.4.2
# Load the datasets
firearm_mortality <- read_csv('C:/Users/Dell/Downloads/firearm_mortality2022.csv')
## Rows: 501 Columns: 5
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): STATE, URL
## dbl (2): YEAR, RATE
## num (1): DEATHS
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
gun_ownership <- read_csv('C:/Users/Dell/Downloads/gun-ownership-by-state.csv')
## Rows: 51 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): state
## dbl (2): GunOwnershipPercentage, GunOwnershipLicensesIn2022
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
burglary <- read_csv('C:/Users/Dell/Downloads/burglary.csv')
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
## dat <- vroom(...)
## problems(dat)
## Rows: 51 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): State
## dbl (2): Rank, Burglary_100k
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# Load state shapefile
states <- st_read('C:/Users/Dell/Downloads/tl_2024_us_state.shp')
## Reading layer `tl_2024_us_state' from data source
## `C:\Users\Dell\Downloads\tl_2024_us_state.shp' using driver `ESRI Shapefile'
## Simple feature collection with 56 features and 15 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -179.2311 ymin: -14.60181 xmax: 179.8597 ymax: 71.43979
## Geodetic CRS: NAD83
# Clean firearm_mortality dataset
firearm_mortality <- firearm_mortality %>%
rename(State = STATE) %>% # Rename STATE to State for consistency
select(State, RATE) %>% # Keep only relevant columns
rename(Mortality_Rate = RATE) # Rename RATE to Mortality_Rate for clarity
# Clean gun_ownership dataset
gun_ownership <- gun_ownership %>%
rename(State = state, GunOwnershipPercentage = GunOwnershipPercentage) # Ensure consistent column names
# Clean burglary dataset
burglary <- burglary %>%
rename(State = State, Burglary_100k = Burglary_100k) %>% # Ensure consistent column names
select(State, Burglary_100k) # Keep only relevant columns
# Clean states shapefile
# Check the correct column name for state names
# For example, if the column is named "NAME", rename it to "State"
states <- states %>%
rename(State = NAME) # Replace NAME with the correct column name
# Merge datasets step-by-step
merged_data <- states %>%
left_join(firearm_mortality, by = "State") %>%
left_join(gun_ownership, by = "State") %>%
left_join(burglary, by = "State")
# Check for missing data
print(summary(merged_data))
## REGION DIVISION STATEFP STATENS
## Length:56 Length:56 Length:56 Length:56
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## GEOID GEOIDFQ STUSPS State
## Length:56 Length:56 Length:56 Length:56
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## LSAD MTFCC FUNCSTAT ALAND
## Length:56 Length:56 Length:56 Min. :1.583e+08
## Class :character Class :character Class :character 1st Qu.:2.483e+10
## Mode :character Mode :character Mode :character Median :1.286e+11
## Mean :1.636e+11
## 3rd Qu.:2.008e+11
## Max. :1.480e+12
##
## AWATER INTPTLAT INTPTLON Mortality_Rate
## Min. :1.871e+07 Length:56 Length:56 Min. :21.4
## 1st Qu.:1.508e+09 Class :character Class :character 1st Qu.:21.4
## Median :3.700e+09 Mode :character Mode :character Median :21.4
## Mean :1.269e+10 Mean :21.4
## 3rd Qu.:8.966e+09 3rd Qu.:21.4
## Max. :2.447e+11 Max. :21.4
## NA's :55
## GunOwnershipPercentage GunOwnershipLicensesIn2022 Burglary_100k
## Min. :14.70 Min. : 4887 Min. : 75.5
## 1st Qu.:40.33 1st Qu.: 67258 1st Qu.:180.6
## Median :46.00 Median : 109835 Median :219.7
## Mean :44.10 Mean : 147281 Mean :252.3
## 3rd Qu.:52.73 3rd Qu.: 151799 3rd Qu.:323.6
## Max. :66.30 Max. :1006555 Max. :499.3
## NA's :6 NA's :5 NA's :7
## geometry
## MULTIPOLYGON :56
## epsg:4269 : 0
## +proj=long...: 0
##
##
##
##
# Remove rows with missing values in key columns
merged_data_clean <- merged_data %>%
drop_na(Mortality_Rate, GunOwnershipPercentage, Burglary_100k)
# Check the cleaned data
print(head(merged_data_clean))
## Simple feature collection with 0 features and 19 fields
## Bounding box: xmin: NA ymin: NA xmax: NA ymax: NA
## Geodetic CRS: NAD83
## [1] REGION DIVISION
## [3] STATEFP STATENS
## [5] GEOID GEOIDFQ
## [7] STUSPS State
## [9] LSAD MTFCC
## [11] FUNCSTAT ALAND
## [13] AWATER INTPTLAT
## [15] INTPTLON Mortality_Rate
## [17] GunOwnershipPercentage GunOwnershipLicensesIn2022
## [19] Burglary_100k geometry
## <0 rows> (or 0-length row.names)
The following steps represent the data cleaning, merging, and visualization to analyze firearm mortality rates and gun ownership percentages. It begins by removing duplicate rows in merged_data_clean, filling missing values in the GunOwnershipPercentage column with its median, and saving the cleaned dataset as a CSV file. After reloading this dataset, it filters out rows with missing values in key columns like GunOwnershipPercentage and Mortality_Rate. Using ggplot2, the code creates two visualizations: a scatter plot to explore the relationship between firearm mortality and gun ownership by state, and a bar chart that ranks states by firearm mortality rates. It then merges the dataset with a state shapefile to add geographic information, enabling the creation of two maps: one visualizing firearm mortality rates by state and another showing gun ownership percentages by state. The viridis color palette is applied for enhanced clarity, and theme_minimal() is used for a clean aesthetic. These steps help prepare, clean, and analyze data while offering visual insights into geographic and numerical trends.
# Load necessary libraries
library(ggplot2)
library(dplyr)
# Standardize and clean the data as previously discussed
# Merge datasets using common keys (State names or abbreviations)
merged_data <- merge(firearm_mortality, mortality_breakdown, by = "State", all = TRUE)
merged_data <- merge(merged_data, gun_ownership, by = "State", all = TRUE)
merged_data_clean <- merge(merged_data, burglary, by = "State", all = TRUE)
# Example visualization: Scatter plot of firearm mortality rate vs. gun ownership percentage
ggplot(merged_data_clean, aes(x = GunOwnershipPercentage, y = Mortality_Rate)) +
geom_point() +
geom_smooth(method = "lm") +
labs(title = "Firearm Mortality Rate vs. Gun Ownership Percentage",
x = "Gun Ownership Percentage",
y = "Firearm Mortality Rate")
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 554 rows containing non-finite outside the scale range
## (`stat_smooth()`).
## Warning: Removed 554 rows containing missing values or values outside the scale range
## (`geom_point()`).
# Example visualization: Bar chart of firearm mortality rate by state
ggplot(merged_data_clean, aes(x = reorder(State, -Mortality_Rate), y = Mortality_Rate)) +
geom_bar(stat = "identity") +
coord_flip() +
labs(title = "Firearm Mortality Rate by State",
x = "State",
y = "Firearm Mortality Rate")
## Warning: Removed 53 rows containing missing values or values outside the scale range
## (`geom_bar()`).
# Load necessary libraries
library(ggplot2)
library(dplyr)
# Ensure that the dataset is merged correctly
# Assume merged_data_clean is the merged dataset from previous steps
# Remove duplicate rows
merged_data_clean <- merged_data_clean %>% distinct()
# Fill missing values in GunOwnershipPercentage column with the median value
merged_data_clean$GunOwnershipPercentage[is.na(merged_data_clean$GunOwnershipPercentage)] <- median(merged_data_clean$GunOwnershipPercentage, na.rm = TRUE)
# Save the cleaned and merged dataset to a CSV file
write.csv(merged_data_clean, file = "merged_data_clean.csv", row.names = FALSE)
# Print a message indicating that the file has been saved
print("The merged dataset has been saved as 'merged_data_clean.csv'.")
## [1] "The merged dataset has been saved as 'merged_data_clean.csv'."
# Load necessary libraries
library(ggplot2)
library(dplyr)
# Read the cleaned and merged dataset from the CSV file
merged_data_clean <- read.csv("merged_data_clean.csv")
# Remove rows with missing or non-finite values
merged_data_clean <- merged_data_clean %>%
filter(!is.na(GunOwnershipPercentage), !is.na(Mortality_Rate))
# Scatter plot with color palette
scatter_plot <- ggplot(merged_data_clean, aes(x = GunOwnershipPercentage, y = Mortality_Rate, color = State)) +
geom_point() +
geom_smooth(method = "lm") +
scale_color_viridis_d() + # Apply viridis color palette
labs(title = "Firearm Mortality Rate vs. Gun Ownership Percentage",
x = "Gun Ownership Percentage",
y = "Firearm Mortality Rate",
color = "State") +
theme_minimal()
print(scatter_plot)
## `geom_smooth()` using formula = 'y ~ x'
# Bar chart with color palette
bar_chart <- ggplot(merged_data_clean, aes(x = reorder(State, -Mortality_Rate), y = Mortality_Rate, fill = State)) +
geom_bar(stat = "identity") +
scale_fill_viridis_d() + # Apply viridis color palette
coord_flip() +
labs(title = "Firearm Mortality Rate by State",
x = "State",
y = "Firearm Mortality Rate",
fill = "State") +
theme_minimal()
print(bar_chart)
# Load necessary libraries
library(ggplot2)
library(dplyr)
library(sf)
# Load state shapefile
states <- st_read('C:/Users/Dell/Downloads/tl_2024_us_state.shp')
## Reading layer `tl_2024_us_state' from data source
## `C:\Users\Dell\Downloads\tl_2024_us_state.shp' using driver `ESRI Shapefile'
## Simple feature collection with 56 features and 15 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -179.2311 ymin: -14.60181 xmax: 179.8597 ymax: 71.43979
## Geodetic CRS: NAD83
# Merge the shapefile with the cleaned dataset based on state names or abbreviations
merged_data <- left_join(states, merged_data_clean, by = c("STUSPS" = "State"))
# Check the merged data
print(head(merged_data))
## Simple feature collection with 6 features and 21 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -82.64459 ymin: 37.20154 xmax: -77.71952 ymax: 40.6388
## Geodetic CRS: NAD83
## REGION DIVISION STATEFP STATENS GEOID GEOIDFQ STUSPS NAME LSAD
## 1 3 5 54 01779805 54 0400000US54 WV West Virginia 00
## 2 3 5 54 01779805 54 0400000US54 WV West Virginia 00
## 3 3 5 54 01779805 54 0400000US54 WV West Virginia 00
## 4 3 5 54 01779805 54 0400000US54 WV West Virginia 00
## 5 3 5 54 01779805 54 0400000US54 WV West Virginia 00
## 6 3 5 54 01779805 54 0400000US54 WV West Virginia 00
## MTFCC FUNCSTAT ALAND AWATER INTPTLAT INTPTLON Mortality_Rate
## 1 G4000 A 62266513826 488918898 +38.6472854 -080.6183274 18.1
## 2 G4000 A 62266513826 488918898 +38.6472854 -080.6183274 17.5
## 3 G4000 A 62266513826 488918898 +38.6472854 -080.6183274 13.8
## 4 G4000 A 62266513826 488918898 +38.6472854 -080.6183274 14.0
## 5 G4000 A 62266513826 488918898 +38.6472854 -080.6183274 18.2
## 6 G4000 A 62266513826 488918898 +38.6472854 -080.6183274 17.3
## suicide_rate homicide_rate GunOwnershipPercentage GunOwnershipLicensesIn2022
## 1 71 27 46 NA
## 2 71 27 46 NA
## 3 71 27 46 NA
## 4 71 27 46 NA
## 5 71 27 46 NA
## 6 71 27 46 NA
## Burglary_100k geometry
## 1 NA MULTIPOLYGON (((-77.75438 3...
## 2 NA MULTIPOLYGON (((-77.75438 3...
## 3 NA MULTIPOLYGON (((-77.75438 3...
## 4 NA MULTIPOLYGON (((-77.75438 3...
## 5 NA MULTIPOLYGON (((-77.75438 3...
## 6 NA MULTIPOLYGON (((-77.75438 3...
#Creating the map visualization
# Map visualization: Firearm Mortality Rate by State
mortality_map <- ggplot(merged_data) +
geom_sf(aes(fill = Mortality_Rate)) +
scale_fill_viridis_c() +
labs(title = "Firearm Mortality Rate by State",
fill = "Mortality Rate") +
theme_minimal()
print(mortality_map)
# Map visualization: Gun Ownership Percentage by State
ownership_map <- ggplot(merged_data) +
geom_sf(aes(fill = GunOwnershipPercentage)) +
scale_fill_viridis_c() +
labs(title = "Gun Ownership Percentage by State",
fill = "Gun Ownership %") +
theme_minimal()
print(ownership_map)
#
Firearm mortaly rate by state
The map effectively visualizes geographical disparities in firearm mortality rates, clearly identifying regions with varying levels of mortality. This visual representation serves as a valuable starting point for further investigation into the relationships between these mortality rates and potential contributing factors.
This plot effectively shows the distribution of gun ownership percentages across states using a consistent representation of 46%
In this chunk the cleaned dataset is merged with a state shapefile to integrate geographic boundaries using left_join(). Two visualizations are created using ggplot2: a map showing firearm mortality rates by state, using the “plasma” color palette, and a categorized map of gun ownership percentages by state, using the “viridis” palette. Both maps apply theme_minimal() for a clean aesthetic. This workflow provides a geographical perspective on the data.
# Load necessary libraries
library(ggplot2)
library(dplyr)
library(sf)
library(viridis)
# 1. Clean the Dataset
# Remove duplicate rows
merged_data_clean <- merged_data_clean %>% distinct()
# Fill missing values with placeholder (e.g., 0)
merged_data_clean <- merged_data_clean %>%
mutate(across(c(Burglary_100k, GunOwnershipLicensesIn2022),
~ ifelse(is.na(.), 0, .)))
# Categorize Gun Ownership Percentages
merged_data_clean <- merged_data_clean %>%
mutate(GunOwnershipCategory = cut(GunOwnershipPercentage,
breaks = c(0, 20, 40, 60, 80, 100),
labels = c("0-20%", "21-40%", "41-60%", "61-80%", "81-100%"),
include.lowest = TRUE))
# 2. Merge with State Shapefile
# Ensure the merging column is aligned
merged_data <- states %>%
left_join(merged_data_clean, by = c("STUSPS" = "State"))
# Check if merge was successful
print(head(merged_data))
## Simple feature collection with 6 features and 22 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -82.64459 ymin: 37.20154 xmax: -77.71952 ymax: 40.6388
## Geodetic CRS: NAD83
## REGION DIVISION STATEFP STATENS GEOID GEOIDFQ STUSPS NAME LSAD
## 1 3 5 54 01779805 54 0400000US54 WV West Virginia 00
## 2 3 5 54 01779805 54 0400000US54 WV West Virginia 00
## 3 3 5 54 01779805 54 0400000US54 WV West Virginia 00
## 4 3 5 54 01779805 54 0400000US54 WV West Virginia 00
## 5 3 5 54 01779805 54 0400000US54 WV West Virginia 00
## 6 3 5 54 01779805 54 0400000US54 WV West Virginia 00
## MTFCC FUNCSTAT ALAND AWATER INTPTLAT INTPTLON Mortality_Rate
## 1 G4000 A 62266513826 488918898 +38.6472854 -080.6183274 18.1
## 2 G4000 A 62266513826 488918898 +38.6472854 -080.6183274 17.5
## 3 G4000 A 62266513826 488918898 +38.6472854 -080.6183274 13.8
## 4 G4000 A 62266513826 488918898 +38.6472854 -080.6183274 14.0
## 5 G4000 A 62266513826 488918898 +38.6472854 -080.6183274 18.2
## 6 G4000 A 62266513826 488918898 +38.6472854 -080.6183274 17.3
## suicide_rate homicide_rate GunOwnershipPercentage GunOwnershipLicensesIn2022
## 1 71 27 46 0
## 2 71 27 46 0
## 3 71 27 46 0
## 4 71 27 46 0
## 5 71 27 46 0
## 6 71 27 46 0
## Burglary_100k GunOwnershipCategory geometry
## 1 0 41-60% MULTIPOLYGON (((-77.75438 3...
## 2 0 41-60% MULTIPOLYGON (((-77.75438 3...
## 3 0 41-60% MULTIPOLYGON (((-77.75438 3...
## 4 0 41-60% MULTIPOLYGON (((-77.75438 3...
## 5 0 41-60% MULTIPOLYGON (((-77.75438 3...
## 6 0 41-60% MULTIPOLYGON (((-77.75438 3...
# 3. Visualizations
# Firearm Mortality Rate Map
mortality_map <- ggplot(merged_data) +
geom_sf(aes(fill = Mortality_Rate), color = "black", size = 0.2) +
scale_fill_viridis_c(option = "plasma", name = "Mortality Rate (per 100k)") +
labs(title = "Firearm Mortality Rates by State",
caption = "Data Source: CDC, 2022") +
theme_minimal() +
theme(legend.position = "right")
print(mortality_map)
# Map Gun Ownership Categories
ownership_map <- ggplot(merged_data) +
geom_sf(aes(fill = GunOwnershipCategory), color = "black", size = 0.2) +
scale_fill_viridis_d(option = "viridis", name = "Gun Ownership %") +
labs(title = "Categorized Gun Ownership Percentages by State",
caption = "Data Source: Gun Ownership Survey") +
theme_minimal() +
theme(legend.position = "right")
print(ownership_map)
This section follows a structured approach to analyze firearm mortality rates by combining data, refining variables, and performing visual and statistical analysis. First, it integrates firearm laws into an existing merged dataset while filtering out rows with missing key variables like mortality rates or gun ownership. It creates new variables such as the total number of firearm laws and an interaction term between gun ownership and firearm laws. These steps allow the data to capture more nuanced relationships. The code then generates three scatterplots—examining firearm mortality against gun ownership, firearm laws, and their interaction—each using jittering and smoothing to highlight potential trends.
After a regression analysis is done to quantify the relationship between mortality rates and predictors, including the interaction term. The model results are summarized and visualized through a coefficient plot, which shows the significance and relative impact of each predictor variable. By combining regression results with visualizations, the approach provides insights into how gun ownership, laws, and other factors may explain variations in firearm mortality. This workflow is designed to answer complex research questions through iterative data exploration and refinement.
# Load necessary libraries
library(ggplot2)
library(dplyr)
library(broom)
library(GGally)
## Warning: package 'GGally' was built under R version 4.4.2
## Registered S3 method overwritten by 'GGally':
## method from
## +.gg ggplot2
# 1. Combine and Refine the Data
# Include socioeconomic factors if available (e.g., income, poverty rates)
# Ensure all relevant datasets are joined before creating new variables
combined_data <- merged_data_clean %>%
left_join(firearm_laws, by = "State") %>% # Ensure firearm laws are merged
filter(!is.na(Mortality_Rate),
!is.na(GunOwnershipPercentage),
!is.na(Burglary_100k)) %>% # Filter out rows with NA in key variables
mutate(Total_Firearm_Laws = rowSums(select(., starts_with("law_")), na.rm = TRUE),
Interaction_GunLaw_Ownership = GunOwnershipPercentage * Total_Firearm_Laws) # Add interaction term
# Check the data structure to confirm variables
print(head(combined_data))
## State Mortality_Rate suicide_rate homicide_rate GunOwnershipPercentage
## 1 AK 21.0 74 21 46
## 2 AK 23.3 74 21 46
## 3 AK 24.4 74 21 46
## 4 AK 24.5 74 21 46
## 5 AK 17.5 74 21 46
## 6 AK 19.2 74 21 46
## GunOwnershipLicensesIn2022 Burglary_100k GunOwnershipCategory FELONY
## 1 0 0 41-60% NA
## 2 0 0 41-60% NA
## 3 0 0 41-60% NA
## 4 0 0 41-60% NA
## 5 0 0 41-60% NA
## 6 0 0 41-60% NA
## INVCOMMITMENT INVOUTPATIENT DANGER DRUGMISDEMEANOR ALCTREATMENT ALCOHOLISM
## 1 NA NA NA NA NA NA
## 2 NA NA NA NA NA NA
## 3 NA NA NA NA NA NA
## 4 NA NA NA NA NA NA
## 5 NA NA NA NA NA NA
## 6 NA NA NA NA NA NA
## RELINQUISHMENT VIOLENT VIOLENTH VIOLENTPARTIAL DEALER DEALERH RECORDSALL
## 1 NA NA NA NA NA NA NA
## 2 NA NA NA NA NA NA NA
## 3 NA NA NA NA NA NA NA
## 4 NA NA NA NA NA NA NA
## 5 NA NA NA NA NA NA NA
## 6 NA NA NA NA NA NA NA
## RECORDSALLH RECORDSDEALER RECORDSDEALERH REPORTALL REPORTALLH REPORTDEALER
## 1 NA NA NA NA NA NA
## 2 NA NA NA NA NA NA
## 3 NA NA NA NA NA NA
## 4 NA NA NA NA NA NA
## 5 NA NA NA NA NA NA
## 6 NA NA NA NA NA NA
## REPORTDEALERH PURGE RESIDENTIAL THEFT SECURITY INSPECTION AMMLICENSE
## 1 NA NA NA NA NA NA NA
## 2 NA NA NA NA NA NA NA
## 3 NA NA NA NA NA NA NA
## 4 NA NA NA NA NA NA NA
## 5 NA NA NA NA NA NA NA
## 6 NA NA NA NA NA NA NA
## AMMRECORDS PERMIT PERMITH FINGERPRINT TRAINING PERMITLAW REGISTRATION
## 1 NA NA NA NA NA NA NA
## 2 NA NA NA NA NA NA NA
## 3 NA NA NA NA NA NA NA
## 4 NA NA NA NA NA NA NA
## 5 NA NA NA NA NA NA NA
## 6 NA NA NA NA NA NA NA
## REGISTRATIONH DEFACTOREG DEFACTOREGH AMMPERMIT AMMRESTRICT AGE21HANDGUNSALE
## 1 NA NA NA NA NA NA
## 2 NA NA NA NA NA NA
## 3 NA NA NA NA NA NA
## 4 NA NA NA NA NA NA
## 5 NA NA NA NA NA NA
## 6 NA NA NA NA NA NA
## AGE18LONGGUNSALE AGE21LONGGUNSALED AGE21LONGGUNSALE AGE21HANDGUNPOSSESS
## 1 NA NA NA NA
## 2 NA NA NA NA
## 3 NA NA NA NA
## 4 NA NA NA NA
## 5 NA NA NA NA
## 6 NA NA NA NA
## AGE18LONGGUNPOSSESS AGE21LONGGUNPOSSESS LOSTSTOLEN AMM18 AMM21H UNIVERSAL
## 1 NA NA NA NA NA NA
## 2 NA NA NA NA NA NA
## 3 NA NA NA NA NA NA
## 4 NA NA NA NA NA NA
## 5 NA NA NA NA NA NA
## 6 NA NA NA NA NA NA
## UNIVERSALH GUNSHOW GUNSHOWH UNIVERSALPERMIT UNIVERSALPERMITH BACKGROUNDPURGE
## 1 NA NA NA NA NA NA
## 2 NA NA NA NA NA NA
## 3 NA NA NA NA NA NA
## 4 NA NA NA NA NA NA
## 5 NA NA NA NA NA NA
## 6 NA NA NA NA NA NA
## AMMBACKGROUND THREEDAYLIMIT MENTALHEALTH STATECHECKS STATECHECKSH WAITING
## 1 NA NA NA NA NA NA
## 2 NA NA NA NA NA NA
## 3 NA NA NA NA NA NA
## 4 NA NA NA NA NA NA
## 5 NA NA NA NA NA NA
## 6 NA NA NA NA NA NA
## WAITINGH ASSAULT ONEFEATURE ASSAULTLIST ASSAULTREGISTER ASSAULTTRANSFER
## 1 NA NA NA NA NA NA
## 2 NA NA NA NA NA NA
## 3 NA NA NA NA NA NA
## 4 NA NA NA NA NA NA
## 5 NA NA NA NA NA NA
## 6 NA NA NA NA NA NA
## MAGAZINE TENROUNDLIMIT MAGAZINEPREOWNED ONEPERMONTH TRAFFICKINGBACKGROUND
## 1 NA NA NA NA NA
## 2 NA NA NA NA NA
## 3 NA NA NA NA NA
## 4 NA NA NA NA NA
## 5 NA NA NA NA NA
## 6 NA NA NA NA NA
## TRAFFICKINGPROHIBITED TRAFFICKINGPROHIBITEDH STRAWPURCHASE STRAWPURCHASEH
## 1 NA NA NA NA
## 2 NA NA NA NA
## 3 NA NA NA NA
## 4 NA NA NA NA
## 5 NA NA NA NA
## 6 NA NA NA NA
## MICROSTAMP GVRO GVROLAWENFORCEMENT COLLEGE COLLEGECONCEALED ELEMENTARY
## 1 NA NA NA NA NA NA
## 2 NA NA NA NA NA NA
## 3 NA NA NA NA NA NA
## 4 NA NA NA NA NA NA
## 5 NA NA NA NA NA NA
## 6 NA NA NA NA NA NA
## OPENCARRYH OPENCARRYL OPENCARRYPERMITH OPENCARRYPERMITL PERMITCONCEALED
## 1 NA NA NA NA NA
## 2 NA NA NA NA NA
## 3 NA NA NA NA NA
## 4 NA NA NA NA NA
## 5 NA NA NA NA NA
## 6 NA NA NA NA NA
## MAYISSUE SHOWING CCBACKGROUND CCBACKGROUNDNICS CCRENEWBACKGROUND CCREVOKE
## 1 NA NA NA NA NA NA
## 2 NA NA NA NA NA NA
## 3 NA NA NA NA NA NA
## 4 NA NA NA NA NA NA
## 5 NA NA NA NA NA NA
## 6 NA NA NA NA NA NA
## NOSYG PERSONALIZED LOCKD LOCKP LOCKED LOCKSTANDARDS CAPLIABILITY CAPACCESS
## 1 NA NA NA NA NA NA NA NA
## 2 NA NA NA NA NA NA NA NA
## 3 NA NA NA NA NA NA NA NA
## 4 NA NA NA NA NA NA NA NA
## 5 NA NA NA NA NA NA NA NA
## 6 NA NA NA NA NA NA NA NA
## CAPUSES CAPUNLOADED CAP18 CAP16 CAP14 JUNKGUN LIABILITY IMMUNITY PREEMPTION
## 1 NA NA NA NA NA NA NA NA NA
## 2 NA NA NA NA NA NA NA NA NA
## 3 NA NA NA NA NA NA NA NA NA
## 4 NA NA NA NA NA NA NA NA NA
## 5 NA NA NA NA NA NA NA NA NA
## 6 NA NA NA NA NA NA NA NA NA
## PREEMPTIONNARROW PREEMPTIONBROAD MCDV MCDVDATING MCDVSURRENDER
## 1 NA NA NA NA NA
## 2 NA NA NA NA NA
## 3 NA NA NA NA NA
## 4 NA NA NA NA NA
## 5 NA NA NA NA NA
## 6 NA NA NA NA NA
## MCDVSURRENDERNOCONDITIONS MCDVSURRENDERDATING MCDVREMOVALALLOWED
## 1 NA NA NA
## 2 NA NA NA
## 3 NA NA NA
## 4 NA NA NA
## 5 NA NA NA
## 6 NA NA NA
## MCDVREMOVALREQUIRED INCIDENTREMOVAL INCIDENTALL DVRO DVRODATING EXPARTE
## 1 NA NA NA NA NA NA
## 2 NA NA NA NA NA NA
## 3 NA NA NA NA NA NA
## 4 NA NA NA NA NA NA
## 5 NA NA NA NA NA NA
## 6 NA NA NA NA NA NA
## EXPARTEDATING DVROSURRENDER DVROSURRENDERNOCONDITIONS DVROSURRENDERDATING
## 1 NA NA NA NA
## 2 NA NA NA NA
## 3 NA NA NA NA
## 4 NA NA NA NA
## 5 NA NA NA NA
## 6 NA NA NA NA
## EXPARTESURRENDER EXPARTESURRENDERNOCONDITIONS EXPARTESURRENDERDATING
## 1 NA NA NA
## 2 NA NA NA
## 3 NA NA NA
## 4 NA NA NA
## 5 NA NA NA
## 6 NA NA NA
## DVROREMOVAL STALKING LAWTOTAL Total_Firearm_Laws Interaction_GunLaw_Ownership
## 1 NA NA NA 0 0
## 2 NA NA NA 0 0
## 3 NA NA NA 0 0
## 4 NA NA NA 0 0
## 5 NA NA NA 0 0
## 6 NA NA NA 0 0
# 2. Scatterplots with Refinements
# Scatterplot: Firearm Mortality vs Gun Ownership (with jitter for variability)
scatter_plot1 <- ggplot(combined_data, aes(x = GunOwnershipPercentage, y = Mortality_Rate)) +
geom_jitter(color = "blue", alpha = 0.6) + # Add jitter for clearer visualization
geom_smooth(method = "lm", color = "red") +
labs(title = "Firearm Mortality Rate vs. Gun Ownership Percentage",
x = "Gun Ownership Percentage",
y = "Mortality Rate (per 100k)") +
theme_minimal()
print(scatter_plot1)
## `geom_smooth()` using formula = 'y ~ x'
# Scatterplot: Firearm Mortality vs Total Firearm Laws
scatter_plot2 <- ggplot(combined_data, aes(x = Total_Firearm_Laws, y = Mortality_Rate)) +
geom_jitter(color = "green", alpha = 0.6) +
geom_smooth(method = "lm", color = "red") +
labs(title = "Firearm Mortality Rate vs. Total Firearm Laws",
x = "Total Firearm Laws",
y = "Mortality Rate (per 100k)") +
theme_minimal()
print(scatter_plot2)
## `geom_smooth()` using formula = 'y ~ x'
# Scatterplot: Firearm Mortality vs Interaction Term
scatter_plot3 <- ggplot(combined_data, aes(x = Interaction_GunLaw_Ownership, y = Mortality_Rate)) +
geom_point(color = "purple", alpha = 0.6) +
geom_smooth(method = "lm", color = "red") +
labs(title = "Firearm Mortality Rate vs. Interaction (Gun Ownership x Laws)",
x = "Interaction: Gun Ownership x Firearm Laws",
y = "Mortality Rate (per 100k)") +
theme_minimal()
print(scatter_plot3)
## `geom_smooth()` using formula = 'y ~ x'
# 3. Regression Analysis with Additional Factors and Interaction Term
# Fit the refined regression model
regression_model <- lm(Mortality_Rate ~ GunOwnershipPercentage + Total_Firearm_Laws +
Burglary_100k + Interaction_GunLaw_Ownership,
data = combined_data)
# Summarize the regression model
regression_summary <- summary(regression_model)
print(regression_summary)
##
## Call:
## lm(formula = Mortality_Rate ~ GunOwnershipPercentage + Total_Firearm_Laws +
## Burglary_100k + Interaction_GunLaw_Ownership, data = combined_data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -11.7004 -3.4504 -0.4004 3.3496 20.0996
##
## Coefficients: (3 not defined because of singularities)
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 13.80043 0.25386 54.363 <2e-16 ***
## GunOwnershipPercentage NA NA NA NA
## Total_Firearm_Laws NA NA NA NA
## Burglary_100k 0.03768 0.02731 1.379 0.168
## Interaction_GunLaw_Ownership NA NA NA NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.503 on 469 degrees of freedom
## Multiple R-squared: 0.004041, Adjusted R-squared: 0.001917
## F-statistic: 1.903 on 1 and 469 DF, p-value: 0.1684
# Tidy regression output for visualization
regression_tidy <- tidy(regression_model)
print(regression_tidy)
## # A tibble: 5 × 5
## term estimate std.error statistic p.value
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 (Intercept) 13.8 0.254 54.4 1.34e-204
## 2 GunOwnershipPercentage NA NA NA NA
## 3 Total_Firearm_Laws NA NA NA NA
## 4 Burglary_100k 0.0377 0.0273 1.38 1.68e- 1
## 5 Interaction_GunLaw_Ownership NA NA NA NA
# 4. Improved Visualization of Regression Coefficients
coef_plot <- ggplot(regression_tidy, aes(x = reorder(term, estimate), y = estimate)) +
geom_col(fill = "skyblue") +
geom_errorbar(aes(ymin = estimate - std.error, ymax = estimate + std.error), width = 0.2) +
labs(title = "Regression Coefficients with Standard Errors",
x = "Predictor Variables",
y = "Coefficient Estimate") +
coord_flip() +
theme_minimal()
print(coef_plot)
## Warning: Removed 3 rows containing missing values or values outside the scale range
## (`geom_col()`).
# Firearm mortalirt rate vs. Gun Ownership percentage
The scatterplot comparing firearm mortality rates to gun ownership percentages shows a wide range of mortality rates despite a very narrow range of gun ownership percentages. The data points are dispersed, indicating a lack of a clear linear relationship between these two variables. In essence, while gun ownership percentage varies little, firearm mortality fluctuates significantly, suggesting other factors may be more influential.
The scatter plot “Firearm Mortality Rate vs. Total Firearm Laws” shows no clear correlation between the number of firearm laws and firearm mortality rates. The data points are scattered without a discernible trend, suggesting that the total number of laws, by itself, doesn’t strongly predict mortality. Additionally, the x-axis displays a very narrow range, indicating minimal variation in the number of firearm laws across the observed data, which further limits the plot’s ability to show a meaningful relationship.
The scatter plot reveals that the interaction between gun ownership and firearm laws, intended to predict firearm mortality, shows very little variability across states, with most data points clustered near zero. This tight clustering renders the interaction term’s impact on firearm mortality difficult to assess, limiting the plot’s ability to identify meaningful trends or outliers. Consequently, the regression line is nearly horizontal, indicating that this interaction term has minimal predictive power in the model.
In short, while the concept of examining the interaction between gun ownership and laws is valuable, the current data distribution in the scatter plot fails to illustrate a clear relationship with firearm mortality.
This statistical model indicates a high baseline firearm mortality rate, as shown by the large positive intercept. However, the model suggests that the included predictors—gun ownership percentage, firearm laws, burglary rates, and their interaction—have minimal individual impact on firearm mortality. While the estimates for these predictors are precise, as indicated by their small standard errors, their coefficients are close to zero, suggesting they do not significantly influence firearm mortality rates within this particular model.
In essence, the model highlights a significant base level of firearm mortality, but fails to demonstrate a strong relationship between firearm mortality and the chosen predictor variables. This suggests that other factors not included in the model may play a more significant role in determining firearm mortality rates.
The statistical model presents critical deficiencies. Specifically, the predictors GunOwnershipPercentage, Total_Firearm_Laws, and Interaction_GunLaw_Ownership display ‘NA’ values for coefficients, standard errors, and significance due to singularities, indicating collinearity. This means these variables are linearly dependent, preventing the model from isolating their individual effects.
Furthermore, the model’s R-squared value of 0.004041 reveals that it explains only 0.4% of the variance in firearm mortality rates, demonstrating a severely low model fit. The Burglary_100k predictor, with a t-value indicating a p-value of 0.168, lacks statistical significance (p > 0.05), and its small positive coefficient suggests a negligible effect. Finally, the residual standard error of 5.503 indicates a moderate spread in unexplained variation, signaling that the model is missing key explanatory variables and failing to capture the dynamics of firearm mortality.
To fully address the complexities of firearm mortality and its disparities, the current analysis needs to incorporate several key elements. First, it lacks a comprehensive socioeconomic context, which could be achieved by including variables like poverty, education, and urban/rural classifications. Second, a breakdown of firearm mortality causes, such as homicide versus suicide, is essential for a more nuanced understanding. Third, a direct comparative analysis of states with contrasting firearm laws would highlight meaningful differences. Finally, the analysis needs to address the apparent lack of statistical significance and low data variability to ensure the findings are robust and reliable.
The regression analysis failed to identify significant predictors of firearm mortality rates. Neither gun ownership percentages nor firearm laws showed any meaningful relationship, likely due to multicollinearity or limited variability. Burglary rates, though included, had a negligible and statistically insignificant positive effect. Furthermore, the interaction between gun ownership and laws also proved ineffective.
Critically, the model exhibited an extremely low R-squared value of
0.004, indicating that the chosen predictors explained only a tiny
fraction of the variation in firearm mortality. This suggests the
necessity for incorporating additional variables or employing
alternative modeling strategies to accurately capture the factors
influencing firearm mortality rates. Note that the
echo = FALSE
parameter was added to the code chunk to
prevent printing of the R code that generated the plot.