Skip to content

Commit b815397

Browse files
authored
Merge pull request #140 from r-spatial/gearyNA
#139 adding na.action to geary.test, geary.mc and globalG.test
2 parents 46c9078 + aae3bbc commit b815397

File tree

8 files changed

+135
-52
lines changed

8 files changed

+135
-52
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Version 1.3-2 (development)
22

3+
* #139 add `na.action` argument to `geary.test`, `geary.mc` and `globalG.test`
4+
35
* add `style` to `sn2listw` use in `tri2nb`
46

57
# Version 1.3-1 (2023-11-23)

R/geary.R

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2001-9, 2021 by Roger Bivand
1+
# Copyright 2001-24 by Roger Bivand
22
#
33

44

@@ -7,6 +7,7 @@ geary <- function(x, listw, n, n1, S0, zero.policy=attr(listw, "zero.policy")) {
77
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
88
stopifnot(is.logical(zero.policy))
99
stopifnot(is.vector(x))
10+
stopifnot(all(is.finite(x)))
1011
# z <- scale(x, scale=FALSE)
1112
z <- scale(x)
1213
zz <- sum(z^2)
@@ -34,16 +35,24 @@ geary.intern <- function(x, listw, n, zero.policy=attr(listw, "zero.policy"), ty
3435
}
3536

3637
geary.test <- function(x, listw, randomisation=TRUE, zero.policy=attr(listw, "zero.policy"),
37-
alternative="greater", spChk=NULL, adjust.n=TRUE) {
38+
alternative="greater", spChk=NULL, adjust.n=TRUE, na.action=na.fail) {
3839
if (is.null(zero.policy))
3940
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
4041
stopifnot(is.logical(zero.policy))
4142
alternative <- match.arg(alternative, c("less", "greater", "two.sided"))
42-
if(!inherits(listw, "listw")) stop(paste(deparse(substitute(listw)),
43-
"is not a listw object"))
44-
if(!is.numeric(x)) stop(paste(deparse(substitute(x)),
45-
"is not a numeric vector"))
46-
if (any(is.na(x))) stop("NA in X")
43+
wname <- deparse(substitute(listw))
44+
if (!inherits(listw, "listw")) stop(wname, "is not a listw object")
45+
xname <- deparse(substitute(x))
46+
if(!is.numeric(x)) stop(xname,
47+
" is not a numeric vector")
48+
if (deparse(substitute(na.action)) == "na.pass")
49+
stop("na.pass not permitted")
50+
x <- na.action(x)
51+
na.act <- attr(x, "na.action")
52+
if (!is.null(na.act)) {
53+
subset <- !(1:length(listw$neighbours) %in% na.act)
54+
listw <- subset(listw, subset, zero.policy=zero.policy)
55+
}
4756
n <- length(listw$neighbours)
4857
if (n != length(x)) stop("objects of different length")
4958
if (is.null(spChk)) spChk <- get.spChkOption()
@@ -52,9 +61,9 @@ geary.test <- function(x, listw, randomisation=TRUE, zero.policy=attr(listw, "ze
5261

5362
wc <- spweights.constants(listw, zero.policy, adjust.n=adjust.n)
5463
S02 <- wc$S0*wc$S0
55-
res <- geary(x, listw, wc$n, wc$n1, wc$S0, zero.policy)
64+
res <- geary(as.vector(x), listw, wc$n, wc$n1, wc$S0, zero.policy)
5665
C <- res$C
57-
if (is.na(C)) stop("NAs generated in geary - check zero.policy")
66+
if (is.na(C)) stop("NAs generated in geary - check zero.policy and na.action")
5867
K <- res$K
5968
EC <- 1
6069
if(randomisation) {
@@ -85,29 +94,43 @@ geary.test <- function(x, listw, randomisation=TRUE, zero.policy=attr(listw, "ze
8594
names(vec) <- c("Geary C statistic", "Expectation", "Variance")
8695
method <- paste("Geary C test under", ifelse(randomisation,
8796
"randomisation", "normality"))
88-
data.name <- paste(deparse(substitute(x)), "\nweights:",
89-
deparse(substitute(listw)), "\n")
97+
data.name <- paste(xname, "\nweights:", wname,
98+
ifelse(is.null(na.act), "", paste("\nomitted:",
99+
paste(na.act, collapse=", "))),
100+
ifelse(adjust.n && isTRUE(any(sum(card(listw$neighbours) == 0L))),
101+
"\nn reduced by no-neighbour observations", ""), "\n")
90102
res <- list(statistic=statistic, p.value=PrC, estimate=vec,
91103
alternative=ifelse(alternative == "two.sided", alternative,
92104
paste("Expectation", alternative, "than statistic")),
93105
method=method, data.name=data.name)
106+
if (!is.null(na.act)) attr(res, "na.action") <- na.act
94107
class(res) <- "htest"
95108
res
96109
}
97110

98111
geary.mc <- function(x, listw, nsim, zero.policy=attr(listw, "zero.policy"),
99-
alternative="greater", spChk=NULL, adjust.n=TRUE, return_boot=FALSE) {
112+
alternative="greater", spChk=NULL, adjust.n=TRUE, return_boot=FALSE,
113+
na.action=na.fail) {
100114
if (is.null(zero.policy))
101115
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
102116
stopifnot(is.logical(zero.policy))
103117
stopifnot(is.vector(x))
104118
alternative <- match.arg(alternative, c("less", "greater", "two.sided"))
105-
if(!inherits(listw, "listw")) stop(paste(deparse(substitute(listw)),
106-
"is not a listw object"))
107-
if(!is.numeric(x)) stop(paste(deparse(substitute(x)),
108-
"is not a numeric vector"))
119+
wname <- deparse(substitute(listw))
120+
if (!inherits(listw, "listw")) stop(wname, "is not a listw object")
121+
xname <- deparse(substitute(x))
122+
if(!is.numeric(x)) stop(xname, " is not a numeric vector")
109123
if(missing(nsim)) stop("nsim must be given")
110-
if (any(is.na(x))) stop("NA in X")
124+
if (deparse(substitute(na.action)) == "na.pass")
125+
stop("na.pass not permitted")
126+
x <- na.action(x)
127+
na.act <- attr(x, "na.action")
128+
if (!is.null(na.act)) {
129+
subset <- !(1:length(listw$neighbours) %in% na.act)
130+
listw <- subset(listw, subset, zero.policy=zero.policy)
131+
if (return_boot)
132+
message("NA observations omitted: ", paste(na.act, collapse=", "))
133+
}
111134
n <- length(listw$neighbours)
112135
if (n != length(x)) stop("objects of different length")
113136
if (is.null(spChk)) spChk <- get.spChkOption()
@@ -134,7 +157,7 @@ geary.mc <- function(x, listw, nsim, zero.policy=attr(listw, "zero.policy"),
134157
res <- numeric(length=nsim+1)
135158
for (i in 1:nsim) res[i] <- geary(sample(x), listw, n, wc$n1, wc$S0,
136159
zero.policy)$C
137-
res[nsim+1] <- geary(x, listw, n, wc$n1, wc$S0, zero.policy)$C
160+
res[nsim+1] <- geary(as.vector(x), listw, n, wc$n1, wc$S0, zero.policy)$C
138161
rankres <- rank(res)
139162
xrank <- rankres[length(res)]
140163
diff <- nsim - xrank
@@ -153,12 +176,13 @@ geary.mc <- function(x, listw, nsim, zero.policy=attr(listw, "zero.policy"),
153176
parameter <- xrank
154177
names(parameter) <- "observed rank"
155178
method <- "Monte-Carlo simulation of Geary C"
156-
data.name <- paste(deparse(substitute(x)), "\nweights:",
157-
deparse(substitute(listw)), "\nnumber of simulations + 1:",
158-
nsim+1, "\n")
179+
data.name <- paste(xname, "\nweights:", wname,
180+
ifelse(is.null(na.act), "", paste("\nomitted:", paste(na.act,
181+
collapse=", "))), "\nnumber of simulations + 1:", nsim+1, "\n")
159182
lres <- list(statistic=statistic, parameter=parameter,
160183
p.value=pval, alternative=alternative, method=method,
161184
data.name=data.name, res=res)
185+
if (!is.null(na.act)) attr(res, "na.action") <- na.act
162186
class(lres) <- c("htest", "mc.sim")
163187
lres
164188
}

R/globalG.R

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
1-
# Copyright 2002-2018 by Hisaji ONO and Roger Bivand
1+
# Copyright 2002-2024 by Hisaji ONO and Roger Bivand
22
#
33
# General G Statistics
44
#
55
#
66
globalG.test <- function(x, listw, zero.policy=attr(listw, "zero.policy"),
7-
alternative="greater", spChk=NULL, adjust.n=TRUE, B1correct=TRUE, adjust.x=TRUE, Arc_all_x=FALSE) {
7+
alternative="greater", spChk=NULL, adjust.n=TRUE, B1correct=TRUE,
8+
adjust.x=TRUE, Arc_all_x=FALSE, na.action=na.fail) {
89
if (is.null(zero.policy))
910
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
1011
stopifnot(is.logical(zero.policy))
1112
stopifnot(is.vector(x))
1213
alternative <- match.arg(alternative, c("greater", "less", "two.sided"))
13-
if (!inherits(listw, "listw"))
14-
stop(paste(deparse(substitute(listw)), "is not a listw object"))
14+
wname <- deparse(substitute(listw))
15+
if (!inherits(listw, "listw")) stop(wname, "is not a listw object")
1516
if (is.na(match(listw$style, c("B", "C", "U"))))
1617
warning("Binary weights recommended (especially for distance bands)")
17-
if (!is.numeric(x))
18-
stop(paste(deparse(substitute(x)), "is not a numeric vector"))
19-
if (any(is.na(x))) stop(paste("NA in ", deparse(substitute(x))))
20-
if (any(x < 0.0))
21-
stop(paste("Negative value in ", deparse(substitute(x))))
18+
xname <- deparse(substitute(x))
19+
if(!is.numeric(x)) stop(xname, " is not a numeric vector")
20+
if (deparse(substitute(na.action)) == "na.pass")
21+
stop("na.pass not permitted")
22+
x <- na.action(x)
23+
na.act <- attr(x, "na.action")
24+
if (!is.null(na.act)) {
25+
subset <- !(1:length(listw$neighbours) %in% na.act)
26+
listw <- subset(listw, subset, zero.policy=zero.policy)
27+
}
28+
if (any(x < 0.0)) stop("Negative value in ", xname)
29+
2230
n <- length(listw$neighbours)
23-
if (n != length(x))stop("Different numbers of observations")
31+
if (n != length(x)) stop("Different numbers of observations")
2432
if (is.null(spChk)) spChk <- get.spChkOption()
2533
if (spChk && !chkIDs(x, listw))
2634
stop("Check of data and weights ID integrity failed")
@@ -80,8 +88,10 @@ globalG.test <- function(x, listw, zero.policy=attr(listw, "zero.policy"),
8088
warning("Out-of-range p-value: reconsider test arguments")
8189
vec <- c(G, E.G, var.G)
8290
names(vec) <- c("Global G statistic", "Expectation", "Variance")
83-
data.name <- paste(deparse(substitute(x)), "\nweights:",
84-
deparse(substitute(listw)), "\n")
91+
data.name <- paste(xname, "\nweights:", wname, ifelse(is.null(na.act),
92+
"", paste("\nomitted:", paste(na.act, collapse=", "))),
93+
ifelse(adjust.n && isTRUE(any(sum(card(listw$neighbours) == 0L))),
94+
"\nn reduced by no-neighbour observations", ""), "\n")
8595
res <- list(statistic=statistic, p.value=PrG, estimate=vec,
8696
alternative=alternative, data.name=data.name, method=method)
8797
class(res) <- "htest"

R/moran.R

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2001-18 by Roger Bivand
1+
# Copyright 2001-24 by Roger Bivand
22
#
33

44
moran <- function(x, listw, n, S0, zero.policy=attr(listw, "zero.policy"), NAOK=FALSE) {
@@ -23,19 +23,17 @@ moran.test <- function(x, listw, randomisation=TRUE, zero.policy=attr(listw, "ze
2323
alternative="greater", rank = FALSE, na.action=na.fail, spChk=NULL,
2424
adjust.n=TRUE, drop.EI2=FALSE) {
2525
alternative <- match.arg(alternative, c("greater", "less", "two.sided"))
26-
if (!inherits(listw, "listw")) stop(paste(deparse(substitute(listw)),
27-
"is not a listw object"))
28-
if (!is.numeric(x)) stop(paste(deparse(substitute(x)),
29-
"is not a numeric vector"))
26+
wname <- deparse(substitute(listw))
27+
if (!inherits(listw, "listw")) stop(wname, "is not a listw object")
28+
xname <- deparse(substitute(x))
29+
if (!is.numeric(x)) stop(xname, " is not a numeric vector")
3030
if (is.null(zero.policy))
3131
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
3232
stopifnot(is.logical(zero.policy))
3333
if (is.null(spChk)) spChk <- get.spChkOption()
3434
if (spChk && !chkIDs(x, listw))
3535
stop("Check of data and weights ID integrity failed")
3636
# if (any(is.na(x))) stop("NA in X")
37-
xname <- deparse(substitute(x))
38-
wname <- deparse(substitute(listw))
3937
NAOK <- deparse(substitute(na.action)) == "na.pass"
4038
x <- na.action(x)
4139
na.act <- attr(x, "na.action")
@@ -86,8 +84,8 @@ moran.test <- function(x, listw, randomisation=TRUE, zero.policy=attr(listw, "ze
8684
wname, ifelse(is.null(na.act), "", paste("\nomitted:",
8785
paste(na.act, collapse=", "))),
8886
ifelse(adjust.n && isTRUE(any(sum(card(listw$neighbours) == 0L))),
89-
"n reduced by no-neighbour observations\n", ""),
90-
ifelse(drop.EI2, "EI^2 term dropped in VI", ""), "\n")
87+
"\nn reduced by no-neighbour observations", ""),
88+
ifelse(drop.EI2, "\nEI^2 term dropped in VI", ""), "\n")
9189
res <- list(statistic=statistic, p.value=PrI, estimate=vec,
9290
alternative=alternative, method=method, data.name=data.name)
9391
if (!is.null(na.act)) attr(res, "na.action") <- na.act
@@ -99,10 +97,10 @@ moran.mc <- function(x, listw, nsim, zero.policy=attr(listw, "zero.policy"),
9997
alternative="greater", na.action=na.fail, spChk=NULL,
10098
return_boot=FALSE, adjust.n=TRUE) {
10199
alternative <- match.arg(alternative, c("greater", "less", "two.sided"))
102-
if(!inherits(listw, "listw")) stop(paste(deparse(substitute(listw)),
103-
"is not a listw object"))
104-
if(!is.numeric(x)) stop(paste(deparse(substitute(x)),
105-
"is not a numeric vector"))
100+
wname <- deparse(substitute(listw))
101+
if(!inherits(listw, "listw")) stop(wname, "is not a listw object")
102+
xname <- deparse(substitute(x))
103+
if(!is.numeric(x)) stop(xname, "is not a numeric vector")
106104
if (is.null(zero.policy))
107105
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
108106
stopifnot(is.logical(zero.policy))
@@ -114,15 +112,15 @@ moran.mc <- function(x, listw, nsim, zero.policy=attr(listw, "zero.policy"),
114112
if (!zero.policy && any(cards == 0))
115113
stop("regions with no neighbours found")
116114
# if (any(is.na(x))) stop("NA in X")
117-
xname <- deparse(substitute(x))
118-
wname <- deparse(substitute(listw))
119115
if (deparse(substitute(na.action)) == "na.pass")
120116
stop("na.pass not permitted")
121117
x <- na.action(x)
122118
na.act <- attr(x, "na.action")
123119
if (!is.null(na.act)) {
124120
subset <- !(1:length(listw$neighbours) %in% na.act)
125121
listw <- subset(listw, subset, zero.policy=zero.policy)
122+
if (return_boot)
123+
message("NA observations omitted: ", paste(na.act, collapse=", "))
126124
}
127125
n <- length(listw$neighbours)
128126
if (n != length(x)) stop("objects of different length")

man/geary.mc.Rd

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
}
88
\usage{
99
geary.mc(x, listw, nsim, zero.policy=attr(listw, "zero.policy"), alternative="greater",
10-
spChk=NULL, adjust.n=TRUE, return_boot=FALSE)
10+
spChk=NULL, adjust.n=TRUE, return_boot=FALSE, na.action=na.fail)
1111
}
1212
\arguments{
1313
\item{x}{a numeric vector the same length as the neighbours list in listw}
@@ -18,7 +18,7 @@ geary.mc(x, listw, nsim, zero.policy=attr(listw, "zero.policy"), alternative="gr
1818
\item{spChk}{should the data vector names be checked against the spatial objects for identity integrity, TRUE, or FALSE, default NULL to use \code{get.spChkOption()}}
1919
\item{adjust.n}{default TRUE, if FALSE the number of observations is not adjusted for no-neighbour observations, if TRUE, the number of observations is adjusted}
2020
\item{return_boot}{return an object of class \code{boot} from the equivalent permutation bootstrap rather than an object of class \code{htest}}
21-
}
21+
\item{na.action}{a function (default \code{na.fail}), can also be \code{na.omit} or \code{na.exclude} - in these cases the 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 \code{nb2listw} may be subsetted. \code{na.pass} is not permitted because it is meaningless in a permutation test.}}
2222

2323
\value{
2424
A list with class \code{htest} and \code{mc.sim} containing the following components:
@@ -37,6 +37,7 @@ A list with class \code{htest} and \code{mc.sim} containing the following compon
3737

3838
\examples{
3939
data(oldcol)
40+
set.seed(1)
4041
sim1 <- geary.mc(COL.OLD$CRIME, nb2listw(COL.nb, style="W"),
4142
nsim=99, alternative="less")
4243
sim1
@@ -52,5 +53,18 @@ sim3 <- geary.mc(COL.OLD$CRIME, nb2listw(colold.lags[[3]],
5253
style="W"), nsim=99)
5354
sim3
5455
summary(sim3$res)
56+
crime <- COL.OLD$CRIME
57+
is.na(crime) <- sample(1:length(crime), 10)
58+
try(geary.mc(crime, nb2listw(COL.nb, style="W"), nsim=99,
59+
na.action=na.fail))
60+
geary.mc(crime, nb2listw(COL.nb, style="W"), nsim=99, zero.policy=TRUE,
61+
na.action=na.omit)
62+
geary.mc(crime, nb2listw(COL.nb, style="W"), nsim=99, zero.policy=TRUE,
63+
return_boot=TRUE, na.action=na.omit)
64+
geary.mc(crime, nb2listw(COL.nb, style="W"), nsim=99, zero.policy=TRUE,
65+
na.action=na.exclude)
66+
geary.mc(crime, nb2listw(COL.nb, style="W"), nsim=99, zero.policy=TRUE,
67+
return_boot=TRUE, na.action=na.exclude)
68+
try(geary.mc(crime, nb2listw(COL.nb, style="W"), nsim=99, na.action=na.pass))
5569
}
5670
\keyword{spatial}

man/geary.test.Rd

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
}
88
\usage{
99
geary.test(x, listw, randomisation=TRUE, zero.policy=attr(listw, "zero.policy"),
10-
alternative="greater", spChk=NULL, adjust.n=TRUE)
10+
alternative="greater", spChk=NULL, adjust.n=TRUE, na.action=na.fail)
1111
}
1212

1313
\arguments{
@@ -18,6 +18,7 @@ geary.test(x, listw, randomisation=TRUE, zero.policy=attr(listw, "zero.policy"),
1818
\item{alternative}{a character string specifying the alternative hypothesis, must be one of "greater" (default), "less" or "two.sided".}
1919
\item{spChk}{should the data vector names be checked against the spatial objects for identity integrity, TRUE, or FALSE, default NULL to use \code{get.spChkOption()}}
2020
\item{adjust.n}{default TRUE, if FALSE the number of observations is not adjusted for no-neighbour observations, if TRUE, the number of observations is adjusted}
21+
\item{na.action}{a function (default \code{na.fail}), can also be \code{na.omit} or \code{na.exclude} - in these cases the 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 \code{nb2listw} may be subsetted. \code{na.pass} is not permitted.}
2122
}
2223

2324
\value{
@@ -62,5 +63,13 @@ geary.test(COL.OLD$CRIME, listw2U(nb2listw(COL.k4.nb,
6263
style="W")))
6364
geary.test(COL.OLD$CRIME, listw2U(nb2listw(COL.k4.nb,
6465
style="W")), randomisation=FALSE)
66+
crime <- COL.OLD$CRIME
67+
is.na(crime) <- sample(1:length(crime), 10)
68+
try(geary.test(crime, nb2listw(COL.nb, style="W"), na.action=na.fail))
69+
geary.test(crime, nb2listw(COL.nb, style="W"), zero.policy=TRUE,
70+
na.action=na.omit)
71+
geary.test(crime, nb2listw(COL.nb, style="W"), zero.policy=TRUE,
72+
na.action=na.exclude)
73+
try(geary.test(crime, nb2listw(COL.nb, style="W"), na.action=na.pass))
6574
}
6675
\keyword{spatial}

man/globalG.test.Rd

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ The global G statistic for spatial autocorrelation, complementing the local Gi L
77
}
88
\usage{
99
globalG.test(x, listw, zero.policy=attr(listw, "zero.policy"), alternative="greater",
10-
spChk=NULL, adjust.n=TRUE, B1correct=TRUE, adjust.x=TRUE, Arc_all_x=FALSE)
10+
spChk=NULL, adjust.n=TRUE, B1correct=TRUE, adjust.x=TRUE, Arc_all_x=FALSE,
11+
na.action=na.fail)
1112
}
1213
\arguments{
1314
\item{x}{a numeric vector the same length as the neighbours list in listw}
@@ -19,6 +20,7 @@ globalG.test(x, listw, zero.policy=attr(listw, "zero.policy"), alternative="grea
1920
\item{B1correct}{default TRUE, if TRUE, the erratum referenced below: "On page 195, the coefficient of W2 in B1, (just below center of the page) should be 6, not 3." is applied; if FALSE, 3 is used (as in CrimeStat IV)}
2021
\item{adjust.x}{default TRUE, if TRUE, x values of observations with no neighbours are omitted in the denominator of G}
2122
\item{Arc_all_x}{default FALSE, if Arc_all_x=TRUE and adjust.x=TRUE, use the full x vector in part of the denominator term for G}
23+
\item{na.action}{a function (default \code{na.fail}), can also be \code{na.omit} or \code{na.exclude} - in these cases the 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 \code{nb2listw} may be subsetted. \code{na.pass} is not permitted.}
2224
}
2325

2426
\value{
@@ -59,5 +61,16 @@ for (i in 1:ndists) {
5961
ZG[[i]] <- globalG.test(sidsrate79, thislw, zero.policy=TRUE, alternative="two.sided")
6062
}
6163
t(sapply(ZG, function(x) c(x$estimate[1], x$statistic, p.value=unname(x$p.value))))
64+
data(oldcol)
65+
crime <- COL.OLD$CRIME
66+
is.na(crime) <- sample(1:length(crime), 10)
67+
res <- try(globalG.test(crime, nb2listw(COL.nb, style="B"),
68+
na.action=na.fail))
69+
res
70+
globalG.test(crime, nb2listw(COL.nb, style="B"), zero.policy=TRUE,
71+
na.action=na.omit)
72+
globalG.test(crime, nb2listw(COL.nb, style="B"), zero.policy=TRUE,
73+
na.action=na.exclude)
74+
try(globalG.test(crime, nb2listw(COL.nb, style="B"), na.action=na.pass))
6275
}
6376
\keyword{spatial}

0 commit comments

Comments
 (0)