Learn R Programming

spdep (version 1.1-7)

moran: Compute Moran's I

Description

A simple function to compute Moran's I, called by moran.test and moran.mc; $$I = \frac{n}{\sum_{i=1}^{n}\sum_{j=1}^{n}w_{ij}} \frac{\sum_{i=1}^{n}\sum_{j=1}^{n}w_{ij}(x_i-\bar{x})(x_j-\bar{x})}{\sum_{i=1}^{n}(x_i - \bar{x})^2} $$

Usage

moran(x, listw, n, S0, zero.policy=NULL, NAOK=FALSE)

Arguments

x

a numeric vector the same length as the neighbours list in listw

listw

a listw object created for example by nb2listw

n

number of zones

S0

global sum of weights

zero.policy

default NULL, use global option value; if TRUE assign zero to the lagged value of zones without neighbours, if FALSE assign NA

NAOK

if 'TRUE' then any 'NA' or 'NaN' or 'Inf' values in x are passed on to the foreign function. If 'FALSE', the presence of 'NA' or 'NaN' or 'Inf' values is regarded as an error.

Value

a list of

I

Moran's I

K

sample kurtosis of x

References

Cliff, A. D., Ord, J. K. 1981 Spatial processes, Pion, p. 17.

See Also

moran.test, moran.mc

Examples

Run this code
# NOT RUN {
data(oldcol)
col.W <- nb2listw(COL.nb, style="W")
crime <- COL.OLD$CRIME
str(moran(crime, col.W, length(COL.nb), Szero(col.W)))
is.na(crime) <- sample(1:length(crime), 10)
str(moran(crime, col.W, length(COL.nb), Szero(col.W), NAOK=TRUE))
# }

Run the code above in your browser using DataLab