[R-sig-Geo] FW: [R-sig-Epi] problem with nb2listw( ) command
Roger Bivand
Roger.Bivand at nhh.no
Sun Apr 27 15:17:20 CEST 2014
Do not write to multiple lists at the same time - nobody not on both lists
will know whether the question has been answered.
Always provide simple reproducible code.
See below inline for answer:
On Sun, 20 Apr 2014, irum Amir wrote:
>
>
>> From: imirum_amir at hotmail.com
>> To: r-sig-epi at r-project.org
>> Date: Sun, 20 Apr 2014 09:23:14 +0000
>> Subject: [R-sig-Epi] problem with nb2listw( ) command
>>
>>
>> Dear all I am using scottish lip cancer data, which contains the
>> columns of observed, expected, AFF(person at risk) and latitude and
>> longitude. i use the commands
>>
>
>> nc<-combine.data.shapefile(data=scotland,shp=shp,dbf=dbf)
>> ###CARBayes package
>
This function is rather confusing and probably not a good idea here - see
PS below.
>> W.nb<-poly2nb(nc=scotland,row.names=rownames(scotland)) ### spdep
>> package
>>
>> > W.nb
>> Out put is
>>
>> Neighbour
>> list object:
>>
>>
>> Number of
>> regions: 56
>>
>>
>> Number of
>> nonzero links: 234
>>
>>
>> Percentage
>> nonzero weights: 7.461735
>>
>>
>> Average
>> number of links: 4.178571
>>
>>
>> 3 regions
>> with no links:
>>
^^^^^^^^^^^^^^^^^^^^
Please always read the output you see - your use of poly2nb created three
no-neighbour regions,
>>
>> 6554 6655 6756
^^^^^^^^^^^^^^^^^^^^
these.
>>
>>
>> > col.W<-nb2listw(W.nb,style="B",zero.policy=TRUE)
>>
>>
You use zero.policy=TRUE to get round the problem you yourself created
here, but then forget to continue to do the same in print.listw() and
moranI.test().
If you really want regions with no neighbours, you must use
zero.policy=TRUE everwhere - because usually you are advised not to
generate such neighbour objects (the theoretical properties of tests etc.
were developed for graphs with all regions connected.
If you read ?set.ZeroPolicyOption in spdep, you can see how to set the
option to TRUE globally as an option for your current session. Only use
this if you understand the consequences and wish to accept the risk that
the methods do not behave as expected.
Hope this clarifies,
Roger
PS. The boundaries in the scot_BNG shapefile in rgdal (see examples in
readOGR) include small slivers securing contiguity across water (spotted
by Barry Rowlingson, derived from an unprojected shapefile on Lance
Waller's website), and the data you are trying to analyse. This is also
used in Bivand et al. (2013), see:
http://www.asdar-book.org/bundles2ed/die_bundle.zip, and:
http://www.asdar-book.org/book2ed/die_mod.R chunks 31-46.
>> > col.W
>>
>>
>> which gives out put
>> Error in
>> print.listw(list(style = "B", neighbours = list(c(5L, 9L, 19L : regions with no neighbours found, use zero.policy=TRUEwhen i use the command
>>> moranI.test(Observed~AFF+offset(log(Expected)),
>> as(nc, "data.frame"), "negbin", 999,
>>
>>
>> listw=col.W, n=length(W.nb), S0=Szero(col.W)
>> )
>>
>>
>> Moran's I test of
>> spatial autocorrelation
>>
>>
>> Type of boots.: parametric
>>
>> Model used when sampling: Negative
>> Binomial
>>
>> Number of simulations: 999
>> Statistic: NA
>> p-value : NA
>> please help if any body has an idea.
>>
>>
>>
>> There were 50 or more warnings (use
>> warnings() to see the first 50)
>>
>>
>>
>> [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Epi at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-epi
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at 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.Bivand at nhh.no
More information about the R-sig-Geo
mailing list