[R] plot for binomial glm

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Mon Oct 29 17:16:01 CET 2007


Tom,

Allow me to give a few comments.

x  <-  c(x=(rep(33:55,1)))
#Is a very uggly way to write
x <- 33:55

#This (untested) code will probably generate a smooth plot too. Maybe
it's not the plot that you intended to create. I'm just guessing as I
can not reproduce your code (because I don't have het dataframe 'data')

newdata <- data.frame(temp = seq(33, 55, length = 101))
predicted <- cbind(newdta, predict(glm.mort, type='response', newdata =
newdata))
plot(fit ~ newdata, type = "l")


HTH,

Thierry

------------------------------------------------------------------------
----
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium 
tel. + 32 54/436 185
Thierry.Onkelinx op inbo.be 
www.inbo.be 

Do not put your faith in what statistics say until you have carefully
considered what they do not say.  ~William W. Watt
A statistical analysis, properly conducted, is a delicate dissection of
uncertainties, a surgery of suppositions. ~M.J.Moroney

-----Oorspronkelijk bericht-----
Van: r-help-bounces op r-project.org [mailto:r-help-bounces op r-project.org]
Namens Tom Willems
Verzonden: maandag 29 oktober 2007 16:51
Aan: r-help op r-project.org
Onderwerp: Re: [R] plot for binomial glm

Dear Jonh,
there is probably an easier way, but i find this to give nice smooth
plots.
 good luck with it.

### R-file

alive <- data$num - data$numdead
numdead <- data$numdead
temp <- data$temp

data.table <- cbind(numdead, alive)
points.graph <-   data$alive/data$num

glm.mort<-glm(data.table ~ temp, family=binomial)

 fit <- predict(glm.mort, type='response' )


a <- glm.mort$coef[1]    # writes model parameters to named variable,
you 
can also use them directly in a function, as you like b <-
glm.mort$coef[2]

          x2 <- c((logit(fit)-(a))/b)
         p2 <- c ((inv.logit(a+b*x2)) )
         y2 <- c ( a+b*x2)


plot(c(30,55), c(0,1),type="n", main= "survival",xlab = "Log x", ylab =
"Probability")
  lines( sortedXyData( (logit(p2)-(a))/b,p2),type="l",lty=1
,col="blue",ylim=c(0,1.2) )
  points(temp,fit,pch=4,type= "p",col="black")

## This will plot a smooth cuve

x  <-  c(x=(rep(33:55,1)))
p <- c ((inv.logit(a+b*x)) )
y  <-  c ( a+b*x)

plot(c(30,55), c(0,1),type="n", main= "survival",xlab = "Log x", ylab =
"Probability")
  lines( sortedXyData( (logit(p)-(a))/b,p),type="l",lty=1
,col="blue",ylim=c(0,1.2) )
  points(temp,fit,pch=4,type= "p",col="black")

### END 



Willems Tom

E-mail: towil op var.fgov.be




Disclaimer: click here
	[[alternative HTML version deleted]]

______________________________________________
R-help op r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list