ME: Moran eigenvector GLM filtering

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/ME.R

Description

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).

Usage

1
2
ME(formula, data, family = gaussian, weights, offset, listw,
 alpha=0.05, nsim=99, verbose=NULL, stdev=FALSE)

Arguments

formula

a symbolic description of the model to be fit

data

an optional data frame containing the variables in the model

family

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

weights

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

offset

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

listw

a listw object created for example by nb2listw

alpha

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

nsim

number of permutations for permutation bootstrap for finding p-values

verbose

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

stdev

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

Details

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.

Value

An object of class ME_res:

selection

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

Eigenvector

number of selected eigenvector

ZI

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

pr(ZI)

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

vectors

a matrix of the selected eigenvectors in order of selection

Author(s)

Roger Bivand and Pedro Peres-Neto

References

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.

See Also

SpatialFiltering, glm

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
## Not run: 
example(columbus)
lmbase <- lm(CRIME ~ INC + HOVAL, data=columbus)
lagcol <- SpatialFiltering(CRIME ~ 1, ~ INC + HOVAL, data=columbus,
 nb=col.gal.nb, style="W", alpha=0.1, verbose=TRUE)
lagcol
lmlag <- lm(CRIME ~ INC + HOVAL + fitted(lagcol), data=columbus)
anova(lmlag)
anova(lmbase, lmlag)
set.seed(123)
lagcol1 <- ME(CRIME ~ INC + HOVAL, data=columbus, family="gaussian",
 listw=nb2listw(col.gal.nb), alpha=0.1, verbose=TRUE)
lagcol1
lmlag1 <- lm(CRIME ~ INC + HOVAL + fitted(lagcol1), data=columbus)
anova(lmlag1)
anova(lmbase, lmlag1)
set.seed(123)
lagcol2 <- ME(CRIME ~ INC + HOVAL, data=columbus, family="gaussian",
 listw=nb2listw(col.gal.nb), alpha=0.1, stdev=TRUE, verbose=TRUE)
lagcol2
lmlag2 <- lm(CRIME ~ INC + HOVAL + fitted(lagcol2), data=columbus)
anova(lmlag2)
anova(lmbase, lmlag2)
example(nc.sids)
glmbase <- glm(SID74 ~ 1, data=nc.sids, offset=log(BIR74),
 family="poisson")
set.seed(123)
MEpois1 <- ME(SID74 ~ 1, data=nc.sids, offset=log(BIR74),
 family="poisson", listw=nb2listw(ncCR85_nb, style="B"), alpha=0.2, verbose=TRUE)
MEpois1
glmME <- glm(SID74 ~ 1 + fitted(MEpois1), data=nc.sids, offset=log(BIR74),
 family="poisson")
anova(glmME, test="Chisq")
anova(glmbase, glmME, test="Chisq")
data(hopkins)
hopkins_part <- hopkins[21:36,36:21]
hopkins_part[which(hopkins_part > 0, arr.ind=TRUE)] <- 1
hopkins.rook.nb <- cell2nb(16, 16, type="rook")
glmbase <- glm(c(hopkins_part) ~ 1, family="binomial")
set.seed(123)
MEbinom1 <- ME(c(hopkins_part) ~ 1, family="binomial",
 listw=nb2listw(hopkins.rook.nb, style="B"), alpha=0.2, verbose=TRUE)
glmME <- glm(c(hopkins_part) ~ 1 + fitted(MEbinom1), family="binomial")
anova(glmME, test="Chisq")
anova(glmbase, glmME, test="Chisq")

## End(Not run)

Example output

Loading required package: sp
Loading required package: Matrix

colmbs> require(maptools)
Loading required package: maptools
Checking rgeos availability: TRUE

colmbs> columbus <- readShapePoly(system.file("etc/shapes/columbus.shp",
colmbs+  package="spdep")[1])

colmbs> col.gal.nb <- read.gal(system.file("etc/weights/columbus.gal",
colmbs+  package="spdep")[1])
Warning message:
use rgdal::readOGR or sf::st_read 
Step 0 SelEvec 0 MinMi 0.2123742 ZMinMi 2.681 Pr(ZI) 0.007340246 
Step 1 SelEvec 6 MinMi 0.1178225 ZMinMi 1.84512 Pr(ZI) 0.06502014 
Step 2 SelEvec 4 MinMi 0.06242664 ZMinMi 1.494821 Pr(ZI) 0.1349611 
  Step SelEvec      Eval      MinMi   ZMinMi      Pr(ZI)        R2    gamma
0    0       0 0.0000000 0.21237415 2.681000 0.007340246 0.5524040  0.00000
1    1       6 0.7161123 0.11782248 1.845120 0.065020139 0.6038801 25.46181
2    2       4 0.8682938 0.06242664 1.494821 0.134961136 0.6531288 26.68319
Analysis of Variance Table

Response: CRIME
               Df Sum Sq Mean Sq F value    Pr(>F)    
INC             1 6502.0  6502.0 61.3749 6.988e-10 ***
HOVAL           1  921.3   921.3  8.6966  0.005089 ** 
fitted(lagcol)  2 1353.6   676.8  6.3884  0.003666 ** 
Residuals      44 4661.3   105.9                      
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Analysis of Variance Table

Model 1: CRIME ~ INC + HOVAL
Model 2: CRIME ~ INC + HOVAL + fitted(lagcol)
  Res.Df    RSS Df Sum of Sq      F   Pr(>F)   
1     46 6014.9                                
2     44 4661.3  2    1353.6 6.3884 0.003666 **
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
eV[,6], I: 0.1178225 ZI: NA, pr(ZI): 0.07
eV[,4], I: 0.06242664 ZI: NA, pr(ZI): 0.19
  Eigenvector ZI pr(ZI)
0          NA NA   0.04
1           6 NA   0.07
2           4 NA   0.19
Analysis of Variance Table

Response: CRIME
                Df Sum Sq Mean Sq F value    Pr(>F)    
INC              1 6502.0  6502.0 61.3749 6.988e-10 ***
HOVAL            1  921.3   921.3  8.6966  0.005089 ** 
fitted(lagcol1)  2 1353.6   676.8  6.3884  0.003666 ** 
Residuals       44 4661.3   105.9                      
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Analysis of Variance Table

Model 1: CRIME ~ INC + HOVAL
Model 2: CRIME ~ INC + HOVAL + fitted(lagcol1)
  Res.Df    RSS Df Sum of Sq      F   Pr(>F)   
1     46 6014.9                                
2     44 4661.3  2    1353.6 6.3884 0.003666 **
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
eV[,6], I: 0.1178225 ZI: 1.672528, pr(ZI): 0.0472101
eV[,4], I: 0.06242664 ZI: 0.9968862, pr(ZI): 0.1594099
  Eigenvector        ZI     pr(ZI)
0          NA 2.3241331 0.01005918
1           6 1.6725283 0.04721010
2           4 0.9968862 0.15940988
Analysis of Variance Table

Response: CRIME
                Df Sum Sq Mean Sq F value    Pr(>F)    
INC              1 6502.0  6502.0 61.3749 6.988e-10 ***
HOVAL            1  921.3   921.3  8.6966  0.005089 ** 
fitted(lagcol2)  2 1353.6   676.8  6.3884  0.003666 ** 
Residuals       44 4661.3   105.9                      
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Analysis of Variance Table

Model 1: CRIME ~ INC + HOVAL
Model 2: CRIME ~ INC + HOVAL + fitted(lagcol2)
  Res.Df    RSS Df Sum of Sq      F   Pr(>F)   
1     46 6014.9                                
2     44 4661.3  2    1353.6 6.3884 0.003666 **
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

nc.sds> require(maptools)

nc.sds> nc.sids <- readShapePoly(system.file("etc/shapes/sids.shp", package="spdep")[1],
nc.sds+   ID="FIPSNO", proj4string=CRS("+proj=longlat +ellps=clrk66"))
NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files

nc.sds> rn <- sapply(slot(nc.sids, "polygons"), function(x) slot(x, "ID"))

nc.sds> ncCC89_nb <- read.gal(system.file("etc/weights/ncCC89.gal", package="spdep")[1],
nc.sds+   region.id=rn)

nc.sds> ncCR85_nb <- read.gal(system.file("etc/weights/ncCR85.gal", package="spdep")[1],
nc.sds+   region.id=rn)

nc.sds> ## Not run: 
nc.sds> ##D plot(nc.sids, border="grey")
nc.sds> ##D plot(ncCR85_nb, coordinates(nc.sids), add=TRUE, col="blue")
nc.sds> ##D plot(nc.sids, border="grey")
nc.sds> ##D plot(ncCC89_nb, coordinates(nc.sids), add=TRUE, col="blue")
nc.sds> ## End(Not run)
nc.sds> 
nc.sds> 
nc.sds> 
Warning message:
use rgdal::readOGR or sf::st_read 
eV[,1], I: 0.1327384 ZI: NA, pr(ZI): 0.01
eV[,8], I: 0.06936385 ZI: NA, pr(ZI): 0.11
eV[,4], I: 0.03584503 ZI: NA, pr(ZI): 0.27
  Eigenvector ZI pr(ZI)
0          NA NA   0.01
1           1 NA   0.01
2           8 NA   0.11
3           4 NA   0.27
Analysis of Deviance Table

Model: poisson, link: log

Response: SID74

Terms added sequentially (first to last)


                Df Deviance Resid. Df Resid. Dev  Pr(>Chi)    
NULL                               99     203.34              
fitted(MEpois1)  3   32.499        96     170.84 4.108e-07 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Analysis of Deviance Table

Model 1: SID74 ~ 1
Model 2: SID74 ~ 1 + fitted(MEpois1)
  Resid. Df Resid. Dev Df Deviance  Pr(>Chi)    
1        99     203.34                          
2        96     170.84  3   32.499 4.108e-07 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
eV[,2], I: 0.08451491 ZI: NA, pr(ZI): 0.03
eV[,8], I: 0.06530444 ZI: NA, pr(ZI): 0.06
eV[,55], I: 0.04982992 ZI: NA, pr(ZI): 0.11
eV[,1], I: 0.03004852 ZI: NA, pr(ZI): 0.24
Analysis of Deviance Table

Model: binomial, link: logit

Response: c(hopkins_part)

Terms added sequentially (first to last)


                 Df Deviance Resid. Df Resid. Dev  Pr(>Chi)    
NULL                               255     292.23              
fitted(MEbinom1)  4   32.335       251     259.89 1.634e-06 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
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       251     259.89  4   32.335 1.634e-06 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

spdep documentation built on May 29, 2017, 1:04 p.m.