0
$\begingroup$

I am trying to replicate the method in section 3a of this paper where, for a logistic regression model, they plot the functional relationship between a continuous variable and the odds for developing the outcome (using a smoothing spline).

enter image description here

I was wondering how do you replicate this from an R glm model, as example:

x <- c( 0,1,2,2,2,3,4,5,5,6,6,6,7,8,10 )
y <- c( 0,0,0,0,0,0,1,0,1,0,1,1,0,1,1 )

m <- glm( y ~ x , family = "binomial" )
summary(m)

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

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-1.6671  -0.5085  -0.3056   0.7814   1.6066  

Coefficients:
            Estimate Std. Error z value Pr(>|z|)  
(Intercept)  -3.7311     1.9556  -1.908   0.0564 .
x             0.6906     0.3611   1.912   0.0559 .
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 20.19  on 14  degrees of freedom
Residual deviance: 13.47  on 13  degrees of freedom
AIC: 17.47

Number of Fisher Scoring iterations: 5

how can I extract the OR for each single value in order to replicate the example? Is the m$effect or what other parameter? I know how to plot predicted values, like this, but this is a different question

$\endgroup$
3
  • 1
    $\begingroup$ From the paper you cite: "functional relationship between time between last ASI therapy and surgery versus the odds for developing hypotension using a smoothing spline" [my emphasis]. The model you fit is linear (on the log-odds scale). The model you fit and the model used to produce the graph are fundamentally different beasts. So the short answer is "you can't". Or rather, the graph you get from the glm is rather uninteresting: It's a horizontal straight line. $\endgroup$
    – Limey
    Commented Jun 6, 2021 at 12:06
  • $\begingroup$ @Limey thank you for your reply. I'm fitting a logistic regression model as they are, otherwise we won't get ORs (that I know how to extract for the variable itself but not for each value as they show in the plot). If they use a linear model, how did they got to a linear model from a logistic one? $\endgroup$
    – cccnrc
    Commented Jun 6, 2021 at 13:02
  • 1
    $\begingroup$ Your logistic model is linear in the predictors (albeit, as I previously said, on the log odds scale). That's why your plot of OR against time post op is a straight line. Their logistic model is a spline, which is why their graph is a curve. If this is the main point you would like to discuss, I suggest migrating to StackExchange, as it is more of a stats question than a programming question. $\endgroup$
    – Limey
    Commented Jun 6, 2021 at 13:23

0

Your Answer

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

Browse other questions tagged or ask your own question.