[R-sig-Geo] Question about HSAR package

Justin Schon j@chon7 @ending from gm@il@com
Thu Sep 27 22:08:56 CEST 2018


Ok, it's helpful to know that I need to zoom in on those three things.

I created the Random Effects Matrix by hand in Excel, so I read that into R
and put the matrix into the format recommended here:
https://cran.r-project.org/web/packages/HSAR/vignettes/hsar.html

Below, I show how I made W, M, and Delta.mat, before I try to estimate the
model. Hopefully this helps.


constit<- readShapeSpatial("Population
Weighted/Constituencies_2008/20170209_Constit")
constit.nb<- poly2nb(constit, row.names = constit$X20160526_5)
ghana.constit.weights.binary<- nb2listw(constit.nb, style="B", zero.policy
= TRUE)

W.constit<- listw2mat(ghana.constit.weights.binary)
W.constit <- W.constit / rowSums(W.constit)
W.constit <- as(W.constit,"dgCMatrix")


dist2008<- readShapeSpatial("Population Weighted/Districts_2008/Volta
Variable/20170226_Districts")
dist2008.nb<- poly2nb(dist2008, row.names = dist2008$DIST_2008)
ghana.dist2008.weights.binary<- nb2listw(dist2008.nb, style="B",
zero.policy=T)

W.dist<- listw2mat(ghana.dist2008.weights.binary)
W.dist <- W.dist / rowSums(W.dist)
W.dist <- as(W.dist,"dgCMatrix")


Delta<- read.csv("Random Effects Matrix_Ghana.csv",
                 header = T, row.names = 1)
Delta.mat<- as.matrix(Delta)
Delta.mat <- as(Delta.mat,"dgCMatrix")


> HSAR.model1<- hsar(Count_ ~ ndc_pres_3
+                    + volatility + turnout_21
+                    + volatili_1 + X20160526_6
+                    + DENSITY_RD + Count_3
+                    + MEAN + pov_p_2008
+                    + gini_2008 + ferat_2008
+                    + Count_4 + literacy
+                    + grid_perCa, data=constit, W=W.constit,
+                    M=W.dist, Delta = Delta.mat,
+                    burnin = 5000, Nsim = 10000,
+                    thinning = 1, parameters.start = NULL)
Error in hsar(Count_ ~ ndc_pres_3 + volatility + turnout_21 + volatili_1 +
:
  not an S4 object







On Thu, Sep 27, 2018 at 3:57 PM Roger Bivand <Roger.Bivand using nhh.no> wrote:

> This code tells nothing, the problem is in your construction of W, M
> and/or Delta. Pleaseng show this code too, best as a reproducible example.
> Tip: sometimes running traceback() after an error shows where it happens.
>
> Roger Bivand
> Norwegian School of Economics
> Bergen, Norway
>
> Fra: Justin Schon
> Sendt: torsdag 27. september, 21.36
> Emne: [R-sig-Geo] Question about HSAR package
> Til: r-sig-geo using r-project.org
>
>
> Dear all, I am receiving the error "not an S4 object" when I attempt to
> estimate the hierarchal spatial auto-regressive model from the HSAR
> package. I have attempted several ways of creating the lower level matrix
> and higher level matrix. Rather than asking if members of this list can
> help with the code, I am first wondering if anyone can explain why this
> error would appear. I am including the code that estimates the model, as
> well as the error, below: > HSAR.model1
>


-- 
Justin Schon
Post-Doctoral Researcher on Environmental Change and Migration
MURI Migration Research Team: http://murimigration.org/
University of Florida
Fellow, Initiative for Sustainable Energy Policy (ISEP)

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list