Created
November 28, 2015 00:34
-
-
Save docsteveharris/264628336fa9f75c6b43 to your computer and use it in GitHub Desktop.
Function to calculate the median odds ratio
This file contains hidden or 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
# via https://stat.ethz.ch/pipermail/r-sig-mixed-models/2008q2/000874.html | |
# Calculate the median odds ratio | |
# ------------------------------- | |
MOR <- function(my.var, digits = 2) | |
{ # MOR arguments: my.var = variance associated with level 2 clustering variable | |
# digits = number of decimal places to which MOR value will be rounded. | |
Median.OR <- round(exp(sqrt(2*my.var)*qnorm(.75)), digits) | |
paste("Median Odds-Ratio (MOR) = ", Median.OR) } | |
IOR <- function(my.var, my.coef, my.diff, digits = 2) | |
{ # IOR arguments: my.var = variance associated with level 2 clustering variable | |
# my.coef = fixed effect coefficient associated with a level 2 covariate | |
# my.diff = difference between 2 different possible values on the level | |
# 2 covariate associated with my.coef | |
# digits = number of decimal places to which MOR value will be rounded. | |
IOR.LL <- round(exp(my.coef*my.diff + sqrt(2*my.var)*qnorm(.10)), digits) | |
IOR.UL <- round(exp(my.coef*my.diff + sqrt(2*my.var)*qnorm(.90)), digits) | |
print("80% Interval Odds Ratio lower & upper limits (IOR.LL & IOR.UL)") | |
cbind(my.var, my.coef, my.diff, IOR.LL, IOR.UL) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Steve, I'm going to nick this function if you don't mind!