12
$\begingroup$

I have the following data from a Research paper:

S1 : n = 30 / Rest : n = 66

SH      11  /      8

For this to calculate p-value I have done it like following:

library(MASS)
x = matrix(c(19,11,58,8), nrow=2, byrow=T)
D = factor(c("S1","SH"), levels=c("S1","SH"))
m = glm(x~D, family=binomial)
summary(m)

Call:
glm(formula = x ~ D, family = binomial)

Deviance Residuals: 
[1]  0  0

Coefficients:
        Estimate Std. Error z value Pr(>|z|)   
(Intercept)   0.5465     0.3789   1.443  0.14914   
DSH           1.4345     0.5346   2.683  0.00729 **
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for binomial family taken to be 1)

Null deviance:  7.3387e+00  on 1  degrees of freedom
Residual deviance: -8.8818e-16  on 0  degrees of freedom
AIC: 11.607

Number of Fisher Scoring iterations: 3

The p-value is 0.007. This is same as I saw in the research paper. And the Odds Ratio is given as 4.20 and 95% CI is (1.47-11.97)

I would like to know how to calculate Odds Ratio and 95% Confidence interval for this? Can anyone please tell me how can I calculate this in R? Are there any functions?

$\endgroup$
1
  • 2
    $\begingroup$ The function odds.ratio(your_model) from package questionr gives you odds.ratio with confidence intervals library("questionr"); odds.ratio(your_model, level=0.95). $\endgroup$ Aug 13, 2019 at 10:28

3 Answers 3

12
$\begingroup$
  • $\exp(1.4345) \approx 4.20$
  • $\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
$\endgroup$
6
  • $\begingroup$ Could you please tell me what is this? qnorm(c(0.025,0.5,0.975)) $\endgroup$ Sep 25, 2017 at 13:25
  • 1
    $\begingroup$ It is the ends of a $95\%$ symmetric interval for a standard normal distribution, with the median between them, i.e. c(-1.959964, 0.000000, 1.959964) $\endgroup$
    – Henry
    Sep 25, 2017 at 13:28
  • $\begingroup$ Hi Henry, the p-value tells us that whether it is statistically significant or not. But what does Odds ratio (95% CI) tell us? In your answer 1.472098 is OR and what does 4.19 (2.5%) and 11.96 (97.5%) mean? Could you please explain what does does OR tell us? $\endgroup$ Oct 16, 2017 at 13:30
  • $\begingroup$ @Henry Hi Henry, could you explain why you chose a normal distribution critical value 1.96 rather than a t-distribution critical value? $\endgroup$
    – Yujian
    Apr 7, 2018 at 21:18
  • 1
    $\begingroup$ @Yujian I think logistic regression does not have a theory that justifies using t-distributions. Thus, the only justification for conventional confidence intervals and hypothesis tests is based on the central limit theorem. For example, Moore, Mccabe, and Craig's textbook, chapter 14, uses normal-based confidence intervals and hypothesis tests for logistic regression. $\endgroup$ Jul 22, 2021 at 15:32
12
$\begingroup$

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)))
$\endgroup$
0
$\begingroup$

Another possible way of calculating the Odds ratio, using your model 'm' would be as below:

# For odds ratio
m$coefficients
exp(m$coefficients)

And for finding the Confidence intervals, you can simply use:

# for confidence intervals
exp(confint(m))

Just for reference, the overall p-value (not just the p-value for each of the predictors) for logistic regression could also be computed:

summary(m)
(modelChi = m$null.deviance - m$deviance)  # for chi sq statistic
(chiDF = m$df.null - m$df.residual)        # for DF
(chisq_prob = 1 - pchisq(modelChi, chiDF)) # for hypothesis testing probability 
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.