[R] Predict Function use with GLM

2015-08-12 Thread trisgutt
I am currently using a GLM with Gaussian family to model fish depth~length +
distance from shore: 

model1 - glm(Depth ~ length + distance from shore,
family=gaussian(link=log))

There are no zero depths. I would like to use the above model with the
predict function in R to generate three lines (with confidence intervals)
for the depth at size for three distances, say 100 m, 500 m and 1000m.
Problem is I am unable to figure out how to do this? 

Any advice / assistance would be gratefully received...

Thank you

Tris




--
View this message in context: 
http://r.789695.n4.nabble.com/Predict-Function-use-with-GLM-tp4711026.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Predict Function use with GLM

2015-08-12 Thread Ben Bolker
trisgutt trisgutt at hotmail.com writes:

 
 I am currently using a GLM with Gaussian family to model fish depth~length +
 distance from shore: 
 
 model1 - glm(Depth ~ length + distance from shore,
 family=gaussian(link=log))
 
 There are no zero depths. I would like to use the above model with the
 predict function in R to generate three lines (with confidence intervals)
 for the depth at size for three distances, say 100 m, 500 m and 1000m.
 Problem is I am unable to figure out how to do this? 
 
 Any advice / assistance would be gratefully received...
 
 Thank you
 
 Tris
 

Something like:

pp - expand.grid(distance=c(100,500,1000),
   length=seq(min_depth,max_depth,length.out=51))
## 51 is arbitrary -- you just need enough points to make the curve
## appear smooth

predvals - predict(model1,newdata=newdata,se.fit=TRUE,type=link)
pp - transform(pp,est=exp(predvals$fit),
lwr=exp(predvals$fit-1.96*predvals$se),
upr=exp(predvals$fit+1.96*predvals$se))

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.