library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.6
## ✔ forcats   1.0.1     ✔ stringr   1.6.0
## ✔ ggplot2   4.0.1     ✔ tibble    3.3.1
## ✔ lubridate 1.9.4     ✔ 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(readr)
Animalcare <- read_csv("Desktop/Applied Quantitative Methods/Animal_Care_and_Control_Division_Annual_Statistics-1.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.
library(ggplot2)
names(Animalcare)
##  [1] "Year"                                     
##  [2] "Number of Employees"                      
##  [3] "Number of Division Vehicles"              
##  [4] "Annual Budget"                            
##  [5] "Owner Surrenders"                         
##  [6] "Strays"                                   
##  [7] "Impounds by ACO (Added in 2015)"          
##  [8] "Total Intake of Animals"                  
##  [9] "Adoptions"                                
## [10] "Return to Owner"                          
## [11] "Euthanized"                               
## [12] "Transported to other shelters and rescues"
## [13] "Fostered Animals"                         
## [14] "Service Calls"                            
## [15] "Emergency Call-Outs"                      
## [16] "Grants Received"                          
## [17] "Annual Adoption Revenue"
ggplot(Animalcare, aes(x = `Annual Budget`, y = Adoptions)) +
  geom_point()

library(janitor)
## 
## Attaching package: 'janitor'
## The following objects are masked from 'package:stats':
## 
##     chisq.test, fisher.test
Animalcare <- clean_names(Animalcare)
names(Animalcare)
##  [1] "year"                                     
##  [2] "number_of_employees"                      
##  [3] "number_of_division_vehicles"              
##  [4] "annual_budget"                            
##  [5] "owner_surrenders"                         
##  [6] "strays"                                   
##  [7] "impounds_by_aco_added_in_2015"            
##  [8] "total_intake_of_animals"                  
##  [9] "adoptions"                                
## [10] "return_to_owner"                          
## [11] "euthanized"                               
## [12] "transported_to_other_shelters_and_rescues"
## [13] "fostered_animals"                         
## [14] "service_calls"                            
## [15] "emergency_call_outs"                      
## [16] "grants_received"                          
## [17] "annual_adoption_revenue"
model <- lm(annual_budget ~ number_of_employees + total_intake_of_animals + 
              adoptions + annual_adoption_revenue,
            data = Animalcare)

summary(model)
## 
## Call:
## lm(formula = annual_budget ~ number_of_employees + total_intake_of_animals + 
##     adoptions + annual_adoption_revenue, data = Animalcare)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -146586  -71386    7507   35198  233012 
## 
## Coefficients:
##                           Estimate Std. Error t value Pr(>|t|)    
## (Intercept)             -2.397e+06  7.254e+05  -3.304  0.00419 ** 
## number_of_employees      2.070e+05  2.589e+04   7.998 3.66e-07 ***
## total_intake_of_animals -1.259e+02  5.277e+01  -2.385  0.02897 *  
## adoptions                4.290e+02  1.170e+02   3.668  0.00191 ** 
## annual_adoption_revenue -3.207e+00  1.238e+00  -2.592  0.01900 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 103700 on 17 degrees of freedom
## Multiple R-squared:  0.9488, Adjusted R-squared:  0.9368 
## F-statistic: 78.78 on 4 and 17 DF,  p-value: 9.662e-11
library(gridExtra)
## 
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
## 
##     combine
library(ggplot2)
library(gridExtra)

p1 <- ggplot(Animalcare, aes(x = number_of_employees, y = annual_budget)) +
  geom_point() +
  geom_smooth(method = "lm", color = "blue") +
  labs(title = "Employees vs Annual Budget")

p2 <- ggplot(Animalcare, aes(x = total_intake_of_animals, y = annual_budget)) +
  geom_point() +
  geom_smooth(method = "lm", color = "blue") +
  labs(title = "Total Intake vs Annual Budget")

p3 <- ggplot(Animalcare, aes(x = adoptions, y = annual_budget)) +
  geom_point() +
  geom_smooth(method = "lm", color = "blue") +
  labs(title = "Adoptions vs Annual Budget")

p4 <- ggplot(Animalcare, aes(x = annual_adoption_revenue, y = annual_budget)) +
  geom_point() +
  geom_smooth(method = "lm", color = "blue") +
  labs(title = "Annual Revenue vs Annual Budget")

grid.arrange(p1, p2, p3, p4, ncol = 2)
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'