An embedded and charset-unspecified text was scrubbed... Name: [??dn? popis nen? k dispozici] Url: https://stat.ethz.ch/pipermail/r-help/attachments/20071028/8e02ff9e/attachment.pl
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 JohnHow 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
Radek John wrote:> > Hello everybody! > I am trying to plot glm with family=binomial and can`t work it out. My > Data > are: > >mort = data.frame(temp=c(32,32,32,37,37,37,42,42,42,47,47,47,52,52,52), num = c( 7,8,8,15,15,17,11,28,15,10,12,13,18,19,22), numdead = c(0,0,0,3,1,3,8,14,12,10,12,13,18,19,22)) glm.mort<-glm(cbind(numdead, num - numdead) ~ temp, family=binomial, data=mort) with(mort,plot(numdead/num~temp)) ## plot with larger points for repeated values library(plotrix) with(mort,sizeplot(temp,numdead/num, xlab="temp",ylab="prop. dead")) tempvec= seq(min(mort$temp),max(mort$temp),length.out=100) pred = predict(glm.mort,"response",newdata=data.frame(temp=tempvec)) lines(tempvec,pred) -- View this message in context: http://www.nabble.com/plot-for-binomial-glm-tf4706812.html#a13453632 Sent from the R help mailing list archive at Nabble.com.