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

Edzer Pebesma edzer.pebesma at uni-muenster.de
Wed Jan 9 23:34:44 CET 2013



On 01/09/2013 10:07 PM, Milan Sharma wrote:
> Dear all,  
> I want to plot Poisson regression spatial residual plot, all the codes run but there is a small error  at the end in spplot command, which is shown below. Can someone figure out what is wrong?
> ##################################
>> GLMp <- glm(Tcrash~X100MVMT+Alcohol+Alignment+PVMT+offset(log(population)), data=data, family="poisson")
>> summary(GLMp)
> 
> Call:
> glm(formula = Tcrash ~ X100MVMT + Alcohol + Alignment + PVMT + 
> Â Â Â  offset(log(population)), family = "poisson", data = data)
> 
> Deviance Residuals: 
>     Min       1Q   Median       3Q      Max  
> -19.144Â Â  -3.900Â Â  -0.500Â Â Â  2.693Â Â  24.990
>  Â 
> 
> Coefficients:
> Â Â Â Â Â Â Â Â Â Â Â Â Â  Estimate Std. Error z value Pr(>|z|)Â Â  Â 
> (Intercept) -4.456e+00Â  4.740e-02 -94.012Â  < 2e-16 ***
> X100MVMTÂ Â Â  -5.574e-05Â  2.457e-06 -22.688Â  < 2e-16 ***
> Alcohol     -2.378e+00  2.598e-01  -9.153  < 2e-16 ***
> Alignment    2.872e-01  7.207e-02   3.985 6.75e-05 ***
> PVMTÂ Â Â Â Â Â Â Â  7.467e-01Â  1.197e-01Â Â  6.236 4.48e-10 ***
> ---
> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
> 
> (Dispersion parameter for poisson family taken to be 1)
> 
> Â Â Â  Null deviance: 5089.2Â  on 70Â  degrees of freedom
> Residual deviance: 3736.1Â  on 66Â  degrees of freedom
> AIC: 4325.1
> 
> Number of
>  Fisher Scoring iterations: 4
> 
>> lmpresid <- residuals(GLMp, type="deviance")
>> #Display residuals; REMOVE sp.layout=list(TCEpts)
>> spplot(data, "lmpresid",col.regions=grey.colors(9, 0.95, 0.55, 2.2), at=seq(-3,5,length.out=9))
> Error in function (classes, fdef, mtable)Â  : 
> Â  unable to find an inherited method for function "spplot", for signature "data.frame"
>>
> Milan

Milan, your email is unreadable and your script is unreproducible.

the error says that object data (which I don't see created in your
script) is of class data.frame -- spplot needs Spatial* objects to do
something useful.

> 
> 
> 
> 
> ________________________________
>  From: Virgilio Gómez-Rubio <virgilio.gomez at uclm.es>
> 
> Cc: "r-sig-geo at r-project.org" <r-sig-geo at r-project.org> 
> Sent: Tuesday, January 8, 2013 1:42 PM
> Subject: Re: [R-sig-Geo] Poisson regression spatial residual plot
> 
> 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
> 	[[alternative HTML version deleted]]
> 
> 
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 

-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de
http://www.52north.org/geostatistics      e.pebesma at wwu.de



More information about the R-sig-Geo mailing list