# Weighting data for a valid analysis

I'm analysing road safety data. I have counts for the number of accidents that occur on different roads:

ggplot(data, aes(as.factor(Road_Type), fill=as.factor(Accident_Severity))) +
geom_bar(position="stack")


Looking at this, Road_Type=6 (corresponding to "Single carriageway") appears most dangerous, however I do not have counts for the total number of traffic or the length of the roads (i.e. Road_Type=6 may have had 1million cars travelled on it, whilst only 10 cars may have travelled on Road_Type=9). Thus, I am struggling to identify which roads are the most dangerous (because I feel those Road_Types with significantly more cars on are generally more likely to have a greater number of accidents).

Is there a technique I can use to find the "weighted" dangerousness of roads (i.e. by taking into account the possible relationships between the number of cars and accidents)?

• I am afraid you need to provide more details. Be specific. How does your database look like? To provide a weight, you need a weighting factor. Do you have something in mind? – Giuseppe Biondi-Zoccai Mar 9 '16 at 16:33
• What do you mean by weighted dangerous roads? Maybe you don't have enough information to say in which road is safest to ride for one hour, but you might be able to say something about where to change speed limit/put radar/more policeman etc – rep_ho Mar 9 '16 at 16:36
• @GiuseppeBiondiZoccai /user2173836- I've updated the question. Does this information help you understand what I am asking? Thanks for your help! – andyandy Mar 9 '16 at 17:28

## 1 Answer

Running the following command produces a nice plot with normalised heights:

ggplot(data, aes(as.factor(Road_Type), fill=as.factor(Accident_Severity))) + geom_bar(position="fill")


This indicates "the proportion of accidents that were of Accident_Severity=1,2,3 (where 1="at least one Fatal", 2="at least one Serious Injury", 3="at least one Slight Injury") that occurred on each individual road time". Thus this graph indicates that Road_Type=3 (i.e. 'Dual carriageways') are most fatal.