library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## âś” dplyr 1.2.1 âś” readr 2.2.0
## âś” forcats 1.0.1 âś” stringr 1.6.0
## âś” ggplot2 4.0.3 âś” tibble 3.3.1
## âś” lubridate 1.9.5 âś” tidyr 1.3.2
## âś” purrr 1.2.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## âś– dplyr::filter() masks stats::filter()
## âś– dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(pastecs)
##
## Attaching package: 'pastecs'
##
## The following objects are masked from 'package:dplyr':
##
## first, last
##
## The following object is masked from 'package:tidyr':
##
## extract
I am using my Texas Department of Family and Protective Services dataset to examine the relationship between fiscal year and the number of victims.
dfps_data <- read.csv("dfps_data.csv", check.names = FALSE)
head(dfps_data)
## Fiscal Year Program County Region Confirmed Victims # of Victims
## 1 2025 DCI Hutchinson 1-Lubbock Not Confirmed 1
## 2 2025 DCI Lubbock 1-Lubbock Not Confirmed 36
## 3 2025 DCI Lubbock 1-Lubbock Confirmed Victim 4
## 4 2025 DCI Ochiltree 1-Lubbock Not Confirmed 1
## 5 2025 DCI Potter 1-Lubbock Not Confirmed 13
## 6 2025 DCI Potter 1-Lubbock Confirmed Victim 1
str(dfps_data)
## 'data.frame': 3121 obs. of 6 variables:
## $ Fiscal Year : int 2025 2025 2025 2025 2025 2025 2025 2025 2025 2025 ...
## $ Program : chr "DCI" "DCI" "DCI" "DCI" ...
## $ County : chr "Hutchinson" "Lubbock" "Lubbock" "Ochiltree" ...
## $ Region : chr "1-Lubbock" "1-Lubbock" "1-Lubbock" "1-Lubbock" ...
## $ Confirmed Victims: chr "Not Confirmed" "Not Confirmed" "Confirmed Victim" "Not Confirmed" ...
## $ # of Victims : chr "1" "36" "4" "1" ...
The number of victims variable must be numeric for correlation analysis.
dfps_data$`# of Victims` <- as.numeric(dfps_data$`# of Victims`)
## Warning: NAs introduced by coercion
correlation_data <- dfps_data %>%
select(`Fiscal Year`, `# of Victims`)
correlation_data <- na.omit(correlation_data)
head(correlation_data)
## Fiscal Year # of Victims
## 1 2025 1
## 2 2025 36
## 3 2025 4
## 4 2025 1
## 5 2025 13
## 6 2025 1
cor(correlation_data)
## Fiscal Year # of Victims
## Fiscal Year 1.0000000 0.0437523
## # of Victims 0.0437523 1.0000000
The correlation coefficient shows the direction and strength of the relationship between fiscal year and victim counts.
pairs(correlation_data)
The pairs plot provides a visual examination of the relationship between fiscal year and victim counts.
The number of victims was strongly right-skewed in Homework 4, so I selected Spearman’s correlation.
cor.test(correlation_data$`Fiscal Year`,
correlation_data$`# of Victims`,
method = "spearman",
exact = FALSE)
##
## Spearman's rank correlation rho
##
## data: correlation_data$`Fiscal Year` and correlation_data$`# of Victims`
## S = 4856082213, p-value = 0.03912
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.03695855
The correlation coefficient describes the relationship between fiscal year and victim counts. The p-value indicates whether the association is statistically significant. Correlation does not establish causation.