In: Statistics and Probability
Refer to Table 2.9. Construct and interpret a 95% confidence interval for the population (a) odds ratio, (b) difference of proportions, and (c) relative risk between seat-belt use and type of injury.
Answer (a) (b) and (c) Reproduce the table in R and display it.
MI <- matrix(c(1601, 510, 162527, 412368), nrow = 2)
dimnames(MI) <- list("Group" = c("None","Seat belt"), "MI" = c("Fatal","Non Fatal"))
MI
MI
Group Fatal Non Fatal
None 1601 162527
Seat belt 510 412368
We can calculate proportions in R using the prop.table function:
prop.table(MI, margin = 1)
MI
Group Fatal Non Fatal
None 0.009754582 0.9902454
Seat belt 0.001235232 0.9987648
Difference of Proportions:The easiest way is to use the prop.test function
prop.test(MI)
2-sample test for equality of proportions with continuity correction
data: MI
X-squared = 2336.1, df = 1, p-value < 2.2e-16
alternative hypothesis: two.sided
95 percent confidence interval:
0.008027691 0.009011009
sample estimates:
prop 1 prop 2
0.009754582 0.001235232
You can find the details of getting answers at following link:
https://data.library.virginia.edu/comparing-proportions-with-relative-risk-and-odds-ratios/
The 95 percent confidence interval is reported to be about (0.008, 0.009).
The actual estimated difference is not provided but we can calculate it easily enough as follows:
p.out <- prop.test(MI)
> p.out$estimate[1] - p.out$estimate[2]
prop 1
0.00851935
Relative Risk: Relative risk is usually defined as the ratio of two “success” proportions. In our case, that’s the “Fatal” group. We can calculate the relative risk in R “by hand” doing something like this:
prop.out <- prop.table(MI, margin = 1)
> prop.out[1,1]/prop.out[1,2]
[1] 0.009850671
Like the difference in proportions, relative risk is just an estimate when working with a sample. Its a good idea to calculate a confidence interval for the relative risk to determine a range of plausible values. Once again we’ll let R do this for us, but this time we’ll use the epitools package, which provides functions for analysis in epidemiology. The function we want is riskratio.
rr.out <- riskratio(MI)
> rr.out$measure
risk ratio with 95% C.I.
Group estimate lower upper
None 1.000000 NA NA
Seat belt 1.008603 1.008107 1.0091
> rr.out <- riskratio(MI, rev="c")
> rr.out$measure
risk ratio with 95% C.I.
Group estimate lower upper
None 1.0000000 NA NA
Seat belt 0.1266309 0.1146384 0.139878
> rr.out <- riskratio(MI, rev="b")
> rr.out$measure
risk ratio with 95% C.I.
Group estimate lower upper
Seat belt 1.000000 NA NA
None 7.896965 7.149089 8.723078
Odds Ratios:
> prop.out[1,1]/prop.out[1,2]
[1] 0.009850671
> prop.out[2,1]/prop.out[2,2]
[1] 0.001236759