(heart <- as.table(matrix(c(11, 2, 4, 6), nrow=2,
dimnames = list(Exposure = c("High", "Low"),
Response = c("Yes", "No")))))
RelRisk(heart)
# calculated as (11/15)/(2/8)
OddsRatio(heart)
# calculated as (11/4)/(2/6)
ORToRelRisk(OddsRatio(heart), p0 = 2/8)
# Relative risk = odds ratio / (1 - p0 + (p0 * odds ratio))
# where p0 is the baseline risk
## single OR to RR
ORToRelRisk(14.1, 0.05)
## OR and 95% confidence interval
ORToRelRisk(c(14.1, 7.8, 27.5), 0.05)
## Logistic OR and 95% confidence interval
logisticOR <- rbind(c(14.1, 7.8, 27.5),
c(8.7, 5.5, 14.3),
c(27.4, 17.2, 45.8),
c(4.5, 2.7, 7.8),
c(0.25, 0.17, 0.37),
c(0.09, 0.05, 0.14))
colnames(logisticOR) <- c("OR", "2.5%", "97.5%")
rownames(logisticOR) <- c("7.4", "4.2", "3.0", "2.0", "0.37", "0.14")
logisticOR
## p0
p0 <- c(0.05, 0.12, 0.32, 0.27, 0.40, 0.40)
## Compute corrected RR
## helper function
ORToRelRisk.mat <- function(or, p0){
res <- matrix(NA, nrow = nrow(or), ncol = ncol(or))
for(i in seq_len(nrow(or)))
res[i,] <- ORToRelRisk(or[i,], p0[i])
dimnames(res) <- dimnames(or)
res
}
RR <- ORToRelRisk.mat(logisticOR, p0)
round(RR, 2)
## Results are not completely identical to Zhang and Yu (1998)
## what probably is caused by the fact that the logistic OR values
## provided in the table are rounded and not true values.
Run the code above in your browser using DataLab