R Markdown
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.2.0 ✔ readr 2.1.6
## ✔ forcats 1.0.1 ✔ stringr 1.6.0
## ✔ ggplot2 4.0.2 ✔ tibble 3.3.1
## ✔ lubridate 1.9.5 ✔ tidyr 1.3.2
## ✔ purrr 1.2.1
## ── 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
library(lmtest)
## Loading required package: zoo
##
## Attaching package: 'zoo'
##
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
library(MASS)
##
## Attaching package: 'MASS'
##
## The following object is masked from 'package:dplyr':
##
## select
library(car)
## Loading required package: carData
##
## Attaching package: 'car'
##
## The following object is masked from 'package:dplyr':
##
## recode
##
## The following object is masked from 'package:purrr':
##
## some
library(ggplot2)
Animal_Control<-read_csv("Animal_Care_and_Control_Division_Annual_Statistics.csv")
## Rows: 22 Columns: 17
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (17): Year, Number of Employees, Number of Division Vehicles, Annual Bud...
##
## ℹ 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.
Animal_Control<- Animal_Control %>% drop_na(Adoptions)
Animal_Control <- Animal_Control %>% drop_na(`Return to Owner`)
Animal_Control <- Animal_Control %>% drop_na(`Fostered Animals`)
hist(Animal_Control$Adoptions)

hist(Animal_Control$`Return to Owner`)

hist(Animal_Control$`Fostered Animals`)

hist(Animal_Control$Euthanized)

ggplot(Animal_Control,aes(x=Adoptions,y=Euthanized)) + geom_point() + labs(title="Adoptions vs Euthanized",subtitle = "From the Animal_Care_and_Control_Division_Annual_Statistics Dataset - R (2026)")

ggplot(Animal_Control,aes(x=`Return to Owner`,y=Euthanized)) + geom_point() + labs(title="Return to Owner vs Euthanized",subtitle = "From the Animal_Care_and_Control_Division_Annual_Statistics Dataset - R (2026)")

ggplot(Animal_Control,aes(x=`Fostered Animals`,y=Euthanized)) + geom_point() + labs(title="Fostered Animals vs Euthanized",subtitle = "From the Animal_Care_and_Control_Division_Annual_Statistics Dataset - R (2026)")

Adoptions_RTO_Foster <- lm(Euthanized~Adoptions+`Fostered Animals`+`Return to Owner`, data=Animal_Control)
summary(Adoptions_RTO_Foster)
##
## Call:
## lm(formula = Euthanized ~ Adoptions + `Fostered Animals` + `Return to Owner`,
## data = Animal_Control)
##
## Residuals:
## Min 1Q Median 3Q Max
## -754.1 -272.6 108.0 255.5 486.0
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3576.9917 1121.0412 3.191 0.005353 **
## Adoptions -1.9252 0.4290 -4.488 0.000324 ***
## `Fostered Animals` -0.1896 0.2593 -0.731 0.474530
## `Return to Owner` 2.9390 1.8206 1.614 0.124861
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 391.9 on 17 degrees of freedom
## Multiple R-squared: 0.6974, Adjusted R-squared: 0.644
## F-statistic: 13.06 on 3 and 17 DF, p-value: 0.0001133
Adoptions_RTO_Foster <- lm(Euthanized~Adoptions+`Fostered Animals`+`Return to Owner`, data=Animal_Control)
plot(Adoptions_RTO_Foster,which=1)

raintest(Adoptions_RTO_Foster)
##
## Rainbow test
##
## data: Adoptions_RTO_Foster
## Rain = 8.1043, df1 = 11, df2 = 6, p-value = 0.009022
Adoptions_RTO_Foster<-lm(Euthanized~Adoptions+`Fostered Animals`+`Return to Owner`, data=Animal_Control)
Adoptions_RTO_Foster_log<-lm(log(Euthanized)~log(Adoptions+`Fostered Animals`+`Return to Owner`),data=Animal_Control)
plot(Adoptions_RTO_Foster_log,which=1)

raintest(Adoptions_RTO_Foster_log)
##
## Rainbow test
##
## data: Adoptions_RTO_Foster_log
## Rain = 4.5353, df1 = 11, df2 = 8, p-value = 0.02055
durbinWatsonTest(Adoptions_RTO_Foster)
## lag Autocorrelation D-W Statistic p-value
## 1 0.1800719 1.569375 0.148
## Alternative hypothesis: rho != 0
plot(Adoptions_RTO_Foster,which = 3)

bptest(Adoptions_RTO_Foster)
##
## studentized Breusch-Pagan test
##
## data: Adoptions_RTO_Foster
## BP = 1.2035, df = 3, p-value = 0.7522
plot(Adoptions_RTO_Foster,which=2)

shapiro.test(Adoptions_RTO_Foster$residuals)
##
## Shapiro-Wilk normality test
##
## data: Adoptions_RTO_Foster$residuals
## W = 0.94478, p-value = 0.2704
plot(Adoptions_RTO_Foster_log,which=2)

Adoptions_RTO_Foster <- lm(Euthanized~Adoptions+`Fostered Animals`+`Return to Owner`, data=Animal_Control)
vif(Adoptions_RTO_Foster)
## Adoptions `Fostered Animals` `Return to Owner`
## 1.470658 1.661375 1.226752