Using R to Evaluate Relative and Absolute Measures


To save ourselves time and to reduce the risk of making an error, we can also use R to perform the computation of these measures of association. R can also be used to calculate the 95% confidence intervals for each measure of association and can also compute the test statistic for the corresponding hypothesis tests.

Note that while R can compute the rate difference as well as its corresponding confidence interval and hypothesis test, those computations are beyond the scope of this class. Here, we will be covering risk ratios, rate ratios, risk differences, and odds ratios.

To perform these calculations in R, we will use the epi.2by2 function in the epiR package. To install the epiR package in RStudio, you can simply type the following into the console:

>install.packages("epiR")

Note that installation of the package only has to be done the first time you want to use the epiR package. After installation of the package, you need to load the epiR package into the current RStudio session. This step has to be performed every time you open a new R session and want to use the epiR package.

To load the epiR package, type the following into your console:

>library(epiR)

[Insert video clip on installing and loading packages in R.]

 

To see how to use R to perform the hand calculations in this module, download smoking_lungca.csv, and then watch and follow-along with the video below.

[Insert epi.2by2 video here]

 

Important note: The z-test comparing two proportions, which we calculated by hand to test the risk difference, is equivalent to the chi-square test of independence, and the prop.test( ) procedure (which we used in the video to test whether the risk difference is different from 0) formally calculates the chi-square test.

The p-value from the z-test for two proportions is equal to the p-value from the chi-square test, and the z-statistic is equal to the square root of the chi-square statistic in this situation.