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 how fiscal year and victim confirmation status relate to 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 regression analysis.
dfps_data$`# of Victims` <- as.numeric(dfps_data$`# of Victims`)
## Warning: NAs introduced by coercion
dfps_data$`Confirmed Victims` <- as.factor(dfps_data$`Confirmed Victims`)
regression_data <- dfps_data %>%
select(`# of Victims`, `Fiscal Year`, `Confirmed Victims`)
regression_data <- na.omit(regression_data)
victim_model <- lm(`# of Victims` ~ `Fiscal Year` + `Confirmed Victims`,
data = regression_data)
summary(victim_model)
##
## Call:
## lm(formula = `# of Victims` ~ `Fiscal Year` + `Confirmed Victims`,
## data = regression_data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -28.93 -22.13 -7.62 -0.34 895.21
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1670.3258 648.8012 -2.574 0.01008 *
## `Fiscal Year` 0.8295 0.3211 2.583 0.00984 **
## `Confirmed Victims`Not Confirmed 20.6207 1.9741 10.446 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 51.4 on 3113 degrees of freedom
## Multiple R-squared: 0.03571, Adjusted R-squared: 0.03509
## F-statistic: 57.65 on 2 and 3113 DF, p-value: < 2.2e-16
The R-squared value shows how much variation in victim counts is explained by the model. The coefficient p-values show which predictors are statistically significant.
In my model output, fiscal year and confirmed victim status were statistically significant predictors at the 0.05 level. The model’s R-squared was approximately 0.0357, meaning it explained about 3.57% of the variation in victim counts.
The fiscal year estimate was approximately 0.8295, indicating a small positive association with victim counts when confirmation status is held constant. The estimate for “Not Confirmed” was approximately 20.6207 higher than the reference category, “Confirmed Victim,” when fiscal year is held constant.
plot(victim_model, which = 1)
The residuals-versus-fitted plot helps assess whether the linearity assumption is reasonable. A random scatter around zero supports linearity, while a curved pattern suggests that the assumption may be violated.