I want to calculate 95% confidence intervals on for the odds ratio derived from a logistic regression calculated using the glm function.
I get the following output:
> fit <- glm(death ~ group, data=d, family=binomial(link="logit"))
> summary(fit)
Call:
glm(formula = death ~ group, family = binomial(link = "logit"),
data = d)
Deviance Residuals:
Min 1Q Median 3Q Max
-0.212 -0.212 -0.105 -0.105 3.224
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -3.784 0.358 -10.58 <0.0000000000000002 ***
group -1.409 0.794 -1.77 0.076 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 105.45 on 721 degrees of freedom
Residual deviance: 101.51 on 720 degrees of freedom
(8 Beobachtungen als fehlend gelöscht)
AIC: 105.5
Number of Fisher Scoring iterations: 8
As the summary function indicates, the P-value for group is >0.05. Therefore, I would expect that the confidence interval overlap the odds ratio of 1.
Searching the internet, I found two options for calculating the 95% confidence interval.
Option #1
> exp(
+ summary(fit)$coefficients["group", 1] + qnorm(c(0.025,0.5,0.975)) * summary(fit)$coefficients["group",2]
+ )
[1] 0.05155 0.24444 1.15913
Option #2
> exp(coef(summary(fit))[2,1]) # OR
[1] 0.2444
> exp(summary(fit)$coefficients["group", 1]) # OR
[1] 0.2444
> exp(confint(fit)[2,]) # 95% CI
Waiting for profiling to be done...
2.5 % 97.5 %
0.03672 0.98372
> exp(confint(fit)["group",]) # 95% CI
Waiting for profiling to be done...
2.5 % 97.5 %
0.03672 0.98372
While the upper confidence limit of option #1 is greater than 1, it is not the case for option #2. Why? What is the problem? Which confidence interval is correct?