[R-sig-Geo] nb2listw() in spdep fails, also errorsarlm() has problems

Roger Bivand Roger.Bivand at nhh.no
Mon Nov 12 18:24:49 CET 2007


And (acknowledging memory outage), I posted a note on the problem on:

http://www.sal.uiuc.edu/csiss/Rgeo/

on 9th October. Google on R 2.6.0 spdep break gets you there as first hit, 
R 2.6.0 spdep as third.

Roger


On Mon, 12 Nov 2007, Roger Bivand wrote:

> Quoting Prof. Brian Ripley's reply on R-help, refering to:
>
> https://stat.ethz.ch/pipermail/r-help/2007-October/142367.html
>
> the problem is likely to be the spdep dependency on Matrix, which should
> be handled as described in the message.
>
> Roger
>
> On Mon, 12 Nov 2007, Roger Bivand wrote:
>
>> On Mon, 12 Nov 2007, Alun Pope wrote:
>>
>>> Further to my post below, the function nb2listw() works if the mode is
>>> coerced to "integer" rather than "numeric" (two places).
>>>
>>
>> No, glist should be numeric or double, not integer - those are the only
>> two mode()<- calls in nb2listw().
>>
>>>
>>>
>>> However the line
>>>
>>>
>>>
>>> can.sim <- as.logical(NA)
>>>
>>>
>>>
>>> in errorsarlm() fails with the error message
>>>
>>>
>>>
>>> Error in UseMethod("as.logical") : no applicable method for
>>> "as.logical".
>>>
>>
>> Almost certainly your system is broken, with a fresh version of R and a
>> stale version of the methods package somewhere in a library on .libPaths()
>>
>> Roger
>>
>>>
>>>
>>> It seems that as.logical(NA) is the culprit here, but I do not
>>> understand how to fix this one.  I would be grateful for a quick fix.
>>> Thanks a lot.
>>>
>>>
>>>
>>> Alun
>>>
>>>
>>>
>>> ________________________________
>>>
>>> From: r-sig-geo-bounces at stat.math.ethz.ch
>>> [mailto:r-sig-geo-bounces at stat.math.ethz.ch] On Behalf Of Alun Pope
>>> Sent: Monday, 12 November 2007 5:18 PM
>>> To: r-sig-geo at stat.math.ethz.ch
>>> Subject: [R-sig-Geo] nb2listw() in spdep fails
>>>
>>>
>>>
>>> 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.
>>>
>>>
>>>
>>>
>>>
>>>
>>
>>
>
>

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