[R] glm help

Joaquín Aldabe joaquin.aldabe at gmail.com
Wed Aug 19 17:54:10 CEST 2015


Dear All, I´m running a glm with poisson errors and have a doubt when
ploting the predicted values. One of my variables has a positive slope in
the summary output, but when I plot the predicted values on the original
plot it draws a line with negative slope. I appreciate your comments on
this and any other aspect of the analysis.

Attached is the script and data in different formats just in case.

Thanks in advanced,

Joaquín.


-- 
*Joaquín Aldabe*

*Grupo Biodiversidad, Ambiente y Sociedad*
Centro Universitario de la Región Este, Universidad de la República
Ruta 15 (y Ruta 9), Km 28.500, Departamento de Rocha

*Departamento de Conservación*
Aves Uruguay
BirdLife International
Canelones 1164, Montevideo

https://sites.google.com/site/joaquin.aldabe
<https://sites.google.com/site/perfilprofesionaljoaquinaldabe>
-------------- next part --------------
my4<-read.table(file.choose(), header=T, dec=",")
my4s<-as.data.frame(scale(my4[,c(6,10,12,13,16)], center=T, scale=T))
my4S<-cbind(BBSA=my4$BBSA, Field_name=my4$Field_name,Grassland_type=my4$Grassland_type, Flood=my4$Flood, Year=my4$Year,my4s)

m2.glm=glm(BBSA~AMGP+Distance_to_lagoon+Grass_height, family="quasipoisson", data=my4S
summary(m2.glm)
#residuales
par(mfrow=c(2,2))
plot(m2.glm)#pretty good

#predict
amgp=seq(-0.51, 5.44, length.out=100)
grass=seq(-0.85,2.83, length.out=100)
dist=seq(-1.59,1.53, length.out=100)
newdata=data.frame(AMGP=amgp, Distance_to_lagoon=dist,Grass_height=grass)
pred.m2.glm=exp(predict(m2.glm,newdata))
plot(BBSA~Grass_height, data=my4S)
lines(newdata$Grass_height,pred.m2.glm)
plot(BBSA~AMGP, data=my4S)
lines(newdata$AMGP,pred.m2.glm)#why negative slope if summary output is positive
plot(BBSA~Distance_to_lagoon, data=my4S)
lines(newdata$Distance_to_lagoon, pred.m2.glm)


More information about the R-help mailing list