Learn R Programming

GeoXp (version 1.6.2)

moranplotmap: Moran scatterplot and map

Description

The function moranplotmap() draws a moran plot, used to detect spatial autocorrelation in the variable var. On the x-axis, is represented $x-bar(x)$ and on the y-axis $W(x-bar(x))$, where W is the spatial weight matrix. It also calcultes Moran's I statistic (see nonnormoran) and give a p-value associated to the autocorrelation test (gaussian version and permutation version).

Usage

moranplotmap(sp.obj, name.var, listw.obj, flower=FALSE, locmoran=FALSE, names.arg=c("H.-H.","L.-H.","L.-L.","H.-L."), names.attr=names(sp.obj), criteria=NULL, carte=NULL, identify=FALSE, cex.lab=0.8, pch=16, col="lightblue3", xlab="", ylab="", axes=FALSE, lablong="", lablat="")

Arguments

sp.obj
object of class extending Spatial-class
name.var
a character; attribute name or column number in attribute table
listw.obj
object of class listw
flower
if TRUE, link neighbouring sites
locmoran
if TRUE, print local Moran's I statistic on the Moran plot
names.arg
names of the quadrant of the Moran plot
names.attr
names to use in panel (if different from the names of variable used in sp.obj)
criteria
a vector of boolean of size the number of spatial units, which permit to represent preselected sites with a cross, using the tcltk window
carte
matrix with 2 columns for drawing spatial polygonal contours : x and y coordinates of the vertices of the polygon
identify
if not FALSE, identify plotted objects (currently only working for points plots). Labels for identification are the row.names of the attribute table row.names(as.data.frame(sp.obj)).
cex.lab
character size of label
pch
16 by default, symbol for selected points
col
"lightblue3" by default, color of bars on the histogram
xlab
a title for the graphic x-axis
ylab
a title for the graphic y-axis
axes
a boolean with TRUE for drawing axes on the map
lablong
name of the x-axis that will be printed on the map
lablat
name of the y-axis that will be printed on the map

Value

In the case where user click on save results button, a list is created as a global variable in last.select object. \$obs, a vector of integer, corresponds to the number of spatial units selected just before leaving the Tk window, \$MORAN, a numeric, corresponds to the value of the Moran'I statistic.

Details

For the permutation test, for each drawing the values of the variable var are randomly assigned to the sites. We then calculate Moran'I statistic associated to each drawing and we give the frequency of drawings when Moran'I statistic is lower or equal to the observed Moran'I statistic. Moreover, the function gives the opportunity to link neighbouring sites and gives Local Moran's I statistic. For a site i: $$I_i=(x_i-\bar{x})\sum_{j}W_{ij}(x_j-\bar{x})$$ with j not equal to i.

References

Thibault Laurent, Anne Ruiz-Gazen, Christine Thomas-Agnan (2012), GeoXp: An R Package for Exploratory Spatial Data Analysis. Journal of Statistical Software, 47(2), 1-23.

Roger S.Bivand, Edzer J.Pebesma, Virgilio Gomez-Rubio (2009), Applied Spatial Data Analysis with R, Springer.

Jim Lesage, ``Spatial Econometrics Toolbox'', http://www.spatial-econometrics.com/

See Also

neighbourmap,makeneighborsw,normw,nonormmoran

Examples

Run this code
##
# data baltimore
data(baltimore)

# SpatialPoints
baltimore.sp <- SpatialPoints(cbind(baltimore$X,baltimore$Y))
# SpatialPointsDataFrame
baltimore.spdf<-SpatialPointsDataFrame(baltimore.sp,baltimore)

# Spatial Weight Matrix
W.nb <- knn2nb(knearneigh(baltimore.sp, k=4))
# We choose a row standardized spatial weight matrix :
W.listw <- nb2listw(W.nb,style="W")


# moranplotmap with some options
moranplotmap(baltimore.spdf, "PRICE", W.listw ,
flower=TRUE, locmoran=TRUE,criteria=(baltimore.spdf$AC==1),
identify=TRUE)

# comparison with the moran.test function
moran.test(baltimore.spdf$PRICE,W.listw)
 
##
# data columbus
require("maptools")
example(columbus)

# use of moranplotmap with spatial weight matrix col.gal.nb :
# 1. row-standardized
moranplotmap(columbus,"HOVAL",nb2listw(col.gal.nb,style="W"))

# 2. basic binary
moranplotmap(columbus,"HOVAL",nb2listw(col.gal.nb,style="B"))

# 3. globally standardized
moranplotmap(columbus,"HOVAL",nb2listw(col.gal.nb,style="C"))

Run the code above in your browser using DataLab