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.2     ✔ 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
setwd("C:/Users/jalex/OneDrive/Desktop/JS R Homework/City of San Antonio -Severe Pedestrain Injury Data")
#Data
COSA_Severe_Data <- read_csv("COSA Severe Pedestrian Injury Areas.csv")
## Rows: 166 Columns: 10
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): StreetName, FromStreet, ToStreet
## dbl (7): OBJECTID, CorridorID, Incapacitated_Injuries, Fata_Injuries, Total_...
## 
## ℹ 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.
names(COSA_Severe_Data)
##  [1] "OBJECTID"               "CorridorID"             "StreetName"            
##  [4] "FromStreet"             "ToStreet"               "Incapacitated_Injuries"
##  [7] "Fata_Injuries"          "Total_Injuries"         "SPIA_Year"             
## [10] "Shape__Length"
model <- lm(Fata_Injuries ~ Total_Injuries, data = COSA_Severe_Data)
summary(model)
## 
## Call:
## lm(formula = Fata_Injuries ~ Total_Injuries, data = COSA_Severe_Data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.2349 -0.5837  0.0512  0.4163  3.5907 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    -0.14658    0.13914  -1.053    0.294    
## Total_Injuries  0.36513    0.02891  12.631   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.043 on 164 degrees of freedom
## Multiple R-squared:  0.4931, Adjusted R-squared:   0.49 
## F-statistic: 159.5 on 1 and 164 DF,  p-value: < 2.2e-16
plot(model, which = 1)