Skip to content

Commit ea905de

Browse files
committed
condition on spdep version for zero.policy
1 parent a64311a commit ea905de

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ importFrom(splines, interpSpline)
3030
importFrom(LearnBayes, rwmetrop)
3131
importFrom(nlme, fdHess)
3232
importFrom(multcomp, glht)
33+
importFrom("utils", "packageVersion")
3334

3435
##################
3536
# ML SE

R/predict.sarlm.R

+30-6
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,11 @@ predict.Sarlm <- function(object, newdata=NULL, listw=NULL, pred.type="TS", all.
193193
W <- as(listw, "CsparseMatrix")
194194
W <- W[region.id, region.id]
195195
style <- listw$style
196-
listw <- mat2listw(W, row.names = region.id, style = style, zero.policy=zero.policy) # re-normalize to keep the style
196+
if (packageVersion("spdep") >= "1.3.1") {
197+
listw <- mat2listw(W, row.names = region.id, style = style, zero.policy=zero.policy) # re-normalize to keep the style
198+
} else {
199+
listw <- mat2listw(W, row.names = region.id, style = style) # re-normalize to keep the style
200+
}
197201
rm(W) # avoid the use of a wrong W
198202
}
199203
}
@@ -247,7 +251,11 @@ predict.Sarlm <- function(object, newdata=NULL, listw=NULL, pred.type="TS", all.
247251
W <- as(listw.mixed, "CsparseMatrix")
248252
W <- W[region.id.mixed, region.id.mixed]
249253
style <- listw.mixed$style
250-
listw.mixed <- mat2listw(W, row.names = region.id.mixed, style = style, zero.policy=zero.policy) # re-normalize to keep the style
254+
if (packageVersion("spdep") >= "1.3.1") {
255+
listw.mixed <- mat2listw(W, row.names = region.id.mixed, style = style, zero.policy=zero.policy) # re-normalize to keep the style
256+
} else {
257+
listw.mixed <- mat2listw(W, row.names = region.id.mixed, style = style) # re-normalize to keep the style
258+
}
251259
rm(W) # avoid the use of a wrong W
252260
}
253261
}
@@ -540,7 +548,11 @@ predict.Sarlm <- function(object, newdata=NULL, listw=NULL, pred.type="TS", all.
540548
for (i in 1:nrow(newdata)) {
541549
region.id.temp <- c(region.id.data, region.id.newdata[i])
542550
Wi <- W[region.id.temp, region.id.temp]
543-
listwi <- mat2listw(Wi, row.names = region.id.temp, style = style, zero.policy=zero.policy) # re-normalize
551+
if (packageVersion("spdep") >= "1.3.1") {
552+
listwi <- mat2listw(Wi, row.names = region.id.temp, style = style, zero.policy=zero.policy) # re-normalize
553+
} else {
554+
listwi <- mat2listw(Wi, row.names = region.id.temp, style = style) # re-normalize to keep the style
555+
}
544556
if (power)
545557
Wi <- as(listwi, "CsparseMatrix")
546558
Xi <- rbind(Xs, Xo[i,])
@@ -564,7 +576,11 @@ predict.Sarlm <- function(object, newdata=NULL, listw=NULL, pred.type="TS", all.
564576
for (i in 1:nrow(newdata)) {
565577
region.id.temp <- c(region.id.data, region.id.newdata[i])
566578
Wi <- W[region.id.temp, region.id.temp]
567-
listwi <- mat2listw(Wi, row.names = region.id.temp, style = style, zero.policy=zero.policy) # re-normalize
579+
if (packageVersion("spdep") >= "1.3.1") {
580+
listwi <- mat2listw(Wi, row.names = region.id.temp, style = style, zero.policy=zero.policy) # re-normalize
581+
} else {
582+
listwi <- mat2listw(Wi, row.names = region.id.temp, style = style) # re-normalize to keep the style
583+
}
568584
Wi <- as(listwi, "CsparseMatrix")
569585
Xi <- rbind(Xs, Xo[i,])
570586
# compute TC1 for S and o units
@@ -599,7 +615,11 @@ predict.Sarlm <- function(object, newdata=NULL, listw=NULL, pred.type="TS", all.
599615
for (i in 1:nrow(newdata)) {
600616
region.id.temp <- c(region.id.data, region.id.newdata[i])
601617
Wi <- W[region.id.temp, region.id.temp]
602-
listwi <- mat2listw(Wi, row.names = region.id.temp, style = style, zero.policy=zero.policy) # re-normalize
618+
if (packageVersion("spdep") >= "1.3.1") {
619+
listwi <- mat2listw(Wi, row.names = region.id.temp, style = style, zero.policy=zero.policy) # re-normalize
620+
} else {
621+
listwi <- mat2listw(Wi, row.names = region.id.temp, style = style) # re-normalize to keep the style
622+
}
603623
Wi <- as(listwi, "CsparseMatrix")
604624
Xi <- rbind(Xs, Xo[i,])
605625
is.data <- 1:length(ys)
@@ -633,7 +653,11 @@ predict.Sarlm <- function(object, newdata=NULL, listw=NULL, pred.type="TS", all.
633653
for (i in 1:nrow(newdata)) {
634654
region.id.temp <- c(region.id.data, region.id.newdata[i])
635655
Wi <- W[region.id.temp, region.id.temp]
636-
listwi <- mat2listw(Wi, row.names = region.id.temp, style = style, zero.policy=zero.policy) # re-normalize
656+
if (packageVersion("spdep") >= "1.3.1") {
657+
listwi <- mat2listw(Wi, row.names = region.id.temp, style = style, zero.policy=zero.policy) # re-normalize
658+
} else {
659+
listwi <- mat2listw(Wi, row.names = region.id.temp, style = style) # re-normalize to keep the style
660+
}
637661
Wi <- as(listwi, "CsparseMatrix")
638662
Xi <- rbind(Xs, Xo[i,])
639663
# compute TC1 for S and o units

vignettes/sids_models.Rmd

+5-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ n <- nc$BIR74
9797
el1 <- min(dij)/dij
9898
el2 <- sqrt(n[sids.nhbr$to]/n[sids.nhbr$from])
9999
sids.nhbr$weights <- el1*el2
100-
sids.nhbr.listw <- sn2listw(sids.nhbr, style="B", zero.policy=TRUE)
100+
if (packageVersion("spdep") >= "1.3.1") {
101+
sids.nhbr.listw <- sn2listw(sids.nhbr, style="B", zero.policy=TRUE)
102+
} else {
103+
sids.nhbr.listw <- sn2listw(sids.nhbr)
104+
}
101105
```
102106

103107
The first model (I) is a null model with just an intercept, the second

0 commit comments

Comments
 (0)