## EXAMPLE 1
## A cross sectional study investigating the relationship between dry cat
## food (DCF) and feline urologic syndrome (FUS) was conducted (Willeberg
## 1977). Counts of individuals in each group were as follows:
## DCF-exposed cats (cases, non-cases) 13, 2163
## Non DCF-exposed cats (cases, non-cases) 5, 3349
dat <- as.table(matrix(c(13,2163,5,3349), nrow = 2, byrow = TRUE))
epi.2by2(dat = dat, method = "cross.sectional",
conf.level = 0.95, units = 100, homogeneity = "breslow.day",
verbose = FALSE)
## Prevalence ratio:
## The prevalence of FUS in DCF exposed cats is 4.01 times (95\% CI 1.43 to
## 11.23) greater than the prevalence of FUS in non-DCF exposed cats.
## Attributable fraction:
## In DCF exposed cats, 75\% of FUS is attributable to DCF (95\% CI 30\% to 91\%).
## Population attributable fraction:
## Fifty-four percent of FUS cases in the cat population are attributable
## to DCF (95\% CI 4\% to 78\%).
## EXAMPLE 2
## This example shows how the table function can be used to pass data to
## epi.2by2. Generate a case-control data set comprise of 1000 subjects.
## The probability of exposure is 0.50. The probability of disease in the
## exposed is 0.75, the probability of disease in the unexposed is 0.45.
n <- 1000; p.exp <- 0.50; pd.exp <- 0.75; pd.exn <- 0.45
dat <- data.frame(exp = rep(0, times = n), stat = rep(0, times = n))
dat$exp <- rbinom(n = n, size = 1, prob = p.exp)
dat$stat[dat$exp == 1] <- rbinom(n = length(dat$stat[dat$exp == 1]),
size = 1, prob = pd.exp)
dat$stat[dat$exp == 0] <- rbinom(n = length(dat$stat[dat$exp == 0]),
size = 1, prob = pd.exn)
dat$exp <- factor(dat$exp, levels = c("1", "0"))
dat$stat <- factor(dat$stat, levels = c("1", "0"))
head(dat)
## Create a 2 by 2 table from this simulated data set:
dat <- table(dat$exp, dat$stat, dnn = c("Exposure", "Disease"))
dat
## 2 by 2 table analysis:
epi.2by2(dat = dat, method = "case.control",
conf.level = 0.95, units = 100, homogeneity = "breslow.day",
verbose = FALSE)
## EXAMPLE 3
## A study was conducted by Feychting et al (1998) comparing cancer occurrence
## among the blind with occurrence among those who were not blind but had
## severe visual impairment. From these data we calculate a cancer rate of
## 136/22050 person-years among the blind compared with 1709/127650 person-
## years among those who were visually impaired but not blind.
dat <- as.table(matrix(c(136,22050,1709,127650), nrow = 2, byrow = TRUE))
rval <- epi.2by2(dat = dat, method = "cohort.time", conf.level = 0.90,
units = 1000, homogeneity = "breslow.day", verbose = TRUE)
round(rval$AR, digits = 3)
## The incidence rate of cancer was 7.22 cases per 1000 person-years less in the
## blind, compared with those who were not blind but had severe visual impairment
## (90\% CI 6.20 to 8.24 cases per 1000 person-years).
round(rval$IRR, digits = 3)
## The incidence rate of cancer in the blind group was less than half that of the
## comparison group (incidence rate ratio 0.46, 90\% CI 0.40 to 0.53).
## EXAMPLE 4
## Adapted from Elwood (2007, pages 194 -- 295):
## The results of an unmatched case control study of the association between
## smoking and cervical cancer were stratified by age. Counts of individuals
## in each group were as follows:
## Age group 20 - 29 years (cases, controls)
## Smokers: 41, 6
## Non-smokers: 13, 53
## Age group 30 - 39 years (cases, controls)
## Smokers: 66, 25
## Non-smokers: 37, 83
## Age +40 years (cases, controls)
## Smokers: 23, 14
## Non-smokers: 37, 62
## Coerce the count data that has been provided into tabular format (take
## care when setting strata labels to make sure they match up with appropriate
## contingency table data):
slabel <- c("20-29 yrs", "30-39 yrs", "40+ yrs")
dat <- data.frame(strata = rep(slabel, each = 2),
exp = rep(c("+","-"), times = length(slabel)), dis = rep(c("+","-"),
times = length(slabel)))
dat$exp <- factor(dat$exp, levels = c("+", "-"))
dat$dis <- factor(dat$dis, levels = c("+", "-"))
dat <- table(dat$exp, dat$dis, dat$strata,
dnn = c("Exposure", "Disease", "Strata"))
dat[1,1,] <- c(41,66,23)
dat[1,2,] <- c(6,25,14)
dat[2,1,] <- c(13,37,37)
dat[2,2,] <- c(53,83,62)
rval <- epi.2by2(dat = dat, method = "case.control", conf.level = 0.95,
units = 100, homogeneity = "breslow.day", verbose = TRUE)
rval
## Crude odds ratio:
## 6.57 (95\% CI 4.22 to 10.28)
## Mantel-Haenszel adjusted odds ratio:
## 6.27 (95\% CI 3.52 to 11.17)
## Mantel-Haenszel chi-squared test for difference in proportions:
## Test statistic 83.31; df = 1; P < 0.01
## Breslow Day test of homeogeneity of odds ratios:
## Test statistic 12.66; df = 2; P < 0.01
## We reject the null hypothesis and conclude that the strata level odds ratios
## are inhomogenous. The crude odds ratio is 6.57 (95\% CI 4.31 -- 10.03).
## The Mantel-Haenszel adjusted odds ratio is 6.27 (95\% CI 3.52 to 11.17).
## The crude odds ratio is 1.05 times the magnitude of the Mantel-Haenszel
## adjusted odds ratio so we conclude that age does not confound the association
## between smoking and risk of cervical cancer (using a ratio of greater
## than 1.10 or less than 0.90 as indicative of the presence of confounding).
## Now plot the individual strata-level odds ratio and compare them with the
## Mantel-Haenszel adjusted odds ratio.
## Not run:
library(latticeExtra)
nstrata <- 1:dim(dat)[3]
strata.lab <- paste("Strata ", nstrata, sep = "")
y.at <- c(nstrata, max(nstrata) + 1)
y.labels <- c("Mantel-Haenszel", strata.lab)
x.labels <- c(0.5, 1, 2, 4, 8, 16, 32, 64, 128)
or.l <- c(rval$OR.mh$lower, rval$OR.strata$lower)
or.u <- c(rval$OR.mh$upper, rval$OR.strata$upper)
or.p <- c(rval$OR.mh$est, rval$OR.strata$est)
vert <- 1:length(or.p)
segplot(vert ~ or.l + or.u, centers = or.p, horizontal = TRUE,
aspect = 1/2, col = "grey",
ylim = c(0,vert + 1),
xlab = "Odds ratio", ylab = "",
scales = list(y = list(at = y.at, labels = y.labels)),
main = "Strata level and summary measures of association")
## End(Not run)
## In this example the precision of the odds ratio estimate for both strata
## 2 and 3 is high (i.e. the confidence intervals are narrow) so strata 2
## and 3 carry most of the weight in determining the value of the
## Mantel-Haenszel adjusted odds ratio.Run the code above in your browser using DataLab