This section will cover how to use R to calculate an
odds ratio and the corresponding confidence interval estimate using
fisher.test(). The general approach is to first find the
frequency counts involved in the odds ratio, then setup our own data
frame containing each count in the proper location so that the computed
odds ratio properly compares the event of interest for each group.
The example data we’ll use comes from a 2009 study on the moves of novice rock-paper-scissors players. Below we find the two-way frequency table showing the relationship between a player’s first and second move:
rps = read.csv("https://remiller1450.github.io/data/rock_paper_scissors.csv")
table(rps$first_move, rps$second_move)
##
## Paper Rock Scissors
## Paper 16 11 12
## Rock 23 29 14
## Scissors 4 3 7
Suppose we are interested in the odds ratio comparing the odds of a player choosing “paper” for the second move for players who had already played “paper” for their first move relative to players who had played either rock or scissors for the first move:
\[\text{OR} = \frac{\text{Odds(Paper | Paper)}}{\text{Odds(Paper | Other)}}\] Notice the odds of a player who chose paper on their first move choosing paper on their second move are \(\tfrac{16}{11+12} = \tfrac{16}{23} = 0.695\) (number of paper choices relative to the number of non-paper choices). Likewise, the odds of a player who did not choose paper on their first move selecting paper for their second move are \(\tfrac{23+4}{29+14+3+7} = \frac{27}{53} = 0.509\)
Below we record the information needed to calculate this odds ratio in a data frame:
paper_or = data.frame(second_paper = c(16, 27), second_other = c(27,53), row.names = c("first_paper", "first_other"))
print(paper_or)
## second_paper second_other
## first_paper 16 27
## first_other 27 53
Notice the event of interest (choosing paper in the second round) is
in the first column, and the group we’d like to put in the numerator of
the odds ratio (those who picked paper in the first round) is in the
first row. This format allows us to use fisher.test() to
calculate the odds ratio and corresponding confidence interval:
fisher.test(paper_or, conf.int = TRUE, conf.level = 0.95)
##
## Fisher's Exact Test for Count Data
##
## data: paper_or
## p-value = 0.6974
## alternative hypothesis: true odds ratio is not equal to 1
## 95 percent confidence interval:
## 0.4954555 2.6873890
## sample estimates:
## odds ratio
## 1.161791
Because the 95% confidence interval contains an odds ratio of 1.0 (equal odds of choosing paper second in each group), there is insufficient evidence of an association.
\(~\)
In 1992 an unknown illness appeared in a small Alaskan community. Based upon the reported symptoms, the CDC suspected fluoride poisoning from one of the town’s water sources. The CDC surveyed 38 individuals from the community who reported feeling ill and 33 of them had drank from the water source. They also surveyed 54 residents who did not report feeling ill and only 8 of them said they had drank from the water source.
Question #1:
R to create a data frame
where the study outcome, suffering from the illness, is the first
column, and the exposure of interest, drinking from the suspected water
source, is the first row.fisher.test() to calculate
an odds ratio and 95% confidence interval investigating whether these
data provide statistical evidence of an association between use of the
water source and self-reported illness. Report a one-sentence conclusion
that summarizes whether these data provide statistically convincing
evidence of an association.\(~\)
An NIH study tracked a group of over 6000 women born in the 1980s in search of risk factors for breast cancer. They found that among the 4540 women who gave birth to their first child before age 25, 65 developed breast cancer during the course of the study, while among the 1188 women who gave birth to their first child after age 25, 31 developed breast cancer.
Question #2:
R to create a data frame
where the study outcome, developing breast cancer, is the first column,
and the exposure of interest, giving birth to the first child after age
25, is the first row.fisher.test() to calculate
an odds ratio and 95% confidence interval investigating whether these
data provide statistical evidence of an association between the age at
which a women gives birth to their first child and breast cancer.