R function for standardized odds ratio
Assuming that M is a regular Logit model run through glm(). The the odds-ratio and standardized odds-ratio can be obtained by the simple function below:
#--------------------------------------------------------
# The function
#--------------------------------------------------------
#. Warning! The function only works when the glm() has an intercept.
s.o.ratio <- function(M){
o.r <- exp(M$coefficients)
o.r[1] <- NA
n <- dim(M$model)[2]
s.d <- rep(NA,n)
for (i in 1:n) {
s.d[i] <- sd(as.numeric(M$model[,i]))
}
s.o.r <- o.r^s.d
out <- rbind(M$coefficients,
s.d, o.r, s.o.r)
rownames(out) <- c("coefficient","st.d",
"odds.ratio", "s.odds.ratio")
out
}
#--------------------------------------------------------
# An output example
#--------------------------------------------------------
> M$call
glm(formula = OUT ~ 1 + MSA + POPLG + POPLG2 + CHIEF,
family = binomial(link = "logit"),
data = subset(data, YEAR == 2005))
>
> options(digits=5)
> s.o.ratio(M)
(Intercept) MSA POPLG POPLG2 CHIEF
coefficient -1.43239 -0.30271 0.043694 0.0014416 -0.29127
st.d 0.44053 0.45442 1.174887 25.1826820 0.49213
odds.ratio NA 0.73881 1.044662 1.0014427 0.74731
s.odds.ratio NA 0.87148 1.052676 1.0369708 0.86646
Note: The function needs to be tweaked if the model has fixed effects or categorical variables.