epitools: Relative Risks and Odds Ratios
Relative Risks and Odds Ratios
We can also compute relative risks (RR) and odds ratios (OR) to compare risk and odds of individuals falling within certain groups (income, education, etc.) also using cannabis at certain frequencies. Unfortunately, there are no functions in base R (or tidyverse) to compute RR and OR. So, we need to install and load another R package: epitools.
#install.packages("epitools")
library(epitools)To calculate the OR and RR, we first need to collapse our income and frequency groups into two binary outcomes respectively, and determine what constitutes to lower/ higher income and lower/ higher frequency.
Now we can perform our RR and OR calculations using the package function epitab():
The fifth column is labeled either riskratio or oddsratio, depending on which method you specify in the function. $tab at the end of the code is used to display the results in a table format. You will learn what the columns to the right of it later in the course.
Based on this output and these data, the odds of high frequency cannabis usage for those classified as being lower income is 1.56 times the odds those classified as being high income. And, the risk of high frequency cannabis usage for those classified as being higher income is roughly 17% lower than those in the low income group. In conclusion, lower income is associated with more frequent cannabis usage for recreational purposes.
Coding Exercise
You give it a try! Create appropriate summaries to explore the association between high cannabis usage frequency and education level. For simplicity, the cannabis_data has been cleaned for you with additional binary variables cannabis_use_binary (corresponding to recreational_use_frequency) and education_binary (corresponding to education).
What type of variables are they?
Review the code for cannabis use frequency and income.
Does any of those summaries that work in this situation?
Here are several options:
# Stacked barplot
barplot(table(cannabis_data$education, cannabis_data$recreational_use_frequency),
legend.text = TRUE,
xlab = "Highest Level of Education")
# Mosaic plot
mosaicplot(table(cannabis_data$education, cannabis_data$recreational_use_frequency),
legend.text = TRUE,
xlab = "Highest Level of Education", ylab="Recreational Cannabis Usage Frequency")
# Frequency table
table(cannabis_data$education, cannabis_data$recreational_use_frequency)
# Proportional table
prop.table(table(cannabis_data$education, cannabis_data$recreational_use_frequency),margin=2)
# RR
epitab(table(cannabis_data$education_binary, cannabis_data$cannabis_use_binary), method="riskratio")$tab
# OR
epitab(table(cannabis_data$education_binary, cannabis_data$cannabis_use_binary), method="oddsratio")$tab