]> git.vanrenterghem.biz Git - www2.vanrenterghem.biz.git/blob - source/posts/explore-AU-road-fatalities.mdwn
Gebruik source folder.
[www2.vanrenterghem.biz.git] / source / posts / explore-AU-road-fatalities.mdwn
1 [[!meta date="2017-10-10 16:56:56 +0800"]]
2 [[!tag R analysis]]
4 Road fatalities in Australia
5 ----------------------------
7 Recently inspired to doing a little analysis again, I landed on a
8 dataset from
9 <https://bitre.gov.au/statistics/safety/fatal_road_crash_database.aspx>,
10 which I downloaded on 5 Oct 2017. Having open datasets for data is a
11 great example of how governments are moving with the times!
13 Trends
14 ------
16 I started by looking at the trends - what is the approximate number of
17 road fatalities a year, and how is it evolving over time? Are there any
18 differences noticeable between states? Or by gender?
20 [[Overall trend line|/pics/explore-AU-road-fatalities_files/fatalitiesTrends-1.png]][[Trend lines by Australian state|/pics/explore-AU-road-fatalities_files/fatalitiesTrends-2.png]][[Trend lines by gender|/pics/explore-AU-road-fatalities_files/fatalitiesTrends-3.png]]
22 What age group is most at risk in city traffic?
23 -----------------------------------------------
25 Next, I wondered if there were any particular ages that were more at
26 risk in city traffic. I opted to quickly bin the data to produce a
27 histogram.
29     fatalities %>%
30       filter(Year != 2017, Speed_Limit <= 50) %>%
31       ggplot(aes(x=Age))+
32       geom_histogram(binwidth = 5) +
33       labs(title = "Australian road fatalities by age group",
34            y = "Fatalities") +
35       theme_economist()
37     ## Warning: Removed 2 rows containing non-finite values (stat_bin).
39 [[histogram|/pics/explore-AU-road-fatalities_files/fatalities.cityTraffic-1.png]]
41 Hypothesis
42 ----------
44 Based on the above, I wondered - are people above 65 more likely to die
45 in slow traffic areas? To make this a bit easier, I added two variables
46 to the dataset - one splitting people in younger and older than 65, and
47 one based on the speed limit in the area of the crash being under or
48 above 50 km per hour - city traffic or faster in Australia.
50     fatalities.pensioners <- fatalities %>%
51       filter(Speed_Limit <= 110) %>% # less than 2% has this - determine why
52       mutate(Pensioner = if_else(Age >= 65, TRUE, FALSE)) %>%
53       mutate(Slow_Traffic = ifelse(Speed_Limit <= 50, TRUE, FALSE)) %>%
54       filter(!is.na(Pensioner))
56 To answer the question, I produce a density plot and a boxplot.
58 [[density plot|/pics/explore-AU-road-fatalities_files/fatalitiesSegmentation-1.png]][[box plot|/pics/explore-AU-road-fatalities_files/fatalitiesSegmentation-2.png]]
60 Some further statistical analysis does confirm the hypothesis!
62     # Build a contingency table and perform prop test
63     cont.table <- table(select(fatalities.pensioners, Slow_Traffic, Pensioner))
64     cont.table
66     ##             Pensioner
67     ## Slow_Traffic FALSE  TRUE
68     ##        FALSE 36706  7245
69     ##        TRUE   1985   690
71     prop.test(cont.table)
73     ## 
74     ##  2-sample test for equality of proportions with continuity
75     ##  correction
76     ## 
77     ## data:  cont.table
78     ## X-squared = 154.11, df = 1, p-value < 2.2e-16
79     ## alternative hypothesis: two.sided
80     ## 95 percent confidence interval:
81     ##  0.07596463 0.11023789
82     ## sample estimates:
83     ##    prop 1    prop 2 
84     ## 0.8351573 0.7420561
86     # Alternative approach to using prop test
87     pensioners <- c(nrow(filter(fatalities.pensioners, Slow_Traffic == TRUE, Pensioner == TRUE)), nrow(filter(fatalities.pensioners, Slow_Traffic == FALSE, Pensioner == TRUE)))
88     everyone <- c(nrow(filter(fatalities.pensioners, Slow_Traffic == TRUE)), nrow(filter(fatalities.pensioners, Slow_Traffic == FALSE)))
89     prop.test(pensioners,everyone)
91     ## 
92     ##  2-sample test for equality of proportions with continuity
93     ##  correction
94     ## 
95     ## data:  pensioners out of everyone
96     ## X-squared = 154.11, df = 1, p-value < 2.2e-16
97     ## alternative hypothesis: two.sided
98     ## 95 percent confidence interval:
99     ##  0.07596463 0.11023789
100     ## sample estimates:
101     ##    prop 1    prop 2 
102     ## 0.2579439 0.1648427
104 Conclusion
105 ----------
107 It's possible to conclude older people are over-represented in the
108 fatalities in lower speed zones. Further ideas for investigation are
109 understanding the impact of the driving age limit on the fatalities -
110 the position in the car of the fatalities (driver or passenger) was not
111 yet considered in this quick look at the contents of the dataset.
113 [[quantile-quantile plot|/pics/explore-AU-road-fatalities_files/fatalitiesDistComp-1.png]]