Description Usage Format Source References Examples
Frequency of cancer in 39,876 women taking and not taking aspirin.
1 |
A data frame with 4 observations on the following 3 variables.
treatmenta factor with levels Aspirin and Placebo
cancera factor with levels no and yes
counta numeric vector
Cook, N.R., I. Lee, J.M. Gaziano, D. Gordon, P.M. Ridker, J.E. Manson, C.H. Hennekens, and J.E. Buring. 2005. Low-dose aspirin in the primary prevention of cancer. Journal of the American Medical Association 294: 47-55.
http://jama.ama-assn.org/cgi/content/abstract/294/1/47
1 | demo(sec9.2)
|


Loading required package: nlme
Loading required package: lattice
Loading required package: grid
Loading required package: mosaic
Loading required package: dplyr
Attaching package: 'dplyr'
The following object is masked from 'package:nlme':
collapse
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
Loading required package: ggformula
Loading required package: ggplot2
Loading required package: ggstance
Attaching package: 'ggstance'
The following objects are masked from 'package:ggplot2':
GeomErrorbarh, geom_errorbarh
New to ggformula? Try the tutorials:
learnr::run_tutorial("introduction", package = "ggformula")
learnr::run_tutorial("refining", package = "ggformula")
Loading required package: mosaicData
Loading required package: Matrix
The 'mosaic' package masks several functions from core packages in order to add
additional features. The original behavior of these functions should not be affected by this.
Note: If you use the Matrix package, be sure to load it BEFORE loading mosaic.
Attaching package: 'mosaic'
The following object is masked from 'package:Matrix':
mean
The following object is masked from 'package:ggplot2':
stat
The following objects are masked from 'package:dplyr':
count, do, tally
The following objects are masked from 'package:stats':
IQR, binom.test, cor, cor.test, cov, fivenum, median, prop.test,
quantile, sd, t.test, var
The following objects are masked from 'package:base':
max, mean, min, prod, range, sample, sum
demo(sec9.2)
---- ~~~~~~
> str(Aspirin)
'data.frame': 39876 obs. of 2 variables:
$ treatment: Factor w/ 2 levels "Aspirin","Placebo": 1 1 1 1 1 1 1 1 1 1 ...
$ cancer : Factor w/ 2 levels "no","yes": 2 2 2 2 2 2 2 2 2 2 ...
> # Plot 2 X 2 Contingency tables
> plot( ~ treatment + cancer, data = Aspirin)
> plot(table(Aspirin), main = "")
> # Calculate odds
> (Pr.asp <- 18496 / (18496 + 1438))
[1] 0.9278619
> (Odds.asp <- Pr.asp / (1 - Pr.asp))
[1] 12.86231
> (Pr.no.asp <- 18515 / (18515 + 1427))
[1] 0.9284425
> (Odds.no.asp <- Pr.no.asp / (1 - Pr.no.asp))
[1] 12.97477
> (Odds <- Odds.asp / Odds.no.asp)
[1] 0.9913321
> ln.Odds <- log(Odds)
> (SE.Odds <- sqrt(sum(1/table(Aspirin))))
[1] 0.03878475
> Z <- 1.96
> (CI.low <- ln.Odds - Z * SE.Odds)
[1] -0.08472376
> (CI.high <- ln.Odds + Z * SE.Odds)
[1] 0.06731248
> exp(CI.low)
[1] 0.918766
> exp(CI.high)
[1] 1.06963
> # Using oddsRatio() from the mosaic package
> # First reformat the data so that "No cancer" is in column 1
> # and "Aspirin" is in row 2.
> x <- matrix(c(18515, 18496, 1427, 1438), nrow = 2)
> x
[,1] [,2]
[1,] 18515 1427
[2,] 18496 1438
> oddsRatio(x)
[1] 0.9913321
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.