inconsistent results from moran.test()

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

inconsistent results from moran.test()

Jay Wang
Hello,

Having my own spatial weight matrix, I converted it to a listw format and
calculated the Moran index. The codes are listed below:

Wod_lw<-mat2listw(Wod)
moran.test(mydata$Ties_processed,Wod_lw, randomisation=TRUE)

However, after I generated a gal file, imported it, converted it back to a
listw file, and re-calculated the Moran index with the following codes, the
results became totally different (0.1624 vs. 0.1942):
write.nb.gal(Wod_lw$neighbours,"Wod.gal")
Wod.gal.nb <- read.gal(file="Wod.gal")
Wod_lw2<-nb2listw(Wod.gal.nb)
moran.test(mydata$Ties_processed,Wod_lw, randomisation=TRUE)
moran.test(mydata$Ties_processed,Wod_lw2, randomisation=TRUE)

I don't know where the problem is. I would appreciate if anyone can help me
with this. Thank you

        [[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: inconsistent results from moran.test()

Roger Bivand
Administrator
On Fri, 8 Mar 2019, Jay Wang wrote:

> Hello,
>
> Having my own spatial weight matrix, I converted it to a listw format and
> calculated the Moran index. The codes are listed below:
>
> Wod_lw<-mat2listw(Wod)
> moran.test(mydata$Ties_processed,Wod_lw, randomisation=TRUE)

Here, Wod_lw has an unknown style, "M" for matrix.

>
> However, after I generated a gal file, imported it, converted it back to a
> listw file, and re-calculated the Moran index with the following codes, the
> results became totally different (0.1624 vs. 0.1942):
> write.nb.gal(Wod_lw$neighbours,"Wod.gal")

This only writes the neighbours (read the help page), not the weights.

> Wod.gal.nb <- read.gal(file="Wod.gal")
> Wod_lw2<-nb2listw(Wod.gal.nb)

The default style in nb2listw() is "W", row standardised.

What does:

all.equal(Wod_lw$weights, Wod_lw2$weights, check.attributes=FALSE)

say? And:

all.equal(Wod_lw$neighbours, Wod_lw2$neighbours, check.attributes=FALSE)

> moran.test(mydata$Ties_processed,Wod_lw, randomisation=TRUE)
> moran.test(mydata$Ties_processed,Wod_lw2, randomisation=TRUE)
>
> I don't know where the problem is. I would appreciate if anyone can help me
> with this. Thank you

Do read the help pages, you'll find they explain these things.

Roger

>
> [[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]
https://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
Reply | Threaded
Open this post in threaded view
|

Re: inconsistent results from moran.test()

Jay Wang
It solved my problem. Thank you!

On Fri, Mar 8, 2019 at 2:25 PM Roger Bivand <[hidden email]> wrote:

> On Fri, 8 Mar 2019, Jay Wang wrote:
>
> > Hello,
> >
> > Having my own spatial weight matrix, I converted it to a listw format and
> > calculated the Moran index. The codes are listed below:
> >
> > Wod_lw<-mat2listw(Wod)
> > moran.test(mydata$Ties_processed,Wod_lw, randomisation=TRUE)
>
> Here, Wod_lw has an unknown style, "M" for matrix.
>
> >
> > However, after I generated a gal file, imported it, converted it back to
> a
> > listw file, and re-calculated the Moran index with the following codes,
> the
> > results became totally different (0.1624 vs. 0.1942):
> > write.nb.gal(Wod_lw$neighbours,"Wod.gal")
>
> This only writes the neighbours (read the help page), not the weights.
>
> > Wod.gal.nb <- read.gal(file="Wod.gal")
> > Wod_lw2<-nb2listw(Wod.gal.nb)
>
> The default style in nb2listw() is "W", row standardised.
>
> What does:
>
> all.equal(Wod_lw$weights, Wod_lw2$weights, check.attributes=FALSE)
>
> say? And:
>
> all.equal(Wod_lw$neighbours, Wod_lw2$neighbours, check.attributes=FALSE)
>
> > moran.test(mydata$Ties_processed,Wod_lw, randomisation=TRUE)
> > moran.test(mydata$Ties_processed,Wod_lw2, randomisation=TRUE)
> >
> > I don't know where the problem is. I would appreciate if anyone can help
> me
> > with this. Thank you
>
> Do read the help pages, you'll find they explain these things.
>
> Roger
>
> >
> >       [[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]
> https://orcid.org/0000-0003-2392-6140
> https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
>

        [[alternative HTML version deleted]]

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