[R-sig-Geo] problems with dnearneigh of spdep

Roger Bivand Roger.Bivand at nhh.no
Fri Oct 29 19:01:55 CEST 2004


On Fri, 29 Oct 2004, Stephane DRAY wrote:

> Hello,
> I have some strange results with the dnearneigh function.
> I would like to have all points of grid linked. I do something like that:
> 
>  > xy=expand.grid(1:10,1:10)
>  > mydnn=dnearneigh(as.matrix(xy),d1=0,d2=50)
>  > mydnn
> Neighbour list object:
> Number of regions: 100
> Number of nonzero links: 9896
> Percentage nonzero weights: 98.96
> Average number of links: 98.96
> I assume to have 100*100-100=9900 links.
> 
>  > m01=nb2mat(mydnn,style="B")
>  > apply(m01,1,sum)
>    1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18 
> 19  20  21  22  23  24  25  26  27
>   98  99  99  99  99  99  99  99  99  98  99  99  99  99  99  99  99  99 
> 99  99  99  99  99  99  99  99  99
>   28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45 
> 46  47  48  49  50  51  52  53  54
>   99  99  99  99  99  99  99  99  99  99  99  99  99  99  99  99  99  99 
> 99  99  99  99  99  99  99  99  99
>   55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72 
> 73  74  75  76  77  78  79  80  81
>   99  99  99  99  99  99  99  99  99  99  99  99  99  99  99  99  99  99 
> 99  99  99  99  99  99  99  99  99
>   82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100
>   99  99  99  99  99  99  99  99  99  98  99  99  99  99  99  99  99  99  98
> 
> It seems that the first and the last points are not linked. I have choose a 
> value of d2 very high, and the distance between this two points is only 
> sqrt(162)

I can't replicate this:

> version
         _                
platform i686-pc-linux-gnu
arch     i686             
os       linux-gnu        
system   i686, linux-gnu  
status                    
major    2                
minor    0.0              
year     2004             
month    10               
day      04               
language R                
> library(spdep)
> spdep()
[1] "spdep, version 0.2-22, 2004-08-07"
> xy=expand.grid(1:10,1:10)
> mydnn=dnearneigh(as.matrix(xy),d1=0,d2=50)
> mydnn
Neighbour list object:
Number of regions: 100 
Number of nonzero links: 9900 
Percentage nonzero weights: 99 
Average number of links: 99 

The line "Number of nonzero links:" is calculated as:

> sum(card(mydnn))
[1] 9900

You can also look at:

> all(sapply(mydnn, length) == 99)
[1] TRUE
> which(sapply(mydnn, length) != 99)
numeric(0)

if you want to be sure it isn't card() getting it wrong. Puzzling. I don't 
think any of the relevant code has changed since September 2003.

Roger

> 
> Any ideas ?
> Thanks
> Stéphane DRAY
> -------------------------------------------------------------------------------------------------- 
> 
> Département des Sciences Biologiques
> Université de Montréal, C.P. 6128, succursale centre-ville
> Montréal, Québec H3C 3J7, Canada
> 
> Tel : (514) 343-6111 poste 1233         Fax : (514) 343-2293
> E-mail : stephane.dray at umontreal.ca
> -------------------------------------------------------------------------------------------------- 
> 
> Web                                          http://www.steph280.freesurf.fr/
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: Roger.Bivand at nhh.no




More information about the R-sig-Geo mailing list