[R] Bug in lowess

Frank E Harrell Jr f.harrell at vanderbilt.edu
Thu Oct 12 15:02:40 CEST 2006


Prof Brian Ripley wrote:
> On Thu, 12 Oct 2006, Gavin Simpson wrote:
> 
>> On Wed, 2006-10-11 at 22:29 -0500, Frank E Harrell Jr wrote:
>>> x <- c(0,7,8,14,15,120,242)
>>> y <- c(122,128,130,158,110,110,92)
>>>
>>> lowess(x,y)
>>>
>>> $x
>>> [1]   0   7   8  14  15 120 242
>>>
>>> $y
>>> [1]   122.0000   128.0000   132.2857   158.0000   110.0000 -4930.0000
>>> 110.0000
>>
>> Same behaviour here on a more recent R (below), and I recall a posting
>> for a year or so back that reported similar behaviour in the then
>> current version of R.
> 
> Actually, it is system-dependent as I get (on x86_64)
> 
>> lowess(x,y, iter=3)
> lowess(): ns = 4
>    cmad =      0.25589
>    cmad =            0
>    cmad =   0.00583385
> $x
> [1]   0   7   8  14  15 120 242
> 
> $y
> [1] 128.0000 128.0000 132.2857 158.0000 110.0000 109.9990 110.0000
> 
> having turned DEBUG_lowess on.  So the issue is finite-precision 
> arithmetic, once again.
> 
> It seems rather a moot point as to what the right answer actually is 
> here, and even if that found by Frank is indeed wrong, as lowess() is 
> defined by an algorithm.  Perhaps the best one can hope for is a good 
> approximation to what the algorithm would give in infinite-precision 
> arithmetic (having defined what should happen if cmod is zero).
> 

Thank you Brian.  It seems that no matter what is the right answer, the 
answer currently returned on my system is clearly wrong.  lowess()$y 
should be constrained to be within range(y).

lowess(x,y,iter=0) provides a reasonable solution in this case; I just 
don't know how to automatically force iter=0.

Frank

-- 
Frank E Harrell Jr   Professor and Chair           School of Medicine
                      Department of Biostatistics   Vanderbilt University



More information about the R-help mailing list