spatial_ac: Compute Local Spatial Autocorrelation

Description Usage Arguments Details Value Examples

View source: R/spatial_ac.R

Description

Sites don't need to be gridded or random; defines neighbors and calculates local spatial autocorrelation as Moran's I

Usage

1
spatial_ac(lon, lat, value)

Arguments

lon

longitude

lat

latitude

value

value of interest for which to calculate AC

Details

The neighborhood is defined in a 2-step process. First, the nearest neighbor for each location is found, and the maximum distance among nearest neighbors recorded. Second, the neighborhood for a focal point is then defined as all points within that distance. So it's defined as all points within a raidus with a size that is the minimum distance required for all points to have at least 1 neighbor.

Local Moran's I is calculated for each site. P value is adjusted to number of sites in each "region" (not the same 'region' used in the trawlDiversity package); see spdep::localmoran.

Value

A named list of length 3. The first element of this list, max2NDist is the minimum distance and is a length 1 numeric vector. The second element, nb is the neighborhood object returned by spdep::knn2nb. The third element, I, is a data.table that contains columns as returned by spdep::localmoran with a few adjustments: the column for the pvalue is changed to lI_pvalue and columns for lon and lat of the sites are added.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# calculate local I on random subset of volcano
data(volcano)
lon <- rep(seq_len(ncol(volcano)), each=nrow(volcano))
lat <- rep(seq_len(nrow(volcano)), ncol(volcano))
rind <- sample(seq_along(lon), 100) # random subset
value <- c(volcano)
spac <- spatial_ac(lon[rind], lat[rind], value[rind])

# plot neighborhood
plot(spac[["nb"]], cbind(lon[rind], lat[rind]))

# plot significant I's
sig_ind <- spac[["I"]][,lI_pvalue] < 0.05
plot(spac[["nb"]], cbind(lon[rind], lat[rind]))
spac[["I"]][sig_ind, points(lon, lat, col=rbLib::zCol(256, Ii), pch=19)]
rbLib::mapLegend(zlim=spac[["I"]][sig_ind,range(Ii)], cols=rbLib::zCol(6, 1:6))

rBatt/trawlDiversity documentation built on Aug. 14, 2021, 1:01 p.m.