epi.2by2: Summary measures for count data presented in a 2 by 2 table

Description Usage Arguments Details Value Note Author(s) References Examples

Description

Computes summary measures of risk and a chi-squared test for difference in the observed proportions from count data presented in a 2 by 2 table. With multiple strata the function returns crude and Mantel-Haenszel adjusted measures of association and chi-squared tests of homogeneity.

Usage

1
2
3
4
5
6
7
8
epi.2by2(dat, method = "cohort.count", conf.level = 0.95, units = 100, 
   outcome = "as.columns")

## S3 method for class 'epi.2by2'
print(x, ...)

## S3 method for class 'epi.2by2'
summary(object, ...)

Arguments

dat

an object of class table containing the individual cell frequencies. See the examples, below, for details.

method

a character string indicating the study design on which the tabular data has been based. Options are cohort.count, cohort.time, case.control, or cross.sectional. Based on the study design specified by the user, appropriate measures of association, measures of effect in the exposed and measures of effect in the population are returned by the function.

conf.level

magnitude of the returned confidence intervals. Must be a single number between 0 and 1.

units

multiplier for prevalence and incidence (risk or rate) estimates.

outcome

a character string indicating how the outcome variable is represented in the contingency table. Options are as.columns (outcome as columns) or as.rows (outcome as rows).

x, object

an object of class epi.2by2.

...

Ignored.

Details

Where method is cohort.count, case.control, or cross.sectional and outcome = as.columns the required 2 by 2 table format is:

----------- ---------- ---------- ----------
Disease + Disease - Total
----------- ---------- ---------- ----------
Expose + a b a+b
Expose - c d c+d
----------- ---------- ---------- ----------
Total a+c b+d a+b+c+d
----------- ---------- ---------- ----------

Where method is cohort.time and outcome = as.columns the required 2 by 2 table format is:

----------- ---------- -------------
Disease + Time at risk
----------- ---------- -------------
Expose + a b
Expose - c d
----------- ---------- -------------
Total a+c b+d
----------- ---------- -------------

A summary of the methods used for each of the confidence interval calculations in this function is as follows:

Value

An object of class epi.2by2 comprised of:

method

character string returning the study design specified by the user.

n.strata

number of strata.

conf.level

magnitude of the returned confidence intervals.

massoc

a list comprised of the computed measures of association, measures of effect in the exposed and measures of effect in the population. See below for details.

tab

a data frame comprised of of the contingency table data.

When method equals cohort.count the following measures of association, measures of effect in the exposed and measures of effect in the population are returned:

RR

Wald and score confidence intervals for the incidence risk ratios for each strata. Wald and score confidence intervals for the crude incidence risk ratio. Wald confidence interval for the Mantel-Haenszel adjusted incidence risk ratio.

OR

Wald, score, Cornfield and maximum likelihood confidence intervals for the odds ratios for each strata. Wald, score, Cornfield and maximum likelihood confidence intervals for the crude odds ratio. Wald confidence interval for the Mantel-Haenszel adjusted odds ratio.

ARisk

Wald and score confidence intervals for the attributable risk (risk difference) for each strata. Wald and score confidence intervals for the crude attributable risk. Wald, Sato and Greenland-Robins confidence intervals for the Mantel-Haenszel adjusted attributable risk.

PARisk

Wald and Pirikahu confidence intervals for the population attributable risk for each strata. Wald and Pirikahu confidence intervals for the crude population attributable risk. The Pirikahu confidence intervals are calculated using the delta method.

AFRisk

Wald confidence intervals for the attributable fraction for each strata. Wald confidence intervals for the crude attributable fraction.

PAFRisk

Wald confidence intervals for the population attributable fraction for each strata. Wald confidence intervals for the crude population attributable fraction.

chisq.strata

chi-squared test for difference in exposed and non-exposed proportions for each strata.

chisq.crude

chi-squared test for difference in exposed and non-exposed proportions across all strata.

chisq.mh

Mantel-Haenszel chi-squared test that the combined odds ratio estimate is equal to 1.

RR.homog

Mantel-Haenszel (Woolf) test of homogeneity of the individual strata incidence risk ratios.

OR.homog

Mantel-Haenszel (Woolf) test of homogeneity of the individual strata odds ratios.

When method equals cohort.time the following measures of association and effect are returned:

IRR

Wald confidence interval for the incidence rate ratios for each strata. Wald confidence interval for the crude incidence rate ratio. Wald confidence interval for the Mantel-Haenszel adjusted incidence rate ratio.

ARate

Wald confidence interval for the attributable rate for each strata. Wald confidence interval for the crude attributable rate. Wald confidence interval for the Mantel-Haenszel adjusted attributable rate.

PARate

Wald confidence interval for the population attributable rate for each strata. Wald confidence intervals for the crude population attributable rate.

AFRate

Wald confidence interval for the attributable fraction for each strata. Wald confidence interval for the crude attributable fraction.

PAFRate

Wald confidence interval for the population attributable fraction for each strata. Wald confidence interval for the crude poulation attributable fraction.

chisq.strata

chi-squared test for difference in exposed and non-exposed proportions for each strata.

chisq.crude

chi-squared test for difference in exposed and non-exposed proportions across all strata.

chisq.mh

Mantel-Haenszel chi-squared test that the combined odds ratio estimate is equal to 1.

When method equals case.control the following measures of association and effect are returned:

OR

Wald, score, Cornfield and maximum likelihood confidence intervals for the odds ratios for each strata. Wald, score, Cornfield and maximum likelihood confidence intervals for the crude odds ratio. Wald confidence interval for the Mantel-Haenszel adjusted odds ratio.

ARisk

Wald and score confidence intervals for the attributable risk for each strata. Wald and score confidence intervals for the crude attributable risk. Wald, Sato and Greenland-Robins confidence intervals for the Mantel-Haenszel adjusted attributable risk.

PARisk

Wald and Pirikahu confidence intervals for the population attributable risk for each strata. Wald and Pirikahu confidence intervals for the crude population attributable risk.

AFest

Wald confidence intervals for the estimated attributable fraction for each strata. Wald confidence intervals for the crude estimated attributable fraction.

PAFest

Wald confidence intervals for the population estimated attributable fraction for each strata. Wald confidence intervals for the crude population estimated attributable fraction.

chisq.strata

chi-squared test for difference in exposed and non-exposed proportions for each strata.

chisq.crude

chi-squared test for difference in exposed and non-exposed proportions across all strata.

chisq.mh

Mantel-Haenszel chi-squared test that the combined odds ratio estimate is equal to 1.

OR.homog

Mantel-Haenszel (Woolf) test of homogeneity of the individual strata odds ratios.

When method equals cross.sectional the following measures of association and effect are returned:

PR

Wald and score confidence intervals for the prevalence ratios for each strata. Wald and score confidence intervals for the crude prevalence ratio. Wald confidence interval for the Mantel-Haenszel adjusted prevalence ratio.

OR

Wald, score, Cornfield and maximum likelihood confidence intervals for the odds ratios for each strata. Wald, score, Cornfield and maximum likelihood confidence intervals for the crude odds ratio. Wald confidence interval for the Mantel-Haenszel adjusted odds ratio.

ARisk

Wald and score confidence intervals for the attributable risk for each strata. Wald and score confidence intervals for the crude attributable risk. Wald, Sato and Greenland-Robins confidence intervals for the Mantel-Haenszel adjusted attributable risk.

PARisk

Wald and Pirikahu confidence intervals for the population attributable risk for each strata. Wald and Pirikahu confidence intervals for the crude population attributable risk.

AFRisk

Wald confidence intervals for the attributable fraction for each strata. Wald confidence intervals for the crude attributable fraction.

PAFRisk

Wald confidence intervals for the population attributable fraction for each strata. Wald confidence intervals for the crude population attributable fraction.

chisq.strata

chi-squared test for difference in exposed and non-exposed proportions for each strata.

chisq.crude

chi-squared test for difference in exposed and non-exposed proportions across all strata.

chisq.mh

Mantel-Haenszel chi-squared test that the combined odds ratio estimate is equal to 1.

PR.homog

Mantel-Haenszel (Woolf) test of homogeneity of the individual strata prevalence ratios.

OR.homog

Mantel-Haenszel (Woolf) test of homogeneity of the individual strata odds ratios.

The point estimates of the wald, score and cfield odds ratios are calculated using the cross product method. Method mle computes the conditional maximum likelihood estimate of the odds ratio.

The Mantel-Haenszel chi-squared test that the combined odds ratio estimate is equal to 1 uses a two-sided test without continuity correction.

Note

Measures of association include the prevalence ratio, the incidence risk ratio, the incidence rate ratio and the odds ratio. The incidence risk ratio is the ratio of the incidence risk of disease in the exposed group to the incidence risk of disease in the unexposed group. The odds ratio (also known as the cross-product ratio) is an estimate of the incidence risk ratio. When the incidence of an outcome in the study population is low (say, less than 5%) the odds ratio will provide a reliable estimate of the incidence risk ratio. The more frequent the outcome becomes, the more the odds ratio will overestimate the incidence risk ratio when it is greater than than 1 or understimate the incidence risk ratio when it is less than 1.

Measures of effect in the exposed include the attributable risk (or prevalence) and the attributable fraction. The attributable risk is the risk of disease in the exposed group minus the risk of disease in the unexposed group. The attributable risk provides a measure of the absolute increase or decrease in risk associated with exposure. The attributable fraction is the proportion of study outcomes in the exposed group that is attributable to exposure.

Measures of effect in the population include the population attributable risk (or prevalence) and the population attributable fraction (also known as the aetiologic fraction). The population attributable risk is the risk of the study outcome in the population that may be attributed to exposure. The population attributable fraction is the proportion of the study outcomes in the population that is attributable to exposure.

Point estimates and confidence intervals for the prevalence ratio and incidence risk ratio are calculated using Wald (Wald 1943) and score methods (Miettinen and Nurminen 1985). Point estimates and confidence intervals for the incidence rate ratio are calculated using the exact method described by Kirkwood and Sterne (2003) and Juul (2004). Point estimates and confidence intervals the odds ratio are calculated using Wald (Wald 1943), score (Miettinen and Nurminen 1985) and maximum likelihood methods (Fleiss et al. 2003). Point estimates and confidence intervals for the population attributable risk are calculated using formulae provided by Rothman and Greenland (1998, p 271) and Pirikahu (2014). Point estimates and confidence intervals for the population attributable fraction are calculated using formulae provided by Jewell (2004, p 84 - 85). Point estimates and confidence intervals for the Mantel-Haenszel adjusted attributable risk are calculated using formulae provided by Klingenberg (2014).

Wald confidence intervals are provided in the summary table simply because they are widely used and would be familiar to most users.

The Mantel-Haenszel adjusted measures of association are valid when the measures of association across the different strata are similar (homogenous), that is when the test of homogeneity of the odds (risk) ratios is not significant.

The Mantel-Haenszel (Woolf) test of homogeneity of the odds ratio are based on Jewell (2004, p 152 - 158). Thanks to Jim Robison-Cox for sharing his implementation of these functions.

Author(s)

Mark Stevenson (Faculty of Veterinary and Agricultural Sciences, The University of Melbourne, Australia), Cord Heuer (EpiCentre, IVABS, Massey University, Palmerston North, New Zealand), Jim Robison-Cox (Department of Math Sciences, Montana State University, Montana, USA), Kazuki Yoshida (Brigham and Women's Hospital, Boston Massachusetts, USA) and Simon Firestone (Faculty of Veterinary and Agricultural Sciences, The University of Melbourne, Australia). Thanks to Ian Dohoo for numerous helpful suggestions to improve the documentation for this function.

References

Altman D, Machin D, Bryant T, Gardner M (2000). Statistics with Confidence. British Medical Journal, London, pp. 69.

Cornfield, J (1956). A statistical problem arising from retrospective studies. In: Proceedings of the Third Berkeley Symposium on Mathematical Statistics and Probability, University of California Press, Berkeley California 4: 135 - 148.

Elwood JM (2007). Critical Appraisal of Epidemiological Studies and Clinical Trials. Oxford University Press, London.

Feinstein AR (2002). Principles of Medical Statistics. Chapman Hall/CRC, London, pp. 332 - 336.

Fisher RA (1962). Confidence limits for a cross-product ratio. Australian Journal of Statistics 4: 41.

Feychting M, Osterlund B, Ahlbom A (1998). Reduced cancer incidence among the blind. Epidemiology 9: 490 - 494.

Fleiss JL, Levin B, Paik MC (2003). Statistical Methods for Rates and Proportions. John Wiley and Sons, New York.

Hanley JA (2001). A heuristic approach to the formulas for population attributable fraction. Journal of Epidemiology and Community Health 55: 508 - 514.

Jewell NP (2004). Statistics for Epidemiology. Chapman & Hall/CRC, London, pp. 84 - 85.

Juul S (2004). Epidemiologi og evidens. Munksgaard, Copenhagen.

Kirkwood BR, Sterne JAC (2003). Essential Medical Statistics. Blackwell Science, Malden, MA, USA.

Klingenberg B (2014). A new and improved confidence interval for the Mantel-Haenszel risk difference. Statistics in Medicine 33: 2968 - 2983.

Lancaster H (1961) Significance tests in discrete distributions. Journal of the American Statistical Association 56: 223 - 234.

Lawson R (2004). Small sample confidence intervals for the odds ratio. Communications in Statistics Simulation and Computation 33: 1095 - 1113.

Martin SW, Meek AH, Willeberg P (1987). Veterinary Epidemiology Principles and Methods. Iowa State University Press, Ames, Iowa, pp. 130.

McNutt L, Wu C, Xue X, Hafner JP (2003). Estimating the relative risk in cohort studies and clinical trials of common outcomes. American Journal of Epidemiology 157: 940 - 943.

Miettinen OS, Nurminen M (1985). Comparative analysis of two rates. Statistics in Medicine 4: 213 - 226.

Pirikahu S (2014). Confidence Intervals for Population Attributable Risk. Unpublished MSc thesis. Massey University, Palmerston North, New Zealand.

Robbins AS, Chao SY, Fonesca VP (2002). What's the relative risk? A method to directly estimate risk ratios in cohort studies of common outcomes. Annals of Epidemiology 12: 452 - 454.

Rothman KJ (2002). Epidemiology An Introduction. Oxford University Press, London, pp. 130 - 143.

Rothman KJ, Greenland S (1998). Modern Epidemiology. Lippincott Williams, & Wilkins, Philadelphia, pp. 271.

Sullivan KM, Dean A, Soe MM (2009). OpenEpi: A Web-based Epidemiologic and Statistical Calculator for Public Health. Public Health Reports 124: 471 - 474.

Wald A (1943). Tests of statistical hypotheses concerning several parameters when the number of observations is large. Transactions of the American Mathematical Society 54: 426 - 482.

Willeberg P (1977). Animal disease information processing: Epidemiologic analyses of the feline urologic syndrome. Acta Veterinaria Scandinavica. Suppl. 64: 1 - 48.

Woodward MS (2005). Epidemiology Study Design and Data Analysis. Chapman & Hall/CRC, New York, pp. 163 - 214.

Zhang J, Yu KF (1998). What's the relative risk? A method for correcting the odds ratio in cohort studies of common outcomes. Journal of the American Medical Association 280: 1690 - 1691.

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
## 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

## Outcome variable (FUS) as columns:
dat <- matrix(c(13,2163,5,3349), nrow = 2, byrow = TRUE)
rownames(dat) <- c("DF+", "DF-"); colnames(dat) <- c("FUS+", "FUS-"); dat

epi.2by2(dat = as.table(dat), method = "cross.sectional", 
   conf.level = 0.95, units = 100, outcome = "as.columns")

## Outcome variable (FUS) as rows:
dat <- matrix(c(13,5,2163,3349), nrow = 2, byrow = TRUE)
rownames(dat) <- c("FUS+", "FUS-"); colnames(dat) <- c("DF+", "DF-"); dat

epi.2by2(dat =  as.table(dat), method = "cross.sectional", 
   conf.level = 0.95, units = 100, outcome = "as.rows")

## Prevalence ratio:
## The prevalence of FUS in DCF exposed cats is 4.01 (95% CI 1.43 to 11.23) 
## times greater than the prevalence of FUS in non-DCF exposed cats.

## Attributable fraction in the exposed:
## In DCF exposed cats, 75% of FUS is attributable to DCF (95% CI 30% to 
## 91%).

## Attributable fraction in the population:
## 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. Here we use the birthwgt data from the MASS package.

library(MASS)
dat1 <- birthwt; head(dat1)

## Generate a table of cell frequencies. First set the levels of the outcome 
## and the exposure so the frequencies in the 2 by 2 table come out in the 
## conventional format:
dat1$low <- factor(dat1$low, levels = c(1,0))
dat1$smoke <- factor(dat1$smoke, levels = c(1,0))
dat1$race <- factor(dat1$race, levels = c(1,2,3))

## Generate the 2 by 2 table. Exposure (rows) = smoke. Outcome (columns) = low.
tab1 <- table(dat1$smoke, dat1$low, dnn = c("Smoke", "Low BW"))
print(tab1)

## Compute the incidence risk ratio and other measures of association:
epi.2by2(dat = tab1, method = "cohort.count", 
   conf.level = 0.95, units = 100, outcome = "as.columns")

## Odds ratio:
## The odds of having a low birth weight child for smokers is 2.02 
## (95% CI 1.08 to 3.78) times greater than the odds of having a low birth 
## weight child for non-smokers.

## Now stratify by race:
tab2 <- table(dat1$smoke, dat1$low, dat1$race, 
   dnn = c("Smoke", "Low BW", "Race"))
print(tab2)

## Compute the crude odds ratio, the Mantel-Haenszel adjusted odds ratio 
## and other measures of association:
rval <- epi.2by2(dat = tab2, method = "cohort.count", 
   conf.level = 0.95, units = 100, outcome = "as.columns")
print(rval)

## The Mantel-Haenszel test of homogeneity of the strata odds ratios is not 
## significant (chi square test statistic 2.8; df 2; p-value = 0.247). 
## We accept the null hypothesis and conclude that the odds ratios for 
## each strata of race are the same. 

## After accounting for the confounding effect of race, the odds of 
## having a low birth weight child for smokers is 3.09 (95% CI 1.49 to 6.39)
## times that of non-smokers.

## Compare the Greenland-Robins confidence intervals for the Mantel-Haenszel
## adjusted attributable risk with the Wald confidence intervals for the 
## Mantel-Haenszel adjusted attributable risk:

rval$massoc$ARisk.mh.green
rval$massoc$ARisk.mh.wald

## Now turn tab2 into a data frame where the frequencies of individuals in 
## each exposure-outcome category are provided. Often your data will be 
## presented in this summary format:
dat2 <- data.frame(tab2)
print(dat2)

## Re-format dat2 (a summary count data frame) into tabular format using the 
## xtabs function:
tab3 <- xtabs(Freq ~ Smoke + Low.BW + Race, data = dat2)
print(tab3)

# tab3 can now be passed to epi.2by2:
rval <- epi.2by2(dat = tab3, method = "cohort.count", 
   conf.level = 0.95, units = 100, outcome = "as.columns")
print(rval)

## The Mantel-Haenszel adjusted odds ratio is 3.09 (95% CI 1.49 to 6.39). The 
## ratio of the crude odds ratio to the Mantel-Haensel adjusted odds ratio is
## 0.66.

## What are the Cornfield confidence limits, the maximum likelihood 
## confidence limits and the score confidence limits for the crude odds ratio?
rval$massoc$OR.crude.cfield
rval$massoc$OR.crude.mle
rval$massoc$OR.crude.score

## Cornfield: 2.02 (95% CI 1.07 to 3.79)
## Maximum likelihood: 2.01 (1.03 to 3.96)
# Score: 2.02 (95% CI 1.08 to 3.77)

## Plot the individual strata-level odds ratios and compare them with the 
## Mantel-Haenszel adjusted odds ratio.

## Not run: 
library(ggplot2); library(scales)

nstrata <- 1:dim(tab3)[3]
strata.lab <- paste("Strata ", nstrata, sep = "")
y.at <- c(nstrata, max(nstrata) + 1)
y.lab <- c("M-H", strata.lab)
x.at <- c(0.25, 0.5, 1, 2, 4, 8, 16, 32)

or.l <- c(rval$massoc$OR.mh$lower, rval$massoc$OR.strata.cfield$lower)
or.u <- c(rval$massoc$OR.mh$upper, rval$massoc$OR.strata.cfield$upper)
or.p <- c(rval$massoc$OR.mh$est, rval$massoc$OR.strata.cfield$est)
dat <- data.frame(y.at, y.lab, or.p, or.l, or.u)

ggplot(dat, aes(or.p, y.at)) +
   geom_point() + 
   geom_errorbarh(aes(xmax = or.l, xmin = or.u, height = 0.2)) + 
   labs(x = "Odds ratio", y = "Strata") + 
   scale_x_continuous(trans = log2_trans(), breaks = x.at, 
   limits = c(0.25,32)) + scale_y_continuous(breaks = y.at, labels = y.lab) + 
   geom_vline(xintercept = 1, lwd = 1) + coord_fixed(ratio = 0.75 / 1) + 
   theme(axis.title.y = element_text(vjust = 0))

## End(Not run)

## 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.

## Not run: 
dat <- as.table(matrix(c(136,22050,1709,127650), nrow = 2, byrow = TRUE))
rval <- epi.2by2(dat = dat, method = "cohort.time", conf.level = 0.95, 
   units = 1000, outcome = "as.columns")
summary(rval)$ARate.strata.wald

## 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.00 to 8.43 cases per 1000 person-years).

round(summary(rval)$IRR.strata.wald, digits = 2)

## End(Not run)

## 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.38 to 0.55).

## EXAMPLE 4:
## A study has been conducted to assess the effect of a new treatment for 
## mastitis in dairy cows. Eight herds took part in the study. The following 
## data were obtained. The vectors ai, bi, ci and di list (for each herd) the 
## number of cows in the E+D+, E+D-, E-D+ and E-D- groups, respectively.

## Not run: 
hid <- 1:8
ai <- c(23,10,20,5,14,6,10,3)
bi <- c(10,2,1,2,2,2,3,0)
ci <- c(3,2,3,2,1,3,3,2)
di <- c(6,4,3,2,6,3,1,1)
dat <- data.frame(hid, ai, bi, ci, di)
print(dat)

## Re-format data frame dat into a format suitable for epi.2by2:
hid <- rep(1:8, times = 4)
exp <- factor(rep(c(1,1,0,0), each = 8), levels = c(1,0))
out <- factor(rep(c(1,0,1,0), each = 8), levels = c(1,0))
dat <- data.frame(hid, exp, out, n = c(ai,bi,ci,di)) 
dat <- xtabs(n ~ exp + out + hid, data = dat)
print(dat)

epi.2by2(dat = dat, method = "cohort.count", outcome= "as.columns")

## The Mantel-Haenszel test of homogeneity of the strata odds ratios is not 
## significant (chi square test statistic 5.276; df 7; p-value = 0.626). 
## We accept the null hypothesis and conclude that the odds ratios for each 
## strata of herd  are the same. 

## After adjusting for the effect of herd, compared to untreated cows, treatment
## increased the odds of recovery by a factor of 5.97 (95% CI 2.72 to 13.13).
 
## End(Not run)

Example output

Loading required package: survival
Package epiR 0.9-99 is loaded
Type help(epi.about) for summary information


    FUS+ FUS-
DF+   13 2163
DF-    5 3349
             Outcome +    Outcome -      Total        Prevalence *        Odds
Exposed +           13         2163       2176               0.597     0.00601
Exposed -            5         3349       3354               0.149     0.00149
Total               18         5512       5530               0.325     0.00327

Point estimates and 95 % CIs:
-------------------------------------------------------------------
Prevalence ratio                             4.01 (1.43, 11.23)
Odds ratio                                   4.03 (1.43, 11.31)
Attrib prevalence *                          0.45 (0.10, 0.80)
Attrib prevalence in population *            0.18 (-0.02, 0.38)
Attrib fraction in exposed (%)              75.05 (30.11, 91.09)
Attrib fraction in population (%)           54.20 (3.61, 78.24)
-------------------------------------------------------------------
 X2 test statistic: 8.177 p-value: 0.004
 Wald confidence limits
 * Outcomes per 100 population units 
      DF+  DF-
FUS+   13    5
FUS- 2163 3349
             Exposed +    Exposed -      Total
Outcome +           13            5         18
Outcome -         2163         3349       5512
Total             2176         3354       5530

Point estimates and 95 % CIs:
-------------------------------------------------------------------
Prevalence ratio                             4.01 (1.43, 11.23)
Odds ratio                                   4.03 (1.43, 11.31)
Attrib prevalence *                          0.45 (0.10, 0.80)
Attrib prevalence in population *            0.18 (-0.02, 0.38)
Attrib fraction in exposed (%)              75.05 (30.11, 91.09)
Attrib fraction in population (%)           54.20 (3.61, 78.24)
-------------------------------------------------------------------
 X2 test statistic: 8.177 p-value: 0.004
 Wald confidence limits
 * Outcomes per 100 population units 
   low age lwt race smoke ptl ht ui ftv  bwt
85   0  19 182    2     0   0  0  1   0 2523
86   0  33 155    3     0   0  0  0   3 2551
87   0  20 105    1     1   0  0  0   1 2557
88   0  21 108    1     1   0  0  1   2 2594
89   0  18 107    1     1   0  0  1   0 2600
91   0  21 124    3     0   0  0  0   0 2622
     Low BW
Smoke  1  0
    1 30 44
    0 29 86
             Outcome +    Outcome -      Total        Inc risk *        Odds
Exposed +           30           44         74              40.5       0.682
Exposed -           29           86        115              25.2       0.337
Total               59          130        189              31.2       0.454

Point estimates and 95 % CIs:
-------------------------------------------------------------------
Inc risk ratio                               1.61 (1.06, 2.44)
Odds ratio                                   2.02 (1.08, 3.78)
Attrib risk *                                15.32 (1.61, 29.04)
Attrib risk in population *                  6.00 (-4.33, 16.33)
Attrib fraction in exposed (%)               37.80 (5.47, 59.07)
Attrib fraction in population (%)            19.22 (-0.21, 34.88)
-------------------------------------------------------------------
 X2 test statistic: 4.924 p-value: 0.026
 Wald confidence limits
 * Outcomes per 100 population units 
, , Race = 1

     Low BW
Smoke  1  0
    1 19 33
    0  4 40

, , Race = 2

     Low BW
Smoke  1  0
    1  6  4
    0  5 11

, , Race = 3

     Low BW
Smoke  1  0
    1  5  7
    0 20 35

             Outcome +    Outcome -      Total        Inc risk *        Odds
Exposed +           30           44         74              40.5       0.682
Exposed -           29           86        115              25.2       0.337
Total               59          130        189              31.2       0.454


Point estimates and 95 % CIs:
-------------------------------------------------------------------
Inc risk ratio (crude)                       1.61 (1.06, 2.44)
Inc risk ratio (M-H)                         2.15 (1.29, 3.58)
Inc risk ratio (crude:M-H)                   0.75
Odds ratio (crude)                           2.02 (1.08, 3.78)
Odds ratio (M-H)                             3.09 (1.49, 6.39)
Odds ratio (crude:M-H)                       0.66
Attrib risk (crude) *                        15.32 (1.61, 29.04)
Attrib risk (M-H) *                          22.17 (1.41, 42.94)
Attrib risk (crude:M-H)                      0.69
-------------------------------------------------------------------
 Test of homogeneity of IRR: X2 test statistic: 3.815 p-value: 0.148
 Test of homogeneity of  OR: X2 test statistic: 3.126 p-value: 0.21
 Wald confidence limits
 M-H: Mantel-Haenszel
 * Outcomes per 100 population units 
       est    lower    upper
1 22.17306 8.797794 35.54832
       est    lower    upper
1 22.17306 1.410787 42.93532
   Smoke Low.BW Race Freq
1      1      1    1   19
2      0      1    1    4
3      1      0    1   33
4      0      0    1   40
5      1      1    2    6
6      0      1    2    5
7      1      0    2    4
8      0      0    2   11
9      1      1    3    5
10     0      1    3   20
11     1      0    3    7
12     0      0    3   35
, , Race = 1

     Low.BW
Smoke  1  0
    1 19 33
    0  4 40

, , Race = 2

     Low.BW
Smoke  1  0
    1  6  4
    0  5 11

, , Race = 3

     Low.BW
Smoke  1  0
    1  5  7
    0 20 35

             Outcome +    Outcome -      Total        Inc risk *        Odds
Exposed +           30           44         74              40.5       0.682
Exposed -           29           86        115              25.2       0.337
Total               59          130        189              31.2       0.454


Point estimates and 95 % CIs:
-------------------------------------------------------------------
Inc risk ratio (crude)                       1.61 (1.06, 2.44)
Inc risk ratio (M-H)                         2.15 (1.29, 3.58)
Inc risk ratio (crude:M-H)                   0.75
Odds ratio (crude)                           2.02 (1.08, 3.78)
Odds ratio (M-H)                             3.09 (1.49, 6.39)
Odds ratio (crude:M-H)                       0.66
Attrib risk (crude) *                        15.32 (1.61, 29.04)
Attrib risk (M-H) *                          22.17 (1.41, 42.94)
Attrib risk (crude:M-H)                      0.69
-------------------------------------------------------------------
 Test of homogeneity of IRR: X2 test statistic: 3.815 p-value: 0.148
 Test of homogeneity of  OR: X2 test statistic: 3.126 p-value: 0.21
 Wald confidence limits
 M-H: Mantel-Haenszel
 * Outcomes per 100 population units 
       est    lower    upper
1 2.021944 1.073694 3.794586
       est   lower    upper
1 2.014137 1.02878 3.964904
       est    lower    upper
1 2.021944 1.084385 3.773885
       est     lower     upper
1 -7.22037 -8.435865 -6.004875
   est lower upper
1 0.46  0.38  0.55
  hid ai bi ci di
1   1 23 10  3  6
2   2 10  2  2  4
3   3 20  1  3  3
4   4  5  2  2  2
5   5 14  2  1  6
6   6  6  2  3  3
7   7 10  3  3  1
8   8  3  0  2  1
, , hid = 1

   out
exp  1  0
  1 23 10
  0  3  6

, , hid = 2

   out
exp  1  0
  1 10  2
  0  2  4

, , hid = 3

   out
exp  1  0
  1 20  1
  0  3  3

, , hid = 4

   out
exp  1  0
  1  5  2
  0  2  2

, , hid = 5

   out
exp  1  0
  1 14  2
  0  1  6

, , hid = 6

   out
exp  1  0
  1  6  2
  0  3  3

, , hid = 7

   out
exp  1  0
  1 10  3
  0  3  1

, , hid = 8

   out
exp  1  0
  1  3  0
  0  2  1

             Outcome +    Outcome -      Total        Inc risk *        Odds
Exposed +           91           22        113              80.5       4.136
Exposed -           19           26         45              42.2       0.731
Total              110           48        158              69.6       2.292


Point estimates and 95 % CIs:
-------------------------------------------------------------------
Inc risk ratio (crude)                       1.91 (1.34, 2.72)
Inc risk ratio (M-H)                         1.94 (1.35, 2.78)
Inc risk ratio (crude:M-H)                   0.98
Odds ratio (crude)                           5.66 (2.67, 12.02)
Odds ratio (M-H)                             5.97 (2.72, 13.13)
Odds ratio (crude:M-H)                       0.95
Attrib risk (crude) *                        38.31 (22.14, 54.48)
Attrib risk (M-H) *                          39.21 (21.11, 57.30)
Attrib risk (crude:M-H)                      0.98
-------------------------------------------------------------------
 Test of homogeneity of IRR: X2 test statistic: 15.207 p-value: 0.033
 Test of homogeneity of  OR: X2 test statistic: 6.452 p-value: 0.488
 Wald confidence limits
 M-H: Mantel-Haenszel
 * Outcomes per 100 population units 

epiR documentation built on Aug. 23, 2019, 9:03 a.m.