lmoranmap: Quick visualization and analysis of areal data

Description Usage Arguments Details Examples

View source: R/lmoranmap.R

Description

Creates a complete visualization and spatial autocorrelation analysis with Moran's I for areal data.

Usage

1
lmoranmap(shapefile, adata, sign = 0.05, knearest = FALSE, k = 3)

Arguments

shapefile

A shapefile of the study region.

adata

A vector with the data for each area unit.

sign

The significance level for the Local Moran's I

knearest

Logical argument to create the neighborhood using the k nearest neighbors.

k

The number of neighbors used when knearest = TRUE. The default is 3.

nb.obj

A neighborhood object.

Details

This function utilizes ggplot2 and spdep to create a complete visualization and spatial autocorrelation analysis for areal data.

The lenght of the areal data vector must be the same as the number of polygons in the shapefile. The data will be merged into it using the tidy function from the broom package so the maps can be created with ggplot2. All the steps in this transformation are made automatically by the function.

A neighborhood must be created for the spatial analysis, the default method utilizes the spdep's poly2nb function which considers area units that share borders as neighbors. Since this can be a problem when the shapefile contains islands there is a option to create the neighbors with spdep's knearneigh function, which considers the k-nearest polygons as neighbors.

The function returns four maps: One for the areal data, one with Local Moran's I results, one with Local Moran's significant p-values (where the significance can be changed via the sign argument) and one with the neighborhood.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Loading the example data and the included shapefile

dengue.data = dengue
rio = rioshapefile

# The example data contains dengue counts between 2009 and 2013 for
# the Rio de Janeiro State. We can run the spatial analysis for each
# of these years.

dengue2010 = lmoranmap(shapefile = rio, adata = dengue.data$`2010`)

# This will generate a grid containing a cloropleth map for the
# dengue counts, a map with the results from Local Moran's I, a
# map indicating which regions had significant results on the
# Local Moran's I and a map with the categories utilized on
# spdep's moran.plot function.

# The significance level used here can be changed via the sign
# parameter on the function.

# The neighborhood for the areal data is created by spdep's
# poly2nb function by default. Since this kind of neighborhood
# can be problematic for regions that are not contiguous as a
# whole it's also possible to create the neighborhood via the
# knearneigh function.

dengue2010 = lmoranmap(shapefile = rio, adata = dengue.data$`2010`, knearest = TRUE, k = 3)

# By default it counts the 3 nearest polygons as neighbors, but
# this can be easily changed via the k parameter on the function.

qspatialR/qspatial documentation built on April 30, 2020, 6:55 a.m.