5
$\begingroup$

I have this data that is the result of a logistic regression.

df<-structure(list(`Predictors of failure` = c("Variable A", "Variable B", 
"Variable C", "Variable D", "Variable E", "Variable F"), Estimate = c(1.73, 
1.18, 1.59, -0.04, 0.16, -0.003), OR = c(3, 3.26, 4.88, 0.98, 
1.01, 1), `p-value` = c(0.049, 0.043, 0.025, 0.095, 0.763, 0.172
)), row.names = c(NA, -6L), spec = structure(list(cols = list(
    `Predictors of failure` = structure(list(), class = c("collector_character", 
    "collector")), Estimate = structure(list(), class = c("collector_double", 
    "collector")), OR = structure(list(), class = c("collector_double", 
    "collector")), `p-value` = structure(list(), class = c("collector_double", 
    "collector"))), default = structure(list(), class = c("collector_guess", 
"collector")), delim = ","), class = "col_spec"), problems = <pointer: 0x000002805bfca420>, class = c("spec_tbl_df", 
"tbl_df", "tbl", "data.frame"))

enter image description here

And unfortunately I don't believe we have access to the original "raw" data anymore that this regression was based on. I've been asked to provide the confidence intervals. Normally I would export these at the time of the regression, but since I don't have access to that anymore, I was looking for another route.

It seems like you MAY be able to calculate confidence intervals from a p-value but I apologize, I wasn't quite clear how I could apply this to the results of this regression.

Is it possible? And if so, could someone help me do it?

$\endgroup$
2
  • 2
    $\begingroup$ Assuming that Esimate is the regression coefficient on the log scale, the first odds ratio seems wrong because $\exp(1.730)\neq 3.00$ but $5.64$. $\endgroup$ Mar 30, 2022 at 15:03
  • $\begingroup$ I will look into that, thank you $\endgroup$ Mar 30, 2022 at 15:08

2 Answers 2

5
$\begingroup$

Yes it's possible. Wald confidence intervals in a logistic regression are calculated on the log-odds scale and then exponentiated to get the confidence interval for the corresponding odds ratio. The $p$-value is based on the test statistic $z = \frac{\hat{\beta}}{\operatorname{SE}_{\hat{\beta}}}$, which is the estimate on the log-odds scale divided by its standard error. The (two-sided) $p$-value is then calculated based on the test statistic $z$ as $p=2\Phi(-|z|)$, where $\Phi$ denotes the cdf of the standard normal distribution. In order to calculate the confidence interval, we need the standard error. Solving for the standard error, we have: $$ \operatorname{SE} = -\frac{|\hat{\beta}|}{\Phi^{-1}(p/2)} $$ where $\Phi^{-1}$ is the quantile function of the standard normal distribution. To calculate the confidence interval on the log-odds scale, we then use: $$ \hat{\beta} \pm z_{1-\alpha/2}\times \operatorname{SE}_{\hat{\beta}} $$ where $z_{1-\alpha/2}$ is a quantile of the standard distribution, e.g. $1.96$ for $\alpha = 0.05$ for a 95% confidence interval on the log-odds scale. Exponentiate the limits to get the confidence interval for the odds ratio.

Let's apply it to the estimate for variable D. Applying the formula, we recover the approximate standard error as $$ \operatorname{SE} = -\frac{|-0.040|}{-1.669593} = 0.024 $$ Hence, an approximate 95% confidence interval for the odds ratio is: $$ \operatorname{exp}(-0.040 \pm 1.96\times 0.024) $$ which evaluates to $(0.917, 1.010)$.

In R, you could do:

library(tidyverse)

df <- df %>%
  mutate(
    z = qnorm(`p-value`/2)
    , se = -abs(Estimate)/z
    , ci_lwr = exp(Estimate - qnorm(0.975)*se)
    , ci_upr = exp(Estimate + qnorm(0.975)*se)
  )
```
$\endgroup$
5
$\begingroup$

The method in your link for example suggests back-calculating starting with:

$z = -0.862 + \sqrt{0.743 - 2.404\log(p)}$

which looks to me like an approximation to using

$z = -\Phi^{-1}(p/2)$

which in turn suggests that they assume the $p$-values came from a two-tailed normal distribution. That seems to be a strong assumption, especially if sample sizes are small. The actual method to derive the $p$-values may have been different.

If you are willing to do this, then for example with variable A using $p=0.049$, you get $z\approx 1.9652$ using their formula or $\approx 1.9686$ using the normal inverse CDF

With the log-odds estimate for A being $1.730$, that suggests a standard error of about $\left|\frac{1.730}{1.9686}\right| \approx 0.8788$

If you want a $95\%$ confidence interval then they suggest multiplying this by $1.96$ to give about $1.72$ and thus your confidence interval for the log-odds estimate would be about $[1.73-1.72,1.73+1.72]$ i.e. $[0.01,3.45]$ (watch out for over precession here). This would make your odds-ratio confidence interval about $[e^{0.01},e^{3.45}]$ i.e. about $[1.01, 32]$

You could use some R code to automate this:

confidence <- 0.95
z <- -qnorm(df$"p-value"/2) # or use  z = -0.862 + sqrt(0.743 - 2.404*log(p))
se <- abs(df$Estimate / z)  
df$lowerCI <- df$Estimate - se * qnorm(1/2 + confidence/2)
df$upperCI <- df$Estimate + se * qnorm(1/2 + confidence/2)
df$ORlowerCI <- exp(df$lowerCI)
df$ORupperCI <- exp(df$upperCI) 

and get

> df
# A tibble: 6 x 8
  `Predictors of ~ Estimate    OR `p-value`  lowerCI upperCI ORlowerCI ORupperCI
  <chr>               <dbl> <dbl>     <dbl>    <dbl>   <dbl>     <dbl>     <dbl>
1 Variable A          1.73   3        0.049  0.00758 3.45        1.01      31.6 
2 Variable B          1.18   3.26     0.043  0.0372  2.32        1.04      10.2 
3 Variable C          1.59   4.88     0.025  0.200   2.98        1.22      19.7 
4 Variable D         -0.04   0.98     0.095 -0.0870  0.00696     0.917      1.01
5 Variable E          0.16   1.01     0.763 -0.880   1.20        0.415      3.32
6 Variable F         -0.003  1        0.172 -0.00731 0.00131     0.993      1.00
$\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.