The Moran eigenvector filtering function is intended to remove spatial autocorrelation from the residuals of generalised linear models. It uses brute force eigenvector selection to reach a subset of such vectors to be added to the RHS of the GLM model to reduce residual autocorrelation to below the specified alpha value. Since eigenvector selection only works on symmetric weights, the weights are made symmetric before the eigenvectors are found (from spdep 0.5-50).

ME(formula, data=list(), family = gaussian, weights, offset,,listw=NULL, alpha=0.05, nsim=99, verbose=NULL,
 stdev=FALSE, zero.policy=NULL)



a symbolic description of the model to be fit


an optional data frame containing the variables in the model


a description of the error distribution and link function to be used in the model


an optional vector of weights to be used in the fitting process


this can be used to specify an a priori known component to be included in the linear predictor during fitting


a function (default options("na.action")), can also be na.omit or na.exclude with consequences for residuals and fitted values - in these cases the spatial weights list will be subsetted to remove NAs in the data. It may be necessary to set zero.policy to TRUE because this subsetting may create no-neighbour observations. Note that only weights lists created without using the glist argument to nb2listw may be subsetted.


a listw object created for example by nb2listw


used as a stopping rule to choose all eigenvectors up to and including the one with a p-value exceeding alpha


number of permutations for permutation bootstrap for finding p-values


default NULL, use global option value; if TRUE report eigenvectors selected


if TRUE, p-value calculated from bootstrap permutation standard deviate using pnorm with alternative="greater", if FALSE the Hope-type p-value


default NULL, use global option value; if FALSE stop with error for any empty neighbour sets, if TRUE permit the weights list to be formed with zero-length weights vectors


The eigenvectors for inclusion are chosen by calculating the empirical Moran's I values for the initial model plus each of the doubly centred symmetric spatial weights matrix eigenvectors in turn. Then the first eigenvector is chosen as that with the lowest Moran's I value. The procedure is repeated until the lowest remaining Moran's I value has a permutation-based probability value above alpha. The probability value is either Hope-type or based on using the mean and standard deviation of the permutations to calculate ZI based on the stdev argument.


An object of class Me_res:


a matrix summarising the selection of eigenvectors for inclusion, with columns:


number of selected eigenvector


permutation-based standardized deviate of Moran's I if stdev=TRUE


probability value: if stdev=TRUE of the permutation-based standardized deviate, if FALSE the Hope-type probability value, in both cases on-sided

The first row is the value at the start of the search


a matrix of the selected eigenvectors in order of selection


Dray S, Legendre P and Peres-Neto PR (2005) Spatial modeling: a comprehensive framework for principle coordinate analysis of neigbbor matrices (PCNM), Ecological Modelling; Griffith DA and Peres-Neto PR (2006) Spatial modeling in ecology: the flexibility of eigenfunction spatial analyses.


Roger Bivand and Pedro Peres-Neto

See also


#require("spdep", quietly=TRUE)
data(hopkins, package="spData")
hopkins_part <- hopkins[21:36,36:21]
hopkins_part[which(hopkins_part > 0, arr.ind=TRUE)] <- 1
hopkins.rook.nb <- spdep::cell2nb(16, 16, type="rook")
glmbase <- glm(c(hopkins_part) ~ 1, family="binomial")
lw <- spdep::nb2listw(hopkins.rook.nb, style="B")
system.time(MEbinom1 <- ME(c(hopkins_part) ~ 1, family="binomial",
 listw=lw, alpha=0.05, verbose=TRUE, nsim=49))
#> eV[,2], I: 0.07978424 ZI: NA, pr(ZI): 0.04
#> eV[,54], I: 0.05704227 ZI: NA, pr(ZI): 0.12
#>    user  system elapsed 
#>   1.590   0.010   1.606 
glmME <- glm(c(hopkins_part) ~ 1 + fitted(MEbinom1), family="binomial")
#anova(glmME, test="Chisq")
#>                        Estimate Std. Error   z value     Pr(>|z|)
#> (Intercept)           -1.194892  0.1600429 -7.466073 8.262357e-14
#> fitted(MEbinom1)vec2   9.030818  2.5381594  3.558019 3.736629e-04
#> fitted(MEbinom1)vec54 -8.759610  2.5205844 -3.475230 5.104161e-04
anova(glmbase, glmME, test="Chisq")
#> Analysis of Deviance Table
#> Model 1: c(hopkins_part) ~ 1
#> Model 2: c(hopkins_part) ~ 1 + fitted(MEbinom1)
#>   Resid. Df Resid. Dev Df Deviance  Pr(>Chi)    
#> 1       255     292.23                          
#> 2       253     266.27  2   25.956 2.311e-06 ***
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
if (FALSE) {
require("sf", quietly=TRUE)
columbus <- st_read(system.file("shapes/columbus.shp", package="spData")[1], quiet=TRUE)
#require("spdep", quietly=TRUE) <-"weights/", package="spData")[1])
lw <- spdep::nb2listw(
lmbase <- lm(CRIME ~ INC + HOVAL, data=columbus)
lagcol <- SpatialFiltering(CRIME ~ 1, ~ INC + HOVAL, data=columbus,, style="W", alpha=0.1, verbose=TRUE)
lmlag <- lm(CRIME ~ INC + HOVAL + fitted(lagcol), data=columbus)
anova(lmbase, lmlag)
system.time(lagcol1 <- ME(CRIME ~ INC + HOVAL, data=columbus, family="gaussian",
 listw=lw, alpha=0.1, verbose=TRUE))
lmlag1 <- lm(CRIME ~ INC + HOVAL + fitted(lagcol1), data=columbus)
anova(lmbase, lmlag1)

lagcol2 <- ME(CRIME ~ INC + HOVAL, data=columbus, family="gaussian",
 listw=lw, alpha=0.1, stdev=TRUE, verbose=TRUE)
lmlag2 <- lm(CRIME ~ INC + HOVAL + fitted(lagcol2), data=columbus)
anova(lmbase, lmlag2)
NA.columbus <- columbus
NA.columbus$CRIME[20:25] <- NA
COL.ME.NA <- ME(CRIME ~ INC + HOVAL, data=NA.columbus, family="gaussian",
 listw=lw, alpha=0.1, stdev=TRUE, verbose=TRUE,
summary(lm(CRIME ~ INC + HOVAL + fitted(COL.ME.NA), data=NA.columbus,
nc.sids <- st_read(system.file("shapes/sids.shp", package="spData")[1], quiet=TRUE)
rn <- as.character(nc.sids$FIPS)
ncCC89_nb <-"weights/", package="spData")[1],
ncCR85_nb <-"weights/", package="spData")[1],
glmbase <- glm(SID74 ~ 1, data=nc.sids, offset=log(BIR74),
MEpois1 <- ME(SID74 ~ 1, data=nc.sids, offset=log(BIR74),
 family="poisson", listw=spdep::nb2listw(ncCR85_nb, style="B"), alpha=0.2, verbose=TRUE)
glmME <- glm(SID74 ~ 1 + fitted(MEpois1), data=nc.sids, offset=log(BIR74),
anova(glmME, test="Chisq")
anova(glmbase, glmME, test="Chisq")