A question about the splm package

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

A question about the splm package

Danlin Yu
Dear list:

I hope this email finds you all well.

I've been recently using the spml package to estimate my data sets for
spatial panel analysis. During the process of applying the package, I made
a few mistakes and realized that when I was supplying the weight matrix
(through the listw object) to the spml/spgm routines, there is no check or
guarantee that the order of the spatial objects as represented in the listw
object is exactly the same as the order of the spatial objects in the data
set as supplied by the argument data = (please let me know if I was wrong
here).

I made such a mistake the first time when I was using the spml/spgm
routines, and found that when I used the pdata.frame routine to convert my
panel data to plm agreeable format (I suspect even if I didn't do that, it
will get converted within the routines), the order of the spatial object
gets re-ordered based on their alphabetic order of the "name" item supplied
to the "index" argument, but the listw was still in the order as it was
created based on the original order of the map object (the
SpatialPolygonDataFrame).

I tried to make some work around, but I can not be 100% sure if what I did
was right, so I am writing to ask for your advice.

Here is what I did:

#for a listw object, say w.listw, I changed it to a weight matrix using
listw2mat:

w.wmat <-listw2mat(w.listw)

#I then assign the names of the spatial objects that correspond to each row
and column to the weight matrix:

colnames(w.wmat)<-colnames(spatialObject@data$Name)
rownames(w.wmat)<-colnames(spatialObject@data$Name)

#I then re-order the weight matrix to make sure the order of the spatial
objects in the new weight matrix is ordered alphabetically:

w.wmat <- w.wmat[order(rownames(w.wmat)),]
w.wmat<- w.wmat[,order(colnames(w.wmat))]

#And then I either supply this weight matrix to the spml/spgm routines or
change it back to a listw object and supply it to the routines:

w.listw<-mat2listw(w.wmat)

After I've done that the outputs from the routines are different from if I
didn't do it. But I am not entire sure if I did this correctly or maybe I
am missing something.

Thank you in advance.

Best,

Danlin Yu, Ph.D.
Professor of GIS and Urban Geography
Department of Earth & Environmental Studies
Montclair State University
Montclair, NJ, 07043
Tel: 973-655-4313
Fax: 973-655-4072
Office: CELS 314
Email: [hidden email]
webpage: csam.montclair.edu/~yu

        [[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: A question about the splm package

Roger Bivand
Administrator
On Sun, 2 Sep 2018, Danlin Yu wrote:

> Dear list:
>
> I hope this email finds you all well.
>
> I've been recently using the spml package to estimate my data sets for
> spatial panel analysis. During the process of applying the package, I made
> a few mistakes and realized that when I was supplying the weight matrix
> (through the listw object) to the spml/spgm routines, there is no check or
> guarantee that the order of the spatial objects as represented in the listw
> object is exactly the same as the order of the spatial objects in the data
> set as supplied by the argument data = (please let me know if I was wrong
> here).

Could you please provide a worked example with (built in?) data - such as
Produc with US states from the maps package? You'd have to work backwards,
using the maps and the data to create your input, then try to provoke the
problem.

Roger

>
> I made such a mistake the first time when I was using the spml/spgm
> routines, and found that when I used the pdata.frame routine to convert my
> panel data to plm agreeable format (I suspect even if I didn't do that, it
> will get converted within the routines), the order of the spatial object
> gets re-ordered based on their alphabetic order of the "name" item supplied
> to the "index" argument, but the listw was still in the order as it was
> created based on the original order of the map object (the
> SpatialPolygonDataFrame).
>
> I tried to make some work around, but I can not be 100% sure if what I did
> was right, so I am writing to ask for your advice.
>
> Here is what I did:
>
> #for a listw object, say w.listw, I changed it to a weight matrix using
> listw2mat:
>
> w.wmat <-listw2mat(w.listw)
>
> #I then assign the names of the spatial objects that correspond to each row
> and column to the weight matrix:
>
> colnames(w.wmat)<-colnames(spatialObject@data$Name)
> rownames(w.wmat)<-colnames(spatialObject@data$Name)
>
> #I then re-order the weight matrix to make sure the order of the spatial
> objects in the new weight matrix is ordered alphabetically:
>
> w.wmat <- w.wmat[order(rownames(w.wmat)),]
> w.wmat<- w.wmat[,order(colnames(w.wmat))]
>
> #And then I either supply this weight matrix to the spml/spgm routines or
> change it back to a listw object and supply it to the routines:
>
> w.listw<-mat2listw(w.wmat)
>
> After I've done that the outputs from the routines are different from if I
> didn't do it. But I am not entire sure if I did this correctly or maybe I
> am missing something.
>
> Thank you in advance.
>
> Best,
>
> Danlin Yu, Ph.D.
> Professor of GIS and Urban Geography
> Department of Earth & Environmental Studies
> Montclair State University
> Montclair, NJ, 07043
> Tel: 973-655-4313
> Fax: 973-655-4072
> Office: CELS 314
> Email: [hidden email]
> webpage: csam.montclair.edu/~yu
>
> [[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.
voice: +47 55 95 93 55; e-mail: [hidden email]
http://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en

_______________________________________________
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