[R-sig-Geo] sarprobit question

Jorge Cárcamo jcarcamo03 at gmail.com
Thu Apr 21 10:37:18 CEST 2016


Good day everyone.

I have been trying to conduct a Spatial Autoregressive probit model in R.
To do so, I added the shapefile (points) that contains all my information
into R, and from it I constructed the spatial weighted matrix by specifying
k=3 nearest neighbors.
    tbe <- readShapePoints('tech_full.shp',
proj4string=CRS("+init=epsg:32719"))
    coortbe <- coordinates(tbe)
    col.knn1 <- knearneigh(coortbe, k=3)
    plot(knn2nb(col.knn1), coortbe, add=TRUE)
    neig <- knn2nb(col.knn1,row.names=tbe$Number)
    listw <- nb2listw(neig, style = "W")
    W <- as(as_dgRMatrix_listw(listw), "CsparseMatrix")

Until this point, R does not give me any warnings or error messages.
Immediately, I execute the following code to fit the spatial AR probit
model (package: 'spatialprobit')

    sarprobit.fit1 <- sarprobit(NV25 ~ SD46 + SD45 + PC18 + PC22 + SS13t +
Age + Gender + sra + sla + saa + uwue, data = tbe, W)

the following error appears:

>Error: Matrices must have same dimensions in .Arith.Csparse(e1, e2,
.Generic, class. = "dgCMatrix")*

Looking into W I found: i=306, p=103. Moreover, tbe has 102 observations.

I first thought that this p=103 was the error, however I did the following:

    wnew <-W[-1,]
    sarprobit.fit1 <- sarprobit(NV25 ~ SD46 + SD45 + PC18 + PC22 + SS13t +
Age + Gender + sra + sla + saa + uwue, data = tbe, wnew)

Now, the following error appears:

>Error in sar_probit_mcmc(y, X, W, ...) :
  sarprobit: spatial weights matrix W must be a sparse matrix with zeros in
the main diagonal

I tried other software, such as GeoDa. However, since my dependent variable
is binary, I did not found on it a proper model for my data.

My question is, did someone deal with this error? and if so, how did you
manage to solve it? I looked in google for this error but did not have any
luck.

Best,

Jorge

*Ing. Jorge Alfredo Cárcamo, M. Sc., Ph. D. (c)*

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list