- $\exp(1.4345+1.96 \times 0.5346) \approx 11.97
\exp(1.4345-1.96 \times 0.5346) \approx 1.472$
In R
> exp(summary(m)$coefficients["DSH",1] +
+ qnorm(c(0.025,0.5,0.975)) * summary(m)$coefficients["DSH",2])
[1] 1.472098 4.197368 11.967884
Answer from Henry on Stack ExchangeVideos
- $\exp(1.4345+1.96 \times 0.5346) \approx 11.97
\exp(1.4345-1.96 \times 0.5346) \approx 1.472$
In R
> exp(summary(m)$coefficients["DSH",1] +
+ qnorm(c(0.025,0.5,0.975)) * summary(m)$coefficients["DSH",2])
[1] 1.472098 4.197368 11.967884
You can also use the confint.default function which is based on asymptotic normality.
exp(cbind("Odds ratio" = coef(m), confint.default(m, level = 0.95)))
Here is the derivation using the delta method. Let's look at the familiar -Table below.
Suppose that where
is defined as in the table above.
The Odds Ratio is defined as
We want to derive the variance of
. The multivariable version of the delta method is:
Where
is the gradient vector. That is:
We want to estimate
Let the function
be
The gradient
is
The variance covariance matrix for a multinomial distribution with
categories is
$$
\Sigma=\frac{1}{n}\left(
\begin{array}{cccc}
\left(1-p_{11}\right) p_{11} & -p_{11} p_{12} & -p_{11} p_{21} & -p_{11} p_{22} \\
-p_{11} p_{12} & \left(1-p_{12}\right) p_{12} & -p_{12} p_{21} & -p_{12} p_{22} \\
-p_{11} p_{21} & -p_{12} p_{21} & \left(1-p_{21}\right) p_{21} & -p_{21} p_{22} \\
-p_{11} p_{22} & -p_{12} p_{22} & -p_{21} p_{22} & \left(1-p_{22}\right) p_{22} \\
\end{array}
\right)
$$
Then
equals
Now we need
which equals:
Substituting the MLEs for
finally yields
So the approximative standard error for the relative risk on the log-scale is
So an approximative two-sided confidence interval of level
for the relative risk on the original scale is
There is actually a section on this in the book Practical Guide to Logistic Regression by Joseph Hilbe on Pages 25-26. They derive a function here that is also in the LOGIT package as the toOR function.
toOR <- function(object, ...) {
coef <- object$coef
se <- sqrt(diag(vcov(object)))
zscore <- coef / se
or <- exp(coef)
delta <- or * se
pvalue <- 2*pnorm(abs(zscore),lower.tail=FALSE)
loci <- coef - qnorm(.975) * se
upci <- coef + qnorm(.975) * se
ortab <- data.frame(or, delta, zscore,
pvalue, exp(loci), exp(upci))
round(ortab, 4)
}
If you load the LOGIT library and the medpar dataset from their package, you can test this out yourself with the following code below:
library(LOGIT)
smlogit <- glm(died ~ white + los + factor(type),
family = binomial, data = medpar)
toOR(smlogit)
Which gives you the confidence intervals you want on the far right.
or delta zscore pvalue exp.loci. exp.upci.
(Intercept) 0.4885 0.1065 -3.2855 0.0010 0.3186 0.7490
white 1.3569 0.2835 1.4610 0.1440 0.9010 2.0436
los 0.9635 0.0075 -4.7747 0.0000 0.9488 0.9783
factor(type)2 1.5163 0.2184 2.8900 0.0039 1.1433 2.0109
factor(type)3 2.5345 0.5789 4.0716 0.0000 1.6198 3.9657
Dipetkov has also kindly mentioned in the comments an alternative from the 'broom' package if you are interested as well.
How many % is the probability for the event to happen?