[R-sig-Geo] nb2listw() in spdep fails

Alun Pope AlunPope at rismark.com.au
Mon Nov 12 07:18:29 CET 2007


Running the latest version of spdep ("spdep, version 0.4-9, 2007-11-01")
I find that code that previously worked no longer does after updating R
to the latest release (2.6.0). 

 

The following example illustrates:

> dataex

       long       lat

1  151.1550 -33.88602

2  151.1922 -33.89780

3  151.1733 -33.91631

4  151.2042 -33.92947

5  151.1854 -33.87928

6  151.2355 -33.92529

7  151.1768 -33.91153

8  151.2352 -33.94703

9  151.2561 -33.93978

10 151.2316 -33.95854

> ngh.listex <-  knearneigh(cbind(dataex$long,dataex$lat), k=2, longlat
= TRUE)

> ngh.listex

$nn

      [,1] [,2]

 [1,]    5    7

 [2,]    7    5

 [3,]    7    2

 [4,]    6    3

 [5,]    2    1

 [6,]    8    9

 [7,]    3    2

 [8,]   10    9

 [9,]    8    6

[10,]    8    9

 

$np

[1] 10

 

$k

[1] 2

 

$dimension

[1] 2

 

$x

          [,1]      [,2]

 [1,] 151.1550 -33.88602

 [2,] 151.1922 -33.89780

 [3,] 151.1733 -33.91631

 [4,] 151.2042 -33.92947

 [5,] 151.1854 -33.87928

 [6,] 151.2355 -33.92529

 [7,] 151.1768 -33.91153

 [8,] 151.2352 -33.94703

 [9,] 151.2561 -33.93978

[10,] 151.2316 -33.95854

 

attr(,"class")

[1] "knn"

attr(,"call")

knearneigh(x = cbind(dataex$long, dataex$lat), k = 2, longlat = TRUE)

> nb.listex <- knn2nb(ngh.listex,sym=TRUE)

> nghwts.listex <- nb2listw(nb.listex,style="U")

Error in UseMethod("as.double") : no applicable method for "as.double"

 

 

The function nb2listw() in spdep contains statements of the form

 

    mode(x) <- "numeric" 

 

which I assume is what is causing that function to fail with the error
message above.  

 

 

I think this because it seems (to me) that this is caused by the change
to the behaviour of as.numeric() in the latest R release, when applied
to vectors of mode "integer".  Here is an example which illustrates
behaviour that appears odd to me:

 

> x1

[1] 1 2 3 4 4 4 4

> mode(x1)

[1] "numeric"

> as.numeric(x1)

Error in UseMethod("as.double") : no applicable method for "as.double"

> is.numeric(x1)

[1] TRUE

 

I have posted separately to the R-help mailing list.

 

I don't know if this ought to be a bug report, sorry.

 

Alun

 

 

 

Dr Alun Pope

 

Research Manager

Rismark International

 

For more on Equity Finance Mortgages*:

See www.efm.info <http://www.efm.info/> 

 

 

 

Level 13 | 50 Margaret Street

Sydney | NSW 2000 | Australia

T +61 (0)2 8243 0656

F +61 (0)2 9290 3703

M +61 (0)412 115 028

E alun.pope at rismark.com.au

W www.rismark.com.au

 

*Best New Product of the Year in the 2007 Your Mortgage Magazine
Mortgage of the Year Competition.

 

This email is strictly confidential. If you are not the intended
recipient you must not disclose or use the information contained in it.
If you have received this email in error please notify us immediately by
return email and delete the document. Failure to comply with this
request could invoke severe legal penalties.

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20071112/efa37584/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 7920 bytes
Desc: image001.gif
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20071112/efa37584/attachment.gif>


More information about the R-sig-Geo mailing list