Skip to content

Commit

Permalink
add zero.policy pass-through, start zero.policy attribute changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rsbivand committed Nov 7, 2023
1 parent e2c1cd6 commit a64311a
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Version 1.2-10 (development)

* added `zero.policy` pass-through to `spdep::mat2listw` calls in `predict.Sarlm` and to `spdep::sn2listw` in `sids_models.Rmd`

* corrected #19 because the fitted model weights component is never NULL, but may have a single unique value

# Version 1.2-9 (2023-05-25)
Expand Down
4 changes: 2 additions & 2 deletions R/kpgm_new.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

GMerrorsar <- function(#W, y, X,
formula, data = list(), listw, na.action=na.fail,
zero.policy=NULL, method="nlminb", arnoldWied=FALSE,
zero.policy=attr(listw, "zero.policy"), method="nlminb", arnoldWied=FALSE,
control=list(), pars=NULL, scaleU=FALSE, verbose=NULL, legacy=FALSE,
se.lambda=TRUE, returnHcov=FALSE, pWOrder=250, tol.Hcov=1.0e-10) {
# ols <- lm(I(y) ~ I(X) - 1)
Expand Down Expand Up @@ -518,7 +518,7 @@ impacts.Gmsar <- function(obj, ..., n=NULL, tr=NULL, R=NULL, listw=NULL,
####SARAR model

gstsls<-function (formula, data = list(), listw, listw2=NULL,
na.action = na.fail, zero.policy = NULL, pars=NULL, scaleU=FALSE,
na.action = na.fail, zero.policy = attr(listw, "zero.policy"), pars=NULL, scaleU=FALSE,
control = list(), verbose = NULL, method = "nlminb", robust = FALSE,
legacy = FALSE, W2X = TRUE )
{
Expand Down
12 changes: 6 additions & 6 deletions R/predict.sarlm.R
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ predict.Sarlm <- function(object, newdata=NULL, listw=NULL, pred.type="TS", all.
W <- as(listw, "CsparseMatrix")
W <- W[region.id, region.id]
style <- listw$style
listw <- mat2listw(W, row.names = region.id, style = style) # re-normalize to keep the style
listw <- mat2listw(W, row.names = region.id, style = style, zero.policy=zero.policy) # re-normalize to keep the style
rm(W) # avoid the use of a wrong W
}
}
Expand Down Expand Up @@ -247,7 +247,7 @@ predict.Sarlm <- function(object, newdata=NULL, listw=NULL, pred.type="TS", all.
W <- as(listw.mixed, "CsparseMatrix")
W <- W[region.id.mixed, region.id.mixed]
style <- listw.mixed$style
listw.mixed <- mat2listw(W, row.names = region.id.mixed, style = style) # re-normalize to keep the style
listw.mixed <- mat2listw(W, row.names = region.id.mixed, style = style, zero.policy=zero.policy) # re-normalize to keep the style
rm(W) # avoid the use of a wrong W
}
}
Expand Down Expand Up @@ -540,7 +540,7 @@ predict.Sarlm <- function(object, newdata=NULL, listw=NULL, pred.type="TS", all.
for (i in 1:nrow(newdata)) {
region.id.temp <- c(region.id.data, region.id.newdata[i])
Wi <- W[region.id.temp, region.id.temp]
listwi <- mat2listw(Wi, row.names = region.id.temp, style = style) # re-normalize
listwi <- mat2listw(Wi, row.names = region.id.temp, style = style, zero.policy=zero.policy) # re-normalize
if (power)
Wi <- as(listwi, "CsparseMatrix")
Xi <- rbind(Xs, Xo[i,])
Expand All @@ -564,7 +564,7 @@ predict.Sarlm <- function(object, newdata=NULL, listw=NULL, pred.type="TS", all.
for (i in 1:nrow(newdata)) {
region.id.temp <- c(region.id.data, region.id.newdata[i])
Wi <- W[region.id.temp, region.id.temp]
listwi <- mat2listw(Wi, row.names = region.id.temp, style = style) # re-normalize
listwi <- mat2listw(Wi, row.names = region.id.temp, style = style, zero.policy=zero.policy) # re-normalize
Wi <- as(listwi, "CsparseMatrix")
Xi <- rbind(Xs, Xo[i,])
# compute TC1 for S and o units
Expand Down Expand Up @@ -599,7 +599,7 @@ predict.Sarlm <- function(object, newdata=NULL, listw=NULL, pred.type="TS", all.
for (i in 1:nrow(newdata)) {
region.id.temp <- c(region.id.data, region.id.newdata[i])
Wi <- W[region.id.temp, region.id.temp]
listwi <- mat2listw(Wi, row.names = region.id.temp, style = style) # re-normalize
listwi <- mat2listw(Wi, row.names = region.id.temp, style = style, zero.policy=zero.policy) # re-normalize
Wi <- as(listwi, "CsparseMatrix")
Xi <- rbind(Xs, Xo[i,])
is.data <- 1:length(ys)
Expand Down Expand Up @@ -633,7 +633,7 @@ predict.Sarlm <- function(object, newdata=NULL, listw=NULL, pred.type="TS", all.
for (i in 1:nrow(newdata)) {
region.id.temp <- c(region.id.data, region.id.newdata[i])
Wi <- W[region.id.temp, region.id.temp]
listwi <- mat2listw(Wi, row.names = region.id.temp, style = style) # re-normalize
listwi <- mat2listw(Wi, row.names = region.id.temp, style = style, zero.policy=zero.policy) # re-normalize
Wi <- as(listwi, "CsparseMatrix")
Xi <- rbind(Xs, Xo[i,])
# compute TC1 for S and o units
Expand Down
2 changes: 1 addition & 1 deletion man/GMerrorsar.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}
\usage{
GMerrorsar(formula, data = list(), listw, na.action = na.fail,
zero.policy = NULL, method="nlminb", arnoldWied=FALSE,
zero.policy = attr(listw, "zero.policy"), method="nlminb", arnoldWied=FALSE,
control = list(), pars, scaleU=FALSE, verbose=NULL, legacy=FALSE,
se.lambda=TRUE, returnHcov=FALSE, pWOrder=250, tol.Hcov=1.0e-10)
\method{summary}{Gmsar}(object, correlation = FALSE, Hausman=FALSE, ...)
Expand Down
2 changes: 1 addition & 1 deletion man/gstsls.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
\usage{
gstsls(formula, data = list(), listw, listw2 = NULL, na.action = na.fail,
zero.policy = NULL, pars=NULL, scaleU=FALSE, control = list(),
zero.policy = attr(listw, "zero.policy"), pars=NULL, scaleU=FALSE, control = list(),
verbose=NULL, method="nlminb", robust=FALSE, legacy=FALSE, W2X=TRUE)
\method{impacts}{Gmsar}(obj, \dots, n = NULL, tr = NULL, R = NULL,
listw = NULL, evalues=NULL, tol = 1e-06, empirical = FALSE, Q=NULL)
Expand Down
2 changes: 1 addition & 1 deletion vignettes/sids_models.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ n <- nc$BIR74
el1 <- min(dij)/dij
el2 <- sqrt(n[sids.nhbr$to]/n[sids.nhbr$from])
sids.nhbr$weights <- el1*el2
sids.nhbr.listw <- sn2listw(sids.nhbr)
sids.nhbr.listw <- sn2listw(sids.nhbr, style="B", zero.policy=TRUE)
```

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

0 comments on commit a64311a

Please sign in to comment.