# risk and odds chapter install.packages("epitools", dependencies=TRUE) library(epitools) ############ skiers ## matrix(c( column . . . . column), nrow , ncol) coloumnwise data thedata <- matrix(c(40, 20, 60, 80 ),nrow = 2 , ncol = 2) # now give the row then columns names - opposite way round to the matrix command) dimnames(thedata) <- list("group" = c("case", "control"), "outcome" = c("injury", "no_injury")) thedata epitab(thedata) ################ the aspirin data thedata <- matrix(c(55, 96, 5376, 5392),2 , 2) dimnames(thedata) <- list("group" = c("aspirin", "placebo"), "outcome" = c("heart_attack", "no_heart_attack")) thedata install.packages("epitools", dependencies=TRUE) library(epitools) epitab(thedata) ################## # different odd ratios CI estimates: oddsratio(thedata) oddsratio.midp(thedata) oddsratio.fisher(thedata) oddsratio.wald(thedata) oddsratio.small (thedata) ############################# # Risk ratios # need to make the control the #reference group ######## riskratio(thedata, rev = "both") riskratio.wald(thedata, rev = "both") riskratio.small(thedata, rev = "both") riskratio.boot(thedata, rev = "both") ### ## can also use: riskratio(method = "boot", rev = "both") etc detach("package:epitools") install.packages("epibasix", dependencies=TRUE) library(epibasix) summary(epi2x2(thedata)) ############## table of recipricals result <- matrix(seq(.5,10,.5), 2) result for (val in seq(1,10,.5)) { x<-1/val print(x) } val <- seq(.5,10,.5) recip <- round(1/val, 3) mydata <- data.frame(val,recip) names(mydata) <- c("value","reciprical") # variable names mydata