1

I´m trying to visualize a glm model with a binomial response variable, I want to put a line in the plots, but neither lines or abline work and I don´t know why when I have significant responses according to the model I used. Any idea why plotting a line does not work?

> summary(model2)

Call:
glm(formula = Lövförekomst ~ Areal + Si, family = binomial)

Deviance Residuals: 
   Min      1Q  Median      3Q     Max  
-1.254  -1.048  -1.012   1.309   1.422  

Coefficients:
              Estimate Std. Error z value Pr(>|z|)   
(Intercept) -0.2158411  0.0634165  -3.404 0.000665 ***
Areal        0.0009178  0.0002495   3.678 0.000235 ***
Si          -0.0117521  0.0038870  -3.023 0.002499 ** 
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 16662  on 12237  degrees of freedom
Residual deviance: 16642  on 12235  degrees of freedom
  (33 observations deleted due to missingness)
AIC: 16648
Number of Fisher Scoring iterations: 4

> mod <- glm(Lövförekomst~Areal, binomial)
> med <- glm(Lövförekomst~Si,    binomial)
> x   <- seq(0,9,0.01)
> y   <- predict(mod, list(Areal=x), type="response")
> par(mfrow=c(1,2))
> plot(Areal, Lövförekomst)
> x2 <- seq(0,9,0.01)
> y2 <- predict(med, list(Si=x), type="response")
> plot(Si, Lövförekomst)
> lines(x,  y)
> lines(x2, y2)
kjetil b halvorsen
  • 63,378
  • 26
  • 142
  • 467
user40116
  • 501
  • 1
  • 5
  • 4
  • 1
    What does "does not work" mean? Is there an error message? Or is the result only unexpected? Without data your example is not reproducible and we can't see what you see. – Roland Feb 13 '14 at 16:34
  • This question appears to be *only* about how to get `R` to do this, & not about any of the underlying statistical or data visualization issues. As such, it would be off-topic for CV (see our [help center](http://stats.stackexchange.com/help/on-topic)). It could be on-topic on [Stack Overflow](http://stackoverflow.com/), but will need some sample data to make a proper [reproducible example](http://stackoverflow.com/q/5963269/). Can you provide that? If you have a substantive question about the stats / vis. issues, please edit to clarify, otherwise this Q will need to be closed. – gung - Reinstate Monica Feb 13 '14 at 16:35
  • For an example of how to plot a logistic regression, my answer here: [graphing a probability curve for a logit model with multiple predictors](http://stats.stackexchange.com/questions/31597//31600#31600) may help you, although I use a different strategy than you are. – gung - Reinstate Monica Feb 13 '14 at 16:37
  • 3
    This question appears to be off-topic because it is about how to make a plot in R. – gung - Reinstate Monica Feb 13 '14 at 16:39
  • 2
    @gung I agree, but wish to point out that the problem ultimately is based on a misunderstanding of logistic regression and what its coefficients mean. That puts it on-topic (although I suspect a search of our site will turn up several good answers). – whuber Feb 13 '14 at 20:16

0 Answers0