-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathKim_Vincent_Traffic_Fatality_Code.Rmd
29 lines (24 loc) · 1.34 KB
/
Kim_Vincent_Traffic_Fatality_Code.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
---
title: "Traffic Fatality Project"
author: "Vincent Kim"
output: html_notebook
---
```{r}
null = glm(INJ_SEV ~ 1, family = binomial, data=fatal)
summary(null)
full = glm(INJ_SEV ~ factor(ROUTE) + factor(MAN_COLL) + factor(LGT_COND)+factor(WEATHERlight)+factor(BODY_TYP)+AGE+factor(DRINKING)+TRAV_SP+factor(L_TYPE), family=binomial, data=fatal)
summary(full)
step(null, scope=list(lower=null, upper=full),direction="forward")
final = glm(INJ_SEV ~ factor(BODY_TYP) + AGE + factor(DRINKING) + TRAV_SP, family = binomial, data=fatal)
summary(final)
final2 = glm(INJ_SEV ~ AGE + factor(DRINKING) + TRAV_SP, family = binomial, data=fatal)
summary(final2)
anova(final2, final, test="Chisq")
round(exp(cbind(Estimate=coef(final), confint(final))),2)
boxplot(AGE ~ DRINKING, data=fatal, main="Age vs Drinking Boxplot", xlab = "Drinking?", ylab = "Age", ylim=c(0,100))
plot(fatal$TRAV_SP, fatal$AGE, groups=fatal$DRINKING, xlab = "Age", ylab = "TRAV_SP", ylim=c(0,150), col=c("red", "blue") )
plot(fatal$TRAV_SP, fatal$AGE, groups=fatal$INJ_SEV, xlab = "Age", ylab = "TRAV_SP", ylim=c(0,150), col=c("red", "blue") )
boxplot(TRAV_SP ~ DRINKING, data=fatal, main="Drinking vs Travelling Speed", xlab = "Drinking?", ylab = "Travelling speed", ylim=c(0,150))
counts = table(fatal$INJ_SEV, fatal$DRINKING)
barplot(counts, col=c("blue", "red"))
```