[R] R loess vs. Matlab loess

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Jan 30 16:17:01 CET 2008

On Wed, 30 Jan 2008, Stuart Leask wrote:

> hits=-2.6 tests=BAYES_00
> X-USF-Spam-Flag: NO
> Hi there.
> Some years ago, I was trying to get loess to behave like lowess, so I could
> repeat some old analyses but 'predict.loess' into some reference data (R
> lowess and loess have different defaults).
> loess(X~Y,span=sp, family=("symmetric"), degree=2)
> seemed pretty much the same as lowess - I think someone on this list made
> the suggestion.
> I have a colleague that is trying to replicate some findings in Matlab. We
> were getting different results, and have determined that Matlab loess
> parameters are different too (see below a description on the Matlab
> smoothing function).
> It seems to come down to the fact that R loess uses a 're-descending M
> estimator', since family = ("symmetric").
> Can anyone suggest whether/how the Matlab SMOOTH can replicate this?
> (Or even just describe what a re-descending M estimator does!)

I suspect that you want 'rloess', but why don't you ask on a Matlab list 
(or as part of a support contract)?

The reference on the R help page will explain what the R function does, 
including what family="symmetric" means.  (But any good book on 
robust statistics, including MASS, would explain what those terms mean.)

> I know, a health warning has to surround results that are differing a lot
> simply due to exact parameters used, but it would be nice to confirm/deny
> the lines are looking different for this reason.

Or even the algorithms used.  Loess is just an algorithm (it does not 
optimize anything explicit), and we know that it is not a very stable one, 
especially when iterations are used.

> Dr Stuart J Leask DM MRCPsych MA BChir
> Senior Lecturer and Honorary Consultant in Clinical Psychiatry
> University Dept of Psychiatry, Duncan Macmillan House
> Porchester Road. Nottingham. NG3 6AA.
> www: Google "Dr Stuart Leask"
> **************************************************************
> 'SMOOTH  Smooth data.
>   Z = SMOOTH(Y) smooths data Y using a 5-point moving average.
>   Z = SMOOTH(Y,SPAN) smooths data Y using SPAN as the number of points used
>   to compute each element of Z.
>   Z = SMOOTH(Y,SPAN,METHOD) smooths data Y with specified METHOD. The
>   available methods are:
>           'moving'   - Moving average (default)
>           'lowess'   - Lowess (linear fit)
>           'loess'    - Loess (quadratic fit)
>           'sgolay'   - Savitzky-Golay
>           'rlowess'  - Robust Lowess (linear fit)
>           'rloess'   - Robust Loess (quadratic fit)
>   Z = SMOOTH(Y,METHOD) uses the default SPAN 5.
>   Z = SMOOTH(Y,SPAN,'sgolay',DEGREE) and Z = SMOOTH(Y,'sgolay',DEGREE)
>   additionally specify the degree of the polynomial to be used in the
>   Savitzky-Golay method. The default DEGREE is 2. DEGREE must be smaller
>   than SPAN.
>   Z = SMOOTH(X,Y,...) additionally specifies the X coordinates.  If X is
>   not provided, methods that require X coordinates assume X = 1:N, where
>   N is the length of Y.
>   Notes:
>   1. When X is given and X is not uniformly distributed, the default method
>   is 'lowess'.  The 'moving' method is not recommended.
>   2. For the 'moving' and 'sgolay' methods, SPAN must be odd.
>   If an even SPAN is specified, it is reduced by 1.
>   3. If SPAN is greater than the length of Y, it is reduced to the
>   length of Y.
>   4. In the case of (robust) lowess and (robust) loess, it is also
>   possible to specify the SPAN as a percentage of the total number
>   of data points. When SPAN is less than or equal to 1, it is
>   treated as a percentage.
>   For example:
>   Z = SMOOTH(Y) uses the moving average method with span 5 and
>   X=1:length(Y).
>   Z = SMOOTH(Y,7) uses the moving average method with span 7 and
>   X=1:length(Y).
>   Z = SMOOTH(Y,'sgolay') uses the Savitzky-Golay method with DEGREE=2,
>   SPAN = 5, X = 1:length(Y).
>   Z = SMOOTH(X,Y,'lowess') uses the lowess method with SPAN=5.
>   Z = SMOOTH(X,Y,SPAN,'rloess') uses the robust loess method.
>   Z = SMOOTH(X,Y) where X is unevenly distributed uses the
>   'lowess' method with span 5.
>   Z = SMOOTH(X,Y,8,'sgolay') uses the Savitzky-Golay method with
>   span 7 (8 is reduced by 1 to make it odd).
>   Z = SMOOTH(X,Y,0.3,'loess') uses the loess method where span is
>   30% of the data, i.e. span = ceil(0.3*length(Y)).'
> This message has been checked for viruses but the contents of an attachment
> may still contain software viruses, which could damage your computer system:
> you are advised to perform your own checks. Email communications with the
> University of Nottingham may be monitored as permitted by UK legislation.
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-help mailing list