# Relative Risk Ratio with Confidence Intervals for multiple rows of data in R

Solution for Relative Risk Ratio with Confidence Intervals for multiple rows of data in R
is Given Below:

Is there an efficient way in R to calculate Relative Risk and 95% CI for multiple rows of data.

Data

or

``````test <- data.frame(Class = c("Grade 1", "Grade 2", "Grade 3"),
Male = c(39815, 0, 39815),
Pass_m = c(7743, 0, 4993),
Pct_male = c(19, 0, 12),
Female = c(26462, 0, 26462),
Pass_f = c(3929, 0, 2530),
Pct_female = c(14, 0, 9))
``````

Currently, my approach has been to do one set at a time.

``````riskratio.wald(table(Pass_m,Pass_f))
``````

This is painstakingly inefficient for more than 500 rows of data.

I have over 500 rows of data and would appreciate if anyone could provide an efficient way to solve this issue.

Also, Is the following calculation and interpretation correct:

risk = number of males pass by the population totals in each
group.

relative risk=risk of one group/risk of other group.

For first row, we can say that relative risk 19/14 = 1.36
Males are 1.36 times more likely to pass in Grade 1 compared to female(RR=1.36).

Is the calculation and interpretation correct?

Looks like a job for ‘apply’. It transfers each margin element (1 for rows) successively to the function.

`````` apply( test[ , c(3,6)],  1, riskratio.Wald)
``````

This of course is assuming that riskratio.Wald returns a single value. Since you didn’t say what package it’s from, that’s my hope, but you could improve the question be being more complete.

Is this what you are looking for? And see here is a very good answer of Ben Bolker
How to calculate relative risk in R?

``````epitab(as.matrix(test[ , c(3,6)]),method="riskratio")
``````

Output:

``````\$tab
Pass_m        p0 Pass_f        p1 riskratio     lower    upper  p.value
[1,]   7743 0.6633825   3929 0.3366175 1.0000000        NA       NA       NA
[2,]      0       NaN      0       NaN       NaN       NaN      NaN 1.000000
[3,]   4993 0.6636980   2530 0.3363020 0.9990626 0.9592189 1.040561 0.975038

\$measure
[1] "wald"

\$conf.level
[1] 0.95

\$pvalue
[1] "fisher.exact"
``````