[R] running median and smoothing splines for robust surface fitting
Vladislav Petyuk
petyuk at mail.ru
Thu Mar 16 07:27:39 CET 2006
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,
Vlad
#=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
#===============================================================
More information about the R-help
mailing list