-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
change the way lag variables are detected in predict #38
Comments
Hi, I have this issue when using |
Could you provide a reproducible example that matches your case? |
So after looking at it more carefully, I believe my error was actually being caused by a mismatch of structure between my original dataset and the predicting dataset. The message I had was: "Error in predict.Sarlm(mod, dfp, listw = weights) : I assumed the first error (which in the code you link to this issue) was the main problem but fixing the second warning appears to have made everything work. An example of what I'm doing: library(tidyverse)
library(sf)
library(spdep)
library(spatialreg)
# Dataset
df <- st_read(system.file("shapes/boston_tracts.shp", package = "spData"))
# Spatial weights
centroids <- st_centroid(df)
neigh <- dnearneigh(centroids, d1 = 0, d2 = 30)
weights <- nb2listw(neigh, glist = lapply(nbdists(neigh, centroids), \(x) 1/(x^2)))
# Model
mod <- lagsarlm(log(MEDV) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + I(RM^2) +
AGE + log(DIS) + log(RAD) + TAX + PTRATIO + B + log(LSTAT),
data = df,
Durbin = ~ CRIM,
listw = weights)
summary(mod)
# Predict
dfp <- df %>%
mutate(TAX = 0.5 * TAX)
predict(mod, dfp, listw = weights) I think this works fine. But just to be clear, |
Yes, |
Handling of formula Durbin objects does not work, get to line 233 in R/predict.sarlm.R.
The text was updated successfully, but these errors were encountered: