Skip to content

Commit

Permalink
add local options to subgraphs vignette
Browse files Browse the repository at this point in the history
  • Loading branch information
rsbivand committed Sep 9, 2024
1 parent 642701d commit 4e2016a
Show file tree
Hide file tree
Showing 41 changed files with 151 additions and 64 deletions.
5 changes: 2 additions & 3 deletions R/AAA.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# Copyright 2001-15 by Roger Bivand
# Copyright 2001-24 by Roger Bivand
#

.spdepOptions <- new.env(FALSE, globalenv())
.spdepOptions <- new.env(TRUE, globalenv())
assign("spChkID", FALSE, envir = .spdepOptions)
assign("zeroPolicy", FALSE, envir = .spdepOptions)
assign("report_nb_subgraphs", FALSE, envir = .spdepOptions)
assign("verbose", FALSE, envir = .spdepOptions)
assign("mc", ifelse(.Platform$OS.type == "windows", FALSE, TRUE),
envir = .spdepOptions)
Expand Down
6 changes: 3 additions & 3 deletions R/EBI.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ EBImoran <- function (z, listw, nn, S0, zero.policy = attr(listw, "zero.policy")
{
#default subtract_mean_in_numerator=TRUE 160219 RA
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
stopifnot(is.vector(z))
zm <- mean(z)
Expand All @@ -24,7 +24,7 @@ EBImoran.mc <- function (n, x, listw, nsim, zero.policy = attr(listw, "zero.poli
#default subtract_mean_in_numerator=TRUE 160219 RA
message("The default for subtract_mean_in_numerator set TRUE from February 2016")
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
alternative <- match.arg(alternative, c("greater", "less", "two.sided"))
if (!inherits(listw, "listw"))
Expand Down Expand Up @@ -198,7 +198,7 @@ EBest <- function(n, x, family="poisson") {
EBlocal <- function(ri, ni, nb, zero.policy = NULL,
spChk = NULL, geoda = FALSE) {
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
# class to inherits Jari Oksanen 080603
if (!inherits(nb, "nb"))
Expand Down
2 changes: 1 addition & 1 deletion R/LOSH.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
LOSH <- function(x, listw, a = 2, var_hi = TRUE, zero.policy = attr(listw, "zero.policy"), na.action = na.fail, spChk = NULL) {
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
n <- length(listw$neighbours)
#a <- 2 ## "a" could be any other positive value, but the chi-square-based inference is then no longer possible
Expand Down
2 changes: 1 addition & 1 deletion R/LOSH.cs.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LOSH.cs <- function(x, listw, zero.policy = attr(listw, "zero.policy"), na.actio
if (!inherits(listw, "listw"))
stop(paste(deparse(substitute(listw)), "is not a listw object"))
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
if (!is.null(attr(listw$neighbours, "self.included")) &&
attr(listw$neighbours, "self.included"))
Expand Down
2 changes: 1 addition & 1 deletion R/LOSH.mc.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LOSH.mc <- function(x, listw, a = 2, nsim = 99, zero.policy = attr(listw, "zero.
if (!inherits(listw, "listw"))
stop(paste(deparse(substitute(listw)), "is not a listw object"))
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
if (!is.null(attr(listw$neighbours, "self.included")) &&
attr(listw$neighbours, "self.included"))
Expand Down
2 changes: 1 addition & 1 deletion R/SD.RStests.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ SD.RStests <- function(model, listw, zero.policy=attr(listw, "zero.policy"), tes
if (!inherits(listw, "listw")) stop(paste(listw_name,
"is not a listw object"))
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
if (!is.null(na.act)) {
subset <- !(1:length(listw$neighbours) %in% na.act)
Expand Down
2 changes: 1 addition & 1 deletion R/autocov.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
autocov_dist <- function(z, xy, nbs=1, type="inverse", zero.policy=NULL,
style="B", longlat=NULL) {
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
stopifnot(is.vector(z))
if (type=="one") expo <- 0
Expand Down
2 changes: 1 addition & 1 deletion R/diffnb.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
diffnb <- function(x, y, verbose=NULL) {
if (!inherits(x, "nb")) stop("not a neighbours list")
if (!inherits(y, "nb")) stop("not a neighbours list")
if (is.null(verbose)) verbose <- get("verbose", envir = .spdepOptions)
if (is.null(verbose)) verbose <- get.VerboseOption()
stopifnot(is.logical(verbose))
n <- length(x)
if (n < 1) stop("non-positive length of x")
Expand Down
8 changes: 4 additions & 4 deletions R/geary.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
geary <- function(x, listw, n, n1, S0, zero.policy=attr(listw, "zero.policy"),
scale=TRUE) { #https://github.com/r-spatial/spdep/issues/151
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
stopifnot(is.vector(x))
stopifnot(all(is.finite(x)))
Expand All @@ -21,7 +21,7 @@ geary <- function(x, listw, n, n1, S0, zero.policy=attr(listw, "zero.policy"),

geary.intern <- function(x, listw, n, zero.policy=attr(listw, "zero.policy"), type="geary") {
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
cardnb <- card(listw$neighbours)
if (type == "geary") ft <- TRUE
Expand All @@ -39,7 +39,7 @@ geary.test <- function(x, listw, randomisation=TRUE,
spChk=NULL, adjust.n=TRUE, na.action=na.fail, scale=TRUE) {
#https://github.com/r-spatial/spdep/issues/151
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
alternative <- match.arg(alternative, c("less", "greater", "two.sided"))
wname <- deparse(substitute(listw))
Expand Down Expand Up @@ -115,7 +115,7 @@ geary.mc <- function(x, listw, nsim, zero.policy=attr(listw, "zero.policy"),
alternative="greater", spChk=NULL, adjust.n=TRUE, return_boot=FALSE,
na.action=na.fail, scale=TRUE) {
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
stopifnot(is.vector(x))
alternative <- match.arg(alternative, c("less", "greater", "two.sided"))
Expand Down
2 changes: 1 addition & 1 deletion R/globalG.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ globalG.test <- function(x, listw, zero.policy=attr(listw, "zero.policy"),
alternative="greater", spChk=NULL, adjust.n=TRUE, B1correct=TRUE,
adjust.x=TRUE, Arc_all_x=FALSE, na.action=na.fail) {
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
stopifnot(is.vector(x))
alternative <- match.arg(alternative, c("greater", "less", "two.sided"))
Expand Down
6 changes: 3 additions & 3 deletions R/jc.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ joincount.test <- function(fx, listw, zero.policy=attr(listw, "zero.policy"),
alternative="greater", sampling="nonfree",
spChk=NULL, adjust.n=TRUE) {
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
alternative <- match.arg(alternative, c("greater", "less", "two.sided"))
sampling <- match.arg(sampling, c("nonfree", "free"))
Expand Down Expand Up @@ -113,7 +113,7 @@ joincount.mc <- function(fx, listw, nsim, zero.policy=attr(listw, "zero.policy")
if(!inherits(listw, "listw")) stop(paste(deparse(substitute(listw)),
"is not a listw object"))
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
if(!is.factor(fx)) stop(paste(deparse(substitute(fx)),
"is not a factor"))
Expand Down Expand Up @@ -192,7 +192,7 @@ joincount.multi <- function(fx, listw, zero.policy=attr(listw, "zero.policy"), #
"is not a factor"))
if (any(is.na(fx))) stop("NA in factor")
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
n <- length(listw$neighbours)
if (n != length(fx)) stop("objects of different length")
Expand Down
2 changes: 1 addition & 1 deletion R/lee.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

lee <- function(x, y, listw, n, S2=NULL, zero.policy=attr(listw, "zero.policy"), NAOK=FALSE) {
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
n1 <- length(listw$neighbours)
x <- c(x)
Expand Down
2 changes: 1 addition & 1 deletion R/lee.mc.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ lee.mc <- function(x, y, listw, nsim, zero.policy=attr(listw, "zero.policy"),
if(!is.numeric(x) | !is.numeric(y)) stop(paste(deparse(substitute(x)),
"is not a numeric vector"))
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
if(missing(nsim)) stop("nsim must be given")
if (is.null(spChk)) spChk <- get.spChkOption()
Expand Down
2 changes: 1 addition & 1 deletion R/lee.test.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ lee.test <- function(x, y, listw, #randomisation=TRUE,
if (!is.numeric(y)) stop(paste(deparse(substitute(y)),
"is not a numeric vector"))
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
if (is.null(spChk)) spChk <- get.spChkOption()
if (spChk && !chkIDs(x, listw) && !chkIDs(y, listw))
Expand Down
2 changes: 1 addition & 1 deletion R/licd_boots.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ licd_multi <- function(fx, listw, zero.policy=attr(listw, "zero.policy"),
"is not a factor"))
if (any(is.na(fx))) stop("NA in factor")
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
n <- length(listw$neighbours)
if (n != length(fx)) stop("objects of different length")
Expand Down
4 changes: 2 additions & 2 deletions R/lisa_perm.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ localmoran_perm <- function(x, listw, nsim=499L, zero.policy=attr(listw, "zero.p
if (!inherits(listw, "listw"))
stop(paste(deparse(substitute(listw)), "is not a listw object"))
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
if (!is.null(attr(listw$neighbours, "self.included")) &&
attr(listw$neighbours, "self.included"))
Expand Down Expand Up @@ -259,7 +259,7 @@ localG_perm <- function(x, listw, nsim=499, zero.policy=attr(listw, "zero.policy
if (!is.numeric(x))
stop(paste(deparse(substitute(x)), "is not a numeric vector"))
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
stopifnot(is.vector(x))
if (any(is.na(x))) stop(paste("NA in ", deparse(substitute(x))))
Expand Down
2 changes: 1 addition & 1 deletion R/listw2sn.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ sn2listw <- function(sn, style=NULL, zero.policy=NULL, from_mat2listw=FALSE) {
if(!inherits(sn, "spatial.neighbour"))
stop("not a spatial.neighbour object")
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
if (is.null(style)) {
style <- "M"
Expand Down
2 changes: 1 addition & 1 deletion R/lm.RStests.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ lm.RStests <- function(model, listw, zero.policy=attr(listw, "zero.policy"), tes
if (!inherits(listw, "listw")) stop(paste(listw_name,
"is not a listw object"))
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
if (!is.null(na.act) && naSubset) {
subset <- !(1:length(listw$neighbours) %in% na.act)
Expand Down
2 changes: 1 addition & 1 deletion R/lm.morantest.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
lm.morantest <- function(model, listw, zero.policy=attr(listw, "zero.policy"),
alternative = "greater", spChk=NULL, resfun=weighted.residuals, naSubset=TRUE) {
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
alternative <- match.arg(alternative, c("greater", "less", "two.sided"))
listw_name <- deparse(substitute(listw))
Expand Down
2 changes: 1 addition & 1 deletion R/local-moran-bv.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ localmoran_bv <- function(x, y, listw, nsim = 199, scale = TRUE,
if(!inherits(listw, "listw")) stop(paste(deparse(substitute(listw)),
"is not a listw object"))
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
n <- length(listw$neighbours)
if (n != length(x)) stop("Different numbers of observations")
Expand Down
2 changes: 1 addition & 1 deletion R/localG.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ localG <- function(x, listw, zero.policy=attr(listw, "zero.policy"), spChk=NULL,
if (!is.numeric(x))
stop(paste(deparse(substitute(x)), "is not a numeric vector"))
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
stopifnot(is.vector(x))
if (any(is.na(x))) stop(paste("NA in ", deparse(substitute(x))))
Expand Down
2 changes: 1 addition & 1 deletion R/localmoran.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ localmoran <- function(x, listw, zero.policy=attr(listw, "zero.policy"), na.acti
if (!inherits(listw, "listw"))
stop(paste(deparse(substitute(listw)), "is not a listw object"))
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
alternative <- match.arg(alternative, c("two.sided", "greater", "less"))
if (!is.null(attr(listw$neighbours, "self.included")) &&
Expand Down
2 changes: 1 addition & 1 deletion R/localmoran.exact.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ localmoran.exact <- function(model, select, nb, glist = NULL, style = "W",
if (!inherits(nb, "nb"))
stop(paste(deparse(substitute(nb)), "not an nb object"))
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
n <- length(nb)
u <- resfun(model)
Expand Down
6 changes: 3 additions & 3 deletions R/moran.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

moran <- function(x, listw, n, S0, zero.policy=attr(listw, "zero.policy"), NAOK=FALSE) {
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
n1 <- length(listw$neighbours)
x <- c(x)
Expand All @@ -28,7 +28,7 @@ moran.test <- function(x, listw, randomisation=TRUE, zero.policy=attr(listw, "ze
xname <- deparse(substitute(x))
if (!is.numeric(x)) stop(xname, " is not a numeric vector")
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
if (is.null(spChk)) spChk <- get.spChkOption()
if (spChk && !chkIDs(x, listw))
Expand Down Expand Up @@ -102,7 +102,7 @@ moran.mc <- function(x, listw, nsim, zero.policy=attr(listw, "zero.policy"),
xname <- deparse(substitute(x))
if(!is.numeric(x)) stop(xname, "is not a numeric vector")
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
if(missing(nsim)) stop("nsim must be given")
if (is.null(spChk)) spChk <- get.spChkOption()
Expand Down
2 changes: 1 addition & 1 deletion R/moran.exact.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ lm.morantest.exact <- function(model, listw, zero.policy = attr(listw, "zero.pol
if (!inherits(model, "lm"))
stop(paste(deparse(substitute(model)), "not an lm object"))
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
N <- length(listw$neighbours)
u <- resfun(model)
Expand Down
6 changes: 3 additions & 3 deletions R/moran.exact.alt.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ localmoran.exact.alt <- function(model, select, nb, glist = NULL, style = "W",
# class to inherits Jari Oksanen 080603
if (!inherits(nb, "nb"))
stop(paste(deparse(substitute(nb)), "not an nb object"))
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
stopifnot(is.logical(zero.policy))
if (is.null(zero.policy))
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
# if (class(model) != "lm")
# stop(paste(deparse(substitute(model)), "not an lm object"))
dmc <- deparse(model$call)
Expand Down
4 changes: 2 additions & 2 deletions R/moran.plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ moran.plot <- function(x, listw, y=NULL, zero.policy=attr(listw, "zero.policy"),
{
if (!inherits(listw, "listw")) stop(paste(deparse(substitute(listw)),
"is not a listw object"))
if (is.null(quiet)) quiet <- !get("verbose", envir = .spdepOptions)
if (is.null(quiet)) quiet <- !get.VerboseOption()
stopifnot(is.vector(x))
if (!is.null(y)) stopifnot(is.vector(y))
stopifnot(is.logical(quiet))
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
xname <- deparse(substitute(x))
if (!is.numeric(x)) stop(paste(xname, "is not a numeric vector"))
Expand Down
2 changes: 1 addition & 1 deletion R/mtlocalmoran.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ localmoran.sad <- function (model, select, nb, glist = NULL, style = "W",
if (!inherits(nb, "nb"))
stop(paste(deparse(substitute(nb)), "not an nb object"))
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
n <- length(nb)
dmc <- deparse(model$call)
Expand Down
2 changes: 1 addition & 1 deletion R/mtmoran.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ lm.morantest.sad <- function (model, listw, zero.policy = attr(listw, "zero.poli
if (!inherits(model, "lm"))
stop(paste(deparse(substitute(model)), "not an lm object"))
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
N <- length(listw$neighbours)
u <- resfun(model)
Expand Down
8 changes: 4 additions & 4 deletions R/nb2listw.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
nb2listw <- function(neighbours, glist=NULL, style="W", zero.policy=NULL)
{
if(!inherits(neighbours, "nb")) stop("Not a neighbours list")
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
if (is.null(zero.policy)) {
zero.policy <- get.ZeroPolicyOption()
}
stopifnot(is.logical(zero.policy))
if (!(style %in% c("W", "B", "C", "S", "U", "minmax")))
stop(paste("Style", style, "invalid"))
n <- length(neighbours)
if (n < 1) stop("non-positive number of entities")
cardnb <- card(neighbours)
if (!zero.policy)
if (any(cardnb == 0)) stop("Empty neighbour sets found")
if (!zero.policy && any(cardnb == 0)) stop("Empty neighbour sets found (zero.policy: ", zero.policy, ")")
vlist <- vector(mode="list", length=n)
if (is.null(glist)) {
glist <- vector(mode="list", length=n)
Expand Down
2 changes: 1 addition & 1 deletion R/nb2listwdist.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ nb2listwdist <- function(neighbours, x, type="idw", style="raw", alpha = 1, dmax
{
if(!inherits(neighbours, "nb")) stop("Not a neighbours list")
if (is.null(zero.policy))
zero.policy <- get("zeroPolicy", envir = .spdepOptions)
zero.policy <- get.ZeroPolicyOption()
stopifnot(is.logical(zero.policy))
if (!(type %in% c("idw", "dpd", "exp")))
stop(paste("type", type, "invalid"))
Expand Down
Loading

0 comments on commit 4e2016a

Please sign in to comment.