Question about HSAR package

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Question about HSAR package

Justin Schon
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<- 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


Again, I am not looking for advice with the code right now. I am wondering
what kinds of problems could cause this error message.

As a note, I receive the same error message when I try to estimate an sar
model and when I simplify the model down to one independent variable.

I greatly appreciate any ideas that members of this list might have.

Thank you,

Justin





--
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]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Question about HSAR package

Roger Bivand
Administrator
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: [hidden email]


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

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway
Reply | Threaded
Open this post in threaded view
|

Re: Question about HSAR package

Justin Schon
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 <[hidden email]> 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: [hidden email]
>
>
> 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]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo