[R] spdep question

Roger Bivand Roger.Bivand at nhh.no
Tue May 4 17:52:48 CEST 2004


On Tue, 4 May 2004, Christian Hennig wrote:

> Dear list,
> 
> (also sent to Roger Bivand, but perhaps somebody of you can help me also)
> 
> I am trying to use package spdep for fitting an SAR model with errorsarlm.
> However, I am not sure how to make a valid nb object out of my
> neighborhood. As far as I have seen, there is no documentation for
> nb.object.
> 

Well, there is always the code ... if you look at tri2nb(), there may be 
some ideas you can use to construct an "nb" object that is recognised as 
such. If you attach me a saved copy of your object, I'll take a look. What 
does str(pschmid$nb) say? Does that look the same as the examples in 
spdep? 

> I have done the following:
> 
> class(pschmid$nb) <- "nb"
> # pschmid is a prab object as generated from function prabinit, package
> # prabclus, and the neighborhood looks as follows:
> > unclass(pschmid$nb)
> [[1]]
>  [1]  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
> 
> [[2]]
>  [1]  1  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
> 
> [[3]]
>  [1]  1  2  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
> 
> (...and so on, a list of 65 integer vectors, up to...)
> 
> [[65]]
>  [1] 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
> 60 61
> [26] 62 63 64
> 
> # This looks more or less like the example (cal.gol.nb), apart from some
> # attribs which I do not understand, and it is exactly
> # how an nb object is described in help(read.gal). But...
> 
> > summary(pschmid$nb)
> Neighbour list object:
> Number of regions: 65 
> Number of nonzero links: 0 
> Percentage nonzero weights: 0 
> Average number of links: 0 
> 65 regions with no links:
> 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 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 55 56 57 58 59 60 61 62 63 64 65
> Link number distribution:
> 
>  0 
> 65 
> 
> # Why are there no links? Do I understand properly what a link is?
> # 1 is a neighbor of 2 and vice versa, so I consider them linked?
> 
> Can somebody tell me how to turn my neighborhood into an object errorsarlm
> and nb2listw (do I need that?) can handle!
> 
> Best,
> Christian
> 
> ***********************************************************************
> Christian Hennig
> Fachbereich Mathematik-SPST/ZMS, Universitaet Hamburg
> hennig at math.uni-hamburg.de, http://www.math.uni-hamburg.de/home/hennig/
> #######################################################################
> ich empfehle www.boag-online.de
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> 

-- 
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-help mailing list