[R] loess and NA

Gavin Simpson gavin.simpson at ucl.ac.uk
Tue Oct 5 18:55:05 CEST 2010


On Tue, 2010-10-05 at 08:11 -0700, Filoche wrote:
> Hi everyone.
> 
> I'm trying to do a loess with missing value on independant variable.
> 
> 
> 
> doc = c(2.27904, 2.59536, 7.44696, NA, 6.24264, 4.58400, 5.79192, 5.39502,
> 7.41216, 4.09440, 4.22868, 4.24620, 5.43804, 1.95528);
> distance = c(26.5,56.5, 90.3, 123.0, 147.5, 176.0, 215.7, 229.3, 252.0,
> 325.3, 362.0, 419.3, 454.6, 470.0);
> 
> myloess = loess(doc ~ distance, na.action = na.omit);

You want na.exclude here not na.omit:

myloess <- loess(doc ~ distance, na.action = na.exclude)

> plot(distance, predict(myloess));

The predict() method ensures that the predictions have the correct
length now that we set na.action to na.exclude.

> When I plot the data there's a problem since distance and predicted values
> have different length.
> 
> Any way to plot the loess without having to specify the X data?

Also, this is R, not C. You don't need the ; at the end of the lines.

> With regards,
> Phil 

HTH

G

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-help mailing list