### examples of using non-parametric regression ## Simulating the data n<-200 x<-runif(n,0,10) y<-sin(x) + rnorm(n) ## make the first plot to show pattern in the data plot(x,y) x y ## first set of boxplots boxplot(split(y,x %/% 1), style.bxp="old") ## make another set of boxplots and add a line joining the medians # make the plot and get the x coordinate of the middle of each pos x.midpoints<-boxplot(split(y,x %/% 1), style.bxp="old") # get information about the location of the boxes result<-boxplot(split(y,x %/% 1), plot=F) # medians of the boxes boxm<-result$stats[3,] # add a line joining the medians to the plot # x.midpoints # boxm #ael: lines(x.midpoints$stats[3,],boxm) lines(c(1:length(boxm)),boxm) ## plot the points and add the above line plot(x,y) #ael: lines(x.midpoints/10.0,boxm) #ael: lines(x.midpoints$stats[3,],boxm) #m<-length(boxm)-1; #lines(c(0:m),boxm) lines(c(1:length(boxm)),boxm) #lea ## now plot the data and add a non-parametric curve plot(x,y, pch="o") lines(lowess(x,y, f=.3)) ## plots not shown # par(mfrow=c(2,2)) # see the effect of changing the span plot(x,y, main="Changing the Span", pch="o") lines(lowess(x,y)) lines(lowess(x,y, f=.5), lty=2, col=2) lines(lowess(x,y, f=.25), lty=3, col=3) # other smoothers # supersmoother # plot(x,y, main="Super Smoother", pch=".") # lines(supsmu(x,y)) # kernel smoothers # plot(x,y, main="Kernel Smoother", pch=".") # lines(ksmooth(x,y)) # splines # plot(x,y, main="Spline Smoother", pch=".") # lines(smooth.spline(x,y))