[R-sig-Geo] sarprobit question
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]] ___ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Re: [R-sig-Geo] sarprobit question
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.go...@uclm.es> wrote: > Hi, > > > I first thought that this p=103 was the error, however I did the > following: > > > >wnew <-W[-1,] > > 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 > > [[alternative HTML version deleted]] ___ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Re: [R-sig-Geo] sarprobit question
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.go...@uclm.es> wrote: > Dear Jorge, > > > > > I will take a look at the commands to understand why is creating this > W=103x103 matrix. Do you have some suggestions? > > > > You probably have 103 points instead of 102 for some reason… That is what > I would check first. > > Best, > > Virgilio > > [[alternative HTML version deleted]] ___ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
[R-sig-Geo] Question impacts lagged independent variables lagsarlm
Dear all, I am working with a lagsarlm "mixed" model I executed: library(spdep) library(coda) dsts15 <- nbdists(nbs15, data.xy) idw15 <- lapply(dsts15, function(x) 1/(x)) sy15 <- nb2listw(nbs15, glist=idw15, style="W") mod.sdm.15<-lagsarlm(AR32 ~ SD46 + Totaland + PC18 + PC22 + sra + sla + saa + owue + yearrain + yearfdi, data=data, listw=sy15, type="mixed", tol.solve=1.0e-12) summary(mod.sdm.15) And got following results (abridged table): Estimate Std. Error z value Pr(>|z|) (Intercept) 1.4255019 0.4824828 2.9545 0.003132 SD46 0.0149057 0.0116146 1.2834 0.199365 Totaland -0.0217556 0.0072475 -3.0018 0.002684 ... yearrain 0.0557373 0.0485612 1.1478 0.251062 yearfdi -0.0109979 0.0069536 -1.5816 0.113741 lag.SD46 0.0262273 0.0278045 0.9433 0.345539 lag.Totaland 0.0060992 0.0141515 0.4310 0.666474 ... lag.yearrain -0.2083118 0.0772751 -2.6957 0.007024 lag.yearfdi 0.0111460 0.0081562 1.3666 0.171761 Rho: -0.54702, LR test value: 10.052, p-value: 0.0015215 Immediatly, I exectued impacts(mod.sdm.15, R=1000), to get the impacts: Direct Indirect Total SD46 0.013136761 0.013451739 0.0265884995 Totaland -0.023517332 0.013397014 -0.0101203177 ... yearrain 0.079110119 -0.177734631 -0.0986245121 yearfdi -0.012677636 0.012773412 0.957761 Through simulation I manage to get credible intervals for direct, indirect and total impacts (HPDinterval(impacts, choice="XXX")). However, how can I get the impacts of the lagged variables? I have seen some publications such as: Läpple, D., & Kelley, H. (2014). Spatial dependence in the adoption of organic drystock farming in Ireland. That report a posterior mean and credible intervals for the lagged variables. All suggestions are welcome. Best regards, *Ing. Jorge Alfredo Cárcamo, M. Sc., Ph. D. (c)* Agriculture economics Georg-August-Universität Göttingen [[alternative HTML version deleted]] ___ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Re: [R-sig-Geo] Question impacts lagged independent variables lagsarlm
Prof. Bivand, Many thanks for your clarification. I think that I should read Läpple & Kelley again. One more question, I assume that if I create independent lag variables with: data$w_xxx <- lag.listw(sy15,data$xxx) and add them into the model I can get the impacts of these lag variables; however, if I add them into the model, do I need to change the type="lag" instead of "mixed" when running lagsarlm command? Many thanks for your attention. Jorge *Ing. Jorge Alfredo Cárcamo, M. Sc., Ph. D. (c)* Agriculture economics Georg-August-Universität Göttingen On Sun, Jun 5, 2016 at 2:17 PM, Roger Bivand wrote: > On Sat, 4 Jun 2016, Jorge Cárcamo wrote: > > Dear all, >> >> I am working with a lagsarlm "mixed" model I executed: >> library(spdep) >> library(coda) >> dsts15 <- nbdists(nbs15, data.xy) >> idw15 <- lapply(dsts15, function(x) 1/(x)) >> sy15 <- nb2listw(nbs15, glist=idw15, style="W") >> mod.sdm.15<-lagsarlm(AR32 ~ SD46 + Totaland + PC18 + PC22 + sra + sla + >> saa >> + owue + yearrain + yearfdi, data=data, listw=sy15, type="mixed", >> tol.solve=1.0e-12) >> summary(mod.sdm.15) >> >> And got following results (abridged table): >> >> Estimate Std. Error z value Pr(>|z|) >> (Intercept) 1.4255019 0.4824828 2.9545 0.003132 >> SD46 0.0149057 0.0116146 1.2834 0.199365 >> Totaland -0.0217556 0.0072475 -3.0018 0.002684 >> ... >> yearrain 0.0557373 0.0485612 1.1478 0.251062 >> yearfdi -0.0109979 0.0069536 -1.5816 0.113741 >> lag.SD46 0.0262273 0.0278045 0.9433 0.345539 >> lag.Totaland 0.0060992 0.0141515 0.4310 0.666474 >> ... >> lag.yearrain -0.2083118 0.0772751 -2.6957 0.007024 >> lag.yearfdi 0.0111460 0.0081562 1.3666 0.171761 >> Rho: -0.54702, LR test value: 10.052, p-value: 0.0015215 >> >> Immediatly, I exectued impacts(mod.sdm.15, R=1000), to get the impacts: >> >> Direct Indirect Total >> SD46 0.013136761 0.013451739 0.0265884995 >> Totaland -0.023517332 0.013397014 -0.0101203177 >> ... >> yearrain 0.079110119 -0.177734631 -0.0986245121 >> yearfdi -0.012677636 0.012773412 0.957761 >> >> Through simulation I manage to get credible intervals for direct, indirect >> and total impacts (HPDinterval(impacts, choice="XXX")). >> > > As you must know from the references on the help page for impacts methods, > these are the combined impacts of the variables: > > S_r(W) = (I - \rho W)^{-1} (\beta_r I - \gamma_r W) > > where the direct impacts are sum(S_r(W))/n, etc. The \gamma_r are the > coefficients on W x_r. > > >> However, how can I get the impacts of the lagged variables? I have seen >> some publications such as: Läpple, D., & Kelley, H. (2014). Spatial >> dependence in the adoption of organic drystock farming in Ireland. That >> report a posterior mean and credible intervals for the lagged variables. >> > > Given the above, either you are misreading Läpple & Kelley (I do not have > access), or both you and they are wrong. There are by definition on > separable impacts for the lagged X variables. > > Hope this clarifies, > > Roger > > >> All suggestions are welcome. >> >> Best regards, >> >> *Ing. Jorge Alfredo Cárcamo, M. Sc., Ph. D. (c)* >> Agriculture economics >> Georg-August-Universität Göttingen >> >> [[alternative HTML version deleted]] >> >> ___ >> R-sig-Geo mailing list >> R-sig-Geo@r-project.org >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >> > > -- > Roger Bivand > Department of Economics, Norwegian School of Economics, > Helleveien 30, N-5045 Bergen, Norway. > voice: +47 55 95 93 55; fax +47 55 95 91 00 > e-mail: roger.biv...@nhh.no > http://orcid.org/-0003-2392-6140 > https://scholar.google.no/citations?user=AWeghB0J&hl=en > http://depsy.org/person/434412 [[alternative HTML version deleted]] ___ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Re: [R-sig-Geo] Question impacts lagged independent variables lagsarlm
Dear Prof. Bivand, Many thanks for your time and attention. I will do as you suggest. Best regards, Jorge On Jun 5, 2016 17:22, "Roger Bivand" wrote: > On Sun, 5 Jun 2016, Jorge Cárcamo wrote: > > Prof. Bivand, >> >> Many thanks for your clarification. I think that I should read Läpple & >> Kelley again. >> >> One more question, I assume that if I create independent lag variables >> with: data$w_xxx <- lag.listw(sy15,data$xxx) and add them into the model I >> can get the impacts of these lag variables; however, if I add them into >> the >> model, do I need to change the type="lag" instead of "mixed" when running >> lagsarlm command? >> > > Don't even think about this, it is senseless. The impact of x_r is as > given in the formula, the only contrast is between the impacts in the > model="lag" case and the model="mixed" case. Because of the interaction > between \rho and the \betas (and \gammas) in the y = \rho W y + ... models, > you only get one set of impacts per x_r per model. You can interprete the > differences between the three impact components between models, but avoid > playing with stuff without doing all of the maths first. > > Roger > > >> Many thanks for your attention. >> >> Jorge >> >> *Ing. Jorge Alfredo Cárcamo, M. Sc., Ph. D. (c)* >> Agriculture economics >> Georg-August-Universität Göttingen >> >> On Sun, Jun 5, 2016 at 2:17 PM, Roger Bivand wrote: >> >> On Sat, 4 Jun 2016, Jorge Cárcamo wrote: >>> >>> Dear all, >>> >>>> >>>> I am working with a lagsarlm "mixed" model I executed: >>>> library(spdep) >>>> library(coda) >>>> dsts15 <- nbdists(nbs15, data.xy) >>>> idw15 <- lapply(dsts15, function(x) 1/(x)) >>>> sy15 <- nb2listw(nbs15, glist=idw15, style="W") >>>> mod.sdm.15<-lagsarlm(AR32 ~ SD46 + Totaland + PC18 + PC22 + sra + sla + >>>> saa >>>> + owue + yearrain + yearfdi, data=data, listw=sy15, type="mixed", >>>> tol.solve=1.0e-12) >>>> summary(mod.sdm.15) >>>> >>>> And got following results (abridged table): >>>> >>>> Estimate Std. Error z value Pr(>|z|) >>>> (Intercept) 1.4255019 0.4824828 2.9545 0.003132 >>>> SD46 0.0149057 0.0116146 1.2834 0.199365 >>>> Totaland -0.0217556 0.0072475 -3.0018 0.002684 >>>> ... >>>> yearrain 0.0557373 0.0485612 1.1478 0.251062 >>>> yearfdi -0.0109979 0.0069536 -1.5816 0.113741 >>>> lag.SD46 0.0262273 0.0278045 0.9433 0.345539 >>>> lag.Totaland 0.0060992 0.0141515 0.4310 0.666474 >>>> ... >>>> lag.yearrain -0.2083118 0.0772751 -2.6957 0.007024 >>>> lag.yearfdi 0.0111460 0.0081562 1.3666 0.171761 >>>> Rho: -0.54702, LR test value: 10.052, p-value: 0.0015215 >>>> >>>> Immediatly, I exectued impacts(mod.sdm.15, R=1000), to get the impacts: >>>> >>>> Direct Indirect Total >>>> SD46 0.013136761 0.013451739 0.0265884995 >>>> Totaland -0.023517332 0.013397014 -0.0101203177 >>>> ... >>>> yearrain 0.079110119 -0.177734631 -0.0986245121 >>>> yearfdi -0.012677636 0.012773412 0.957761 >>>> >>>> Through simulation I manage to get credible intervals for direct, >>>> indirect >>>> and total impacts (HPDinterval(impacts, choice="XXX")). >>>> >>>> >>> As you must know from the references on the help page for impacts >>> methods, >>> these are the combined impacts of the variables: >>> >>> S_r(W) = (I - \rho W)^{-1} (\beta_r I - \gamma_r W) >>> >>> where the direct impacts are sum(S_r(W))/n, etc. The \gamma_r are the >>> coefficients on W x_r. >>> >>> >>> However, how can I get the impacts of the lagged variables? I have seen >>>> some publications such as: Läpple, D., & Kelley, H. (2014). Spatial >>>> dependence in the adoption of organic drystock farming in Ireland. That >>>> report a posterior mean and credible intervals for the lagged variables. >>>> >>>> >>> Given the above, either you are misreading Läpple & Kelley (I do not have >>> access), or both you and they are wrong. There are by definition on >>> separable impacts for the lagged X var