### R code from vignette source 'fastLISA.Rnw'

###################################################
### code chunk number 1: weights
###################################################
library(spdep)
library(fastLISA)

nb <- cell2nb(7, 7)            # 49 cells on a 7 x 7 grid
lw <- nb2listw(nb, style = "W")
x  <- as.numeric(seq_len(49))  # a simple gradient
y  <- rev(x)


###################################################
### code chunk number 2: moran
###################################################
res <- local_moran(x, lw, nsim = 199L, iseed = 1L, n.cores = 1L)
head(res)


###################################################
### code chunk number 3: moran-attr
###################################################
table(attr(res, "cluster"))


###################################################
### code chunk number 4: moran-bv-eb
###################################################
bv <- local_moran_bv(x, y, lw, nsim = 199L, iseed = 1L, n.cores = 1L)
head(bv)

event <- as.numeric(seq_len(49))
base  <- rep(100, 49)
eb <- local_moran_eb(event, base, lw, nsim = 199L, iseed = 1L, n.cores = 1L)
head(eb)


###################################################
### code chunk number 5: geary
###################################################
c_uni <- local_geary(x, lw, nsim = 199L, iseed = 1L, n.cores = 1L)
head(c_uni)

c_multi <- local_multigeary(cbind(x, y), lw, nsim = 199L, iseed = 1L, n.cores = 1L)
head(c_multi)


###################################################
### code chunk number 6: getis
###################################################
g  <- local_g(x, lw, nsim = 199L, iseed = 1L, n.cores = 1L)
gs <- local_gstar(x, lw, nsim = 199L, iseed = 1L, n.cores = 1L)
head(g)
head(gs)
