Docsity

Lab 10: Analyzing Spatial Dependence in Areal Data using R, Lab Reports of Statistics

Toggle sidebar
bg1
Lab 10 Stat 5410/6410 October 29, 2008
Areal Data: Spatial Dependence
Load the Necessary R Packages:
> library(maps)
> library(spdep) # 'spdep' requires several packages
Exploring Areal Data: We initially familiarized ourselves with methods for
displaying areal data in Lab #3. For this exercise we will use a built in dataset
that comes with the 'spdep' package.
> data(columbus)
> summary(columbus)
> columbus
Note, these data are Columbus, OH crime data from 1980. This dataset has
the necessary spatial information (e.g., boundary fields, weight/neighbor
fields, coordinates, and covariates) to ultimately carry out a spatial regression
analysis. The information is stored in several data objects, now included in
your R workspace.
One objective may be to explain the amount of crime among Columbus
neighborhoods. This problem has an inherent spatial component, however,
unlike previously considered datasets in this course, the phenomenon under
study in this case has been measured in spatial areas (neighborhood
polygons). Plot the data to get an idea of the spatial structure:
> crime=(columbus$CRIME-min(columbus$CRIME))/
max(columbus$CRIME)
> hoval=(columbus$HOVAL-min(columbus$HOVAL))/
max(columbus$HOVAL)
> inc=(columbus$INC-min(columbus$INC))/
max(columbus$INC)
> plot(polys,forcefill=FALSE,col=gray(1-crime))
> x11()
> plot(polys,forcefill=FALSE,col=gray(1-inc))
> x11()
> plot(polys,forcefill=FALSE,col=gray(1-hoval))
What sort of spatial structure are you able to see in the CRIME variable?
Does there appear to be a relationship between CRIME and the INC, HOVAL
variables?
pf3

Partial preview of the text

Download Lab 10: Analyzing Spatial Dependence in Areal Data using R and more Lab Reports Statistics in PDF only on Docsity!

Lab 10 Stat 5410/6410 October 29, 2008 Areal Data: Spatial DependenceLoad the Necessary R Packages:

library(maps) library(spdep) # 'spdep' requires several packages  Exploring Areal Data : We initially familiarized ourselves with methods for displaying areal data in Lab #3. For this exercise we will use a built in dataset that comes with the 'spdep' package. data(columbus) summary(columbus) columbus Note, these data are Columbus, OH crime data from 1980. This dataset has the necessary spatial information (e.g., boundary fields, weight/neighbor fields, coordinates, and covariates) to ultimately carry out a spatial regression analysis. The information is stored in several data objects, now included in your R workspace. One objective may be to explain the amount of crime among Columbus neighborhoods. This problem has an inherent spatial component, however, unlike previously considered datasets in this course, the phenomenon under study in this case has been measured in spatial areas (neighborhood polygons). Plot the data to get an idea of the spatial structure: crime=(columbus$CRIME-min(columbus$CRIME))/ max(columbus$CRIME) hoval=(columbus$HOVAL-min(columbus$HOVAL))/ max(columbus$HOVAL) inc=(columbus$INC-min(columbus$INC))/ max(columbus$INC) plot(polys,forcefill=FALSE,col=gray(1-crime)) x11() plot(polys,forcefill=FALSE,col=gray(1-inc)) x11() plot(polys,forcefill=FALSE,col=gray(1-hoval)) What sort of spatial structure are you able to see in the CRIME variable? Does there appear to be a relationship between CRIME and the INC, HOVAL variables?

Testing for Spatial Dependence in Areal Data: Perform a Moran's I test for spatial autocorrelation in the CRIME variable (assuming normality):

moran.test(columbus$CRIME,randomisation=FALSE, nb2listw(col.gal.nb, style="W")) The p-value reported in the above test is for the one-sided hypothesis that values occur at random throughout the spatial domain. A low p-value suggests that the CRIME variable exhibits some "clustering" or positive spatial dependence. The 'style' command designates the type of spatial proximity matrix to use. The test employed above is naïve in that it does not take into account possible first order effects on the process (i.e., crime). Now, consider a regression of Columbus crime with covariates (housing value [HOVAL] and household income [INC]): columbus.lm=lm(CRIME ~ INC + HOVAL, data=columbus) summary(columbus.lm) res=resid(columbus.lm) res=(res-min(res))/diff(range(res)) plot(polys,forcefill=FALSE,col=gray(1-res)) If our goal is to model Columbus crime in terms of the covariates using OLS, then an assumption of independent residuals must be warranted. Does the map of residuals indicate spatial dependence (and thus suggest non- independent errors)? One way to formally test for independence in the residuals from such a regression model is to use the Moran's I test for residuals (note, this statistic is formulated differently than the test statistic used for crime itself): lm.morantest(columbus.lm,nb2listw(col.gal.nb, style="W")) Note that the p-value (which suggests we can reject the hypothesis of independence in the residuals) indicates less spatial dependence in the residuals than in the response variable (by comparing with the earlier Moran's I p-value). There are additional options that allow for tests based on simulations which account for sensitivity to neighbor relationships. Also note that the Geary C statistic can be calculated and used to test for spatial dependence (though not available for use with the 'lm()' object): geary.test(columbus$CRIME,nb2listw(col.gal.nb, style="W"))