Skip to content

sarprobit question

6 messages · Virgilio Gomez Rubio, Jorge Cárcamo

#
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:
.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:
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)*
#
Hi,
You need to remove one row AND one column to have a 102x102 matrix. In the code above you are just removing one row. I believe that the error is there. But you should check why you W is 103x103 if you only have 102 data points?

Best,

Virgilio
#
Dear Virgilio,

Thank you very much for your answer. Effectively, your observation is
correct, after I drop a column the command works.

I will take a look at the commands to understand why is creating this
W=103x103 matrix. Do you have some suggestions?

Once again, thank you very much for your quick reply.

Best,

Jorge

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


On Thu, Apr 21, 2016 at 4:58 PM, VIRGILIO GOMEZ RUBIO <
Virgilio.Gomez at uclm.es> wrote:

            

  
  
#
Hi,
Please, note that dropping the column will give you a 102x102 but, as Obi-Wan Kenobi would say, "this is not the matrix you are looking for?. :) What I mean is that you probably will get a wrong adjacency matrix. :)
If you provide a reproducible example (i.e., code plus data) I could look into it. Feel free to contact me off list.

Best,

Virgilio
3 days later
#
Dear Jorge,
You probably have 103 points instead of 102 for some reason? That is what I would check first.

Best,

Virgilio
#
Dear Virigilio,

Many thanks for your suggestion. I also think that my problem is within my
data and not with my commands. I used the same commands with the columbus
dataset and it run smoothly. The only difference is that columbus dataset
are polygons and I am working with point dataset. The funny thing is that a
friend of mine give me another point dataset, when I tried to run the
commands it gives me the same error message, even if I drop one column and
one row.

I will prepare a subset of this dataset and the script to reproduce the
commands. However, I am hoping to do that this week, since I have to
prepare and give a presentation tomorrow.

Once again, many thanks for your kind help and attention.

Jorge

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


On Tue, Apr 26, 2016 at 12:03 PM, VIRGILIO GOMEZ RUBIO <
Virgilio.Gomez at uclm.es> wrote: