# [R] running median and smoothing splines for robust surface f itting

Liaw, Andy andy_liaw at merck.com
Thu Mar 16 13:13:34 CET 2006

```loess() should be able to do robust 2D smoothing.

There's no natural ordering in 2D, so defining running medians can be
tricky.  I seem to recall Prof. Koenker talked about some robust 2D
smoothing method at useR! 2004, but can't remember if it's available in some
packages.

Andy

>
> Hi,
> Are there any multidimenstional versions of runmed() and
> smooth.spline() functions? I need to fit surface into quite
> noisy 3D data.
>
> Below is an example (2D) of kind of fittings I do.
> Thank you,
>
> #=generating complex x,y dataset with gaussian & uniform
> noise== x <- seq(1:10000) x2 <- rep(NA,2*length(x)) y2 <-
> rep(NA,2*length(x)) x2[seq(1,length(x2),2)] <- x
> x2[seq(2,length(x2),2)] <- x y2[seq(1,length(x2),2)] <-
> sin(4*pi*x/length(x)) + rnorm(length(x))
> y2[seq(2,length(x2),2)] <- runif(length(x),min=-5,max=5)
> #===============================================================
>
> #=robust & smooth fit===========================================
> y3 <- runmed(y2,51,endrule="median") #first round of running
> median y4 <- smooth.spline(x2,y3,df=10) #second round of
> smoothing splines
> #===============================================================
>
> #=ploting data==================================================
> plot(x2,y2,pch=19,cex=0.1)
> points(x2,y3,col="red",pch=19,cex=0.1) #running median
> points(y4,col="green",pch=19,cex=0.1) #smoothing splines
> #===============================================================
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help