Created
June 16, 2018 20:23
-
-
Save chrissyhroberts/b1722100a9eac04c9d045c0ae9c02eec to your computer and use it in GitHub Desktop.
Odds Ratio Wald Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
oddsratioWald.proc <- function(n00, n01, n10, n11, alpha = 0.05) | |
{ | |
# Compute the odds ratio between two binary variables, x and y, | |
# as defined by the four numbers nij: | |
# | |
alpha<-0.05 | |
# n00 = number of cases where x = 0 and y = 0 | |
n00<-14 | |
# n01 = number of cases where x = 0 and y = 1 | |
n01<-01 | |
# n10 = number of cases where x = 1 and y = 0 | |
n10<-17 | |
# n11 = number of cases where x = 1 and y = 1 | |
n11<-81 | |
OR <- (n00 * n11)/(n01 * n10) | |
# | |
# Compute the Wald confidence intervals: | |
# | |
siglog <- sqrt((1/n00) + (1/n01) + (1/n10) + (1/n11)) | |
zalph <- qnorm(1-alpha/2) | |
logOR <- log(OR) | |
loglo <- logOR-zalph * siglog | |
loghi <- logOR + zalph * siglog | |
# | |
ORlo <- exp(loglo) | |
ORhi <- exp(loghi) | |
# | |
oframe <- data.frame(LowerCI = ORlo, OR = OR, UpperCI = ORhi, alpha = alpha) | |
oframe | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment