Tuesday, March 17, 2009

Smoothing on R


One of you asked how to produce a "3RSSH, twice" smooth on R.  It seems that my R notes on the web could be clarified.  Here I illustrate a simple function to do the smooth that we want.

Here is a new function that you can use called smooth.3RSSH.twice.

smooth.3RSSH.twice=function(data)
{
SMOOTH=han(smooth(attend,kind="3RSS")) # 3RSSH smooth
ROUGH=data-SMOOTH                      # computes the rough
SMOOTH+han(smooth(ROUGH,kind="3RSS"))  # twicing operation
}

This program does three things:

1.  First, one computes a 3RSSH smooth using the smooth command in R and the han function from the LearnEDA package.

2.  Then one computes the rough (the residuals) from this smooth.

3.  Then one smooths the rough (using the same 3RSSH smooth) and adds this "smoothed rough" to the first smooth to get a "twiced smooth".

Here is an illustration of how it works for the Braves attendance data from the notes.
(I am assuming the above function has been read into R.)

library(LearnEDA)
data(brave.at)
attach(brave.at)
plot(game,attend)
the.smooth=smooth.3RSSH.twice(attend)
lines(game,the.smooth,lwd=3,col="green")


2 comments:

S.A.L. said...

Nice way to smooth. I've been trying to work on Spatial Analysis using Variogram and I found R quite tough to understand and use for such use. Can you suggest any nice and easy way to Kriging?

S.A.L. said...

Moreover, I've been interested to work on Bayesian Kriging but understanding R seems quite tough.