[R-sig-Geo] Poisson regression spatial residual plot

Virgilio Gómez-Rubio virgilio.gomez at uclm.es
Tue Jan 8 20:42:05 CET 2013


Dear Milan, 

El mar, 08-01-2013 a las 06:48 -0800, Milan Sharma escribió:
> 
> Dear list,
> I wanted to plot residuals from poisson regression model (like the figure 10.5 of Applied spatial data analysis with R, Bivand et. al.).
> My data has response,Tcrash, and the covariates,
> 100MVMT, Alcohol PVMT Alignment 
> and longitude and latitude.
> I used their code, but what "TCE" represents in my case, I am unable to figure out.

TCE refers to a number of sites and they are just another layer on the
plot but has nothing to do on the GLM.

> I will paste a small portion of data and code here, if that helps.
> Please, help me, if possible.
> wi<-map("county", "wisconsin", fill=TRUE, plot=FALSE)
> county.names<-as.character(wi$names)
> wi.sp<-map2SpatialPolygons(wi, IDs=county.names, proj4string=CRS("+proj=longlat"))
> WI_queen<-poly2nb(wi.sp, queen=TRUE)
> WI_queenb<-nb2listw(WI_queen, style="B")
> summary(WI_queenb)
> WI_queenw<-nb2listw(WI_queen, style="W")
> County population Tcrash 100MVMT Alcohol PVMT Alignment Longitude Latitude 
> adams 18643 225 225.6 0.093333 0.288889 0.155556 -89.792 43.95184 
> ashland 16866 187 174.3 0.058824 0.368984 0.235294 -90.7791 46.46137 
> barron 44963 379 495.5 0.055409 0.358839 0.248021 -91.821 45.43696 


The R code in lat2.R (available from www.asdar-book.org) that need to
look at are:

#Fit GLM
nyGLMp <- glm(Cases~PEXPOSURE+PCTAGE65P+PCTOWNHOME+offset(log(POP8)),
data=NY8, family="poisson")

#Get residuals
NY8$lmpresid <- residuals(nyGLMp, type="deviance")

#Display residuals; REMOVE sp.layout=list(TCEpts)
spplot(NY8, "lmpresid", sp.layout=list(TCEpts),
col.regions=grey.colors(9, 0.95, 0.55, 2.2), at=seq(-3,5,length.out=9))


You will need to change the names of the variables in the model but you
should be able to plot the residuals by customizing these tree lines of
code.

Best,

Virgilio



More information about the R-sig-Geo mailing list