gpiras / sphet Goto Github PK
View Code? Open in Web Editor NEWsphet was previously hosted by Rforge. This R library deals with cross sectional spatial econometrics models estimated by IV and GM.
sphet was previously hosted by Rforge. This R library deals with cross sectional spatial econometrics models estimated by IV and GM.
@gpiras listw2dgCMatrix
in sphet
and splm
seems to do the same as as(, "CsparseMatrix")
in spatialreg
. The apparent difference is that listw2dgCMatrix
takes a zero.policy
argument, but:
library(spdep)
columbus <- st_read(system.file("shapes/columbus.shp", package="spData")[1], quiet=TRUE)
(nb0 <- poly2nb(columbus))
lw0 <- nb2listw(nb0)
library(spatialreg)
m0 <- as(lw0, "CsparseMatrix")
library(sphet)
M0 <- listw2dgCMatrix(lw0)
all.equal(mo, M0, check.attributes=FALSE)
col_geoms <- st_geometry(columbus)
col_geoms[1] <- st_buffer(col_geoms[1], dist=-0.05)
st_geometry(columbus) <- col_geoms
(nb1 <- poly2nb(columbus))
lw1 <- nb2listw(nb1, zero.policy=TRUE)
m1 <- as(lw1, "CsparseMatrix")
M1b <- listw2dgCMatrix(lw1, zero.policy=TRUE)
all.equal(m1, M1b, check.attributes=FALSE)
M1a <- listw2dgCMatrix(lw1, zero.policy=FALSE)
fails with:
invalid class "dgCMatrix" object: 'i' slot has elements not in {0,...,Dim[1]-1}
The only other difference is in listw2dgCMatrix
not providing row or column names.
I'm thinking of adding an attribute recording whether a listw
object was created with zero.policy
TRUE
or FALSE
, but in this case I don't see what the zero.policy
argument does in listw2dgCMatrix
over and above the coercion - which implicitly assumes zero.policy
is TRUE because the alternative is full rows and columns of NAs for observations without neighbours. This is part of trying to tidy up interfaces between the SE packages.
Dear dr. Piras,
Thank you so much for the implementation of sphet.
I was wondering, is it possible to use only WX as an instrument in spreg and in gstslshet?
In the hidden code at https://rdrr.io/cran/sphet/src/R/hidden_functions.R I saw that it always uses WX and WWX. However, with my dataset WX and WWX have perfect multicolinearity between certain columns. (I use dummies which have the same value for everyone in the same block of the W-matrix).
Why is it not possible for me to choose which power I want to use as an instrument? Is it because just using WX instead of WX and WWX would lead to inconsistent results? Or for another reason.
Kind regards,
A.Lemmens
Thanks for making this package.
Please consider either enabling a user to run OLS regressions with SHAC standard errors or provide a separate function; i.e. have both shac
and stslshac
.
Hello, I'm a PhD student and I'm using the sphet package.
I had a question about the impacts function and I would like to raise this question since I know that this package is under development (including the impacts function).
follow my code using built-in columbus data.
data(columbus, package="spdep")
listw <- spdep::nb2listw(col.gal.nb)
attach(columbus)
#i'm going direct to regression by sphet
#SAC (SARAR MODEL)
SAC.robust <- spreg(INC ~ HOVAL+DISCBD+CP, data=columbus, listw, model="sarar", het=TRUE)
#LAG MODEL
SARrobust <- spreg(INC ~ HOVAL+DISCBD+CP, data=columbus, listw, model="lag", het=TRUE)
#going to my questions about the impacts function
#FOR SAC MODEL
W <- as(as_dgRMatrix_listw(listw), "CsparseMatrix")
Warning message:Function as_dgRMatrix_listw moved to the spatialreg package
trMatc <- trW(W, type="mult")
Warning message:
Function trW moved to the spatialreg package
effects<- summary(impacts(SAC.robust, tr=trMatc, R=10000), zstats=TRUE, short=TRUE)
effects
that didn’t create problems for me and the simulations follow:
========================================================
Simulation results (GSTSLS variance matrix):
#FOR SAR MODEL
effects<- summary(impacts(SARrobust, tr=trMatc, R=10000), zstats=TRUE, short=TRUE)
that gives me:
Error in UseMethod("impacts", obj) :
no applicable method for 'impacts' applied to an object of class "c('sphet', 'stsls_sphet')".
So, the impacts are not computable.
#One way to compute the impacts is by:
effects<- summary(spatialreg::impacts(SARrobust, tr=trMatc, R=10000), zstats=TRUE, short=TRUE)
effects
But now, the simulation follow:
========================================================
Simulation results (IV HAC variance matrix):
(which left me confused because I did not specify such an attribute in my regression, leaving me in doubt if the standard errors of the regression had also been corrected with HAC.) The same occurs using:
effects<- summary(spatialreg::impacts.stsls(SARrobust, tr=trMatc, R=10000), zstats=TRUE, short=TRUE)
effects.
Through R-sig-Geo I had the advice to use
remotes::install_github("gpiras/sphet")
effects<- impacts(SAC.robust, tr=trMatc, n_mvn=10000, inference=TRUE)
summary(effects)
effects <- impacts(SARrobust, tr=trMatc, n_mvn=10000, inference=TRUE)
summary(effects)
Could you inform me if the updates made and this way of computing the impacts have corrected the impacts and about the IV HAC question.
Thank you. Sorry I expressed something wrong or if I made a mistake.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.