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

Roger Bivand Roger.Bivand at nhh.no
Mon Nov 12 13:11:26 CET 2007


On Mon, 12 Nov 2007, Alun Pope wrote:

> 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).
>

Thank you for your report. Please also state your platform, for example 
the output of sessionInfo(). I have tried to reproduce the error on:

> sessionInfo()
R version 2.6.0 (2007-10-03)
i386-pc-mingw32

locale:
LC_COLLATE=Norwegian (Bokmål)_Norway.1252;LC_CTYPE=Norwegian 
(Bokmål)_Norway.1252;LC_MONETARY=Norwegian 
(Bokmål)_Norway.1252;LC_NUMERIC=C;LC_TIME=Norwegian (Bokmål)_Norway.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] spdep_0.4-9       Matrix_0.999375-3 lattice_0.17-2    boot_1.2-30
[5] maptools_0.6-19   foreign_0.8-23    sp_0.9-17         tripack_1.2-11

loaded via a namespace (and not attached):
[1] grid_2.6.0
>

without finding any errors. I will replace mode()<- calls with 
storage.mode()<- calls, but I don't think that this is the problem.

Best wishes,

Roger

>
>
> 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.
>
>
>
>
>
>

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


More information about the R-sig-Geo mailing list