[R] plot for binomial glm

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Sun Oct 28 14:49:06 CET 2007



Radek John said the following on 10/28/2007 5:53 AM:
>  Hello everybody!
> I am trying to plot glm with family=binomial and can`t work it out. My Data
> are:
>> mort
>    temp num numdead
> 1    32   7       0
> 2    32   8       0
> 3    32   8       0
> 4    37  15       3
> 5    37  15       1
> 6    37  17       3
> 7    42  11       8
> 8    42  28      14
> 9    42  15      12
> 10   47  10      10
> 11   47  12      12
> 12   47  13      13
> 13   52  18      18
> 14   52  19      19
> 15   52  22      22
> I fitted glm
>> glm.mort<-glm(cbind(numdead, num - numdead) ~ temp, family=binomial)
> But now I don`t know, how to plot it. I need a plot with some points for
> variable numdead and some curve for the model. Thanks.
> 
> Radek John

How about:

t1 <- min(mort$temp)
t2 <- max(mort$temp)
mort2 <- data.frame(temp = seq(t1, t2, len = 100))
prd.mort <- predict(glm.mort, mort2, type = "r", se.fit = TRUE)

plot(mort2$temp, prd.mort$fit, type = "l",
      xlab = "Tempature", ylab = "Proportion Dead")
lines(mort2$temp, prd.mort$fit - 1.96 * prd.mort$se.fit, lty = 2)
lines(mort2$temp, prd.mort$fit + 1.96 * prd.mort$se.fit, lty = 2)
points(mort$temp, mort$numdead/mort$num)

See ?predict.glm.

HTH,

--sundar



More information about the R-help mailing list