Created
May 5, 2014 17:09
-
-
Save gregglind/44344c1da126b72a3b06 to your computer and use it in GitHub Desktop.
Exploring Lift and Relative Risk
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
# lift: p(x,y) / ( p(x)*p(y) == ratio of 'overage' compared to independence | |
# rr = relative risk == p(x+|y+) / p(x-|y-) | |
rr_more <- function(n){ | |
m <- matrix(rmultinom(1,n,c(1,2,3,4)),c(2,2)) | |
rownames(m) <- colnames(m) <- c(T,F) | |
R <- rowSums(m) | |
C <- colSums(m) | |
lift <- m[1,1] / (R[1] * C[1] / n) | |
rr <- (m[1,1] / R[1]) / (m[2,1] / R[2]) | |
pred <- rowSums(m) %*% t(colSums(m)) / (n) | |
save <- m[1,1] - pred[1,1] | |
return (list(obs=m, pred=pred, lift=lift, rr=rr, save=save, R=R, C=C)) | |
} | |
# suggested call: rr_more(100) | |
# Assertion: | |
# "number of people we would save by fixing factor" | |
# is p(outcome) * p(factor) * (1 - lift) * N | |
# because: | |
# if outcome and factor were independent, you would have | |
# p(o) * p(f) * N people. (i.e., lift of 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment