Nicola Sturaro Sommacal (Quantide srl)
2010-Nov-03 17:40 UTC
[R] smooth: differences between R and S-PLUS
Hi!
I am studying differences between R and S-PLUS smooth() functions. I know
from the help that they worked differently, so I ask:
- exist a package that permit to have the same results?
- alternatively, someone know how can I obtain the same results in R, using
a self made script?
I know that S-PLUS use the 4(3RSR)2H running median smoothing and I try to
implement it with the code below. I obtain some result equal to the S-PLUS
one, so I think the main problem is understand how NA value from moving
median are treated.
The R result is:
[1] NA NA 4.6250 4.9375 4.7500 4.0000 3.2500 3.0000
[9] 2.8750 2.5000 2.1250
the S-PLUS one is:
[1] * * * 4.6250 4.9375 4.7500 4.0000 3.2500 3.0000 * *
where * stand for a number different from the R one that I don't remember.
Unfortunately I cannot give more details about the S-PLUS function now,
because I am working on a machine without this software. If someone can help
me, tomorrow (CET time), I will provide more details.
Thanks in advance.
Nicola
### EXAMPLE
# Comments indicates which step of the 4(3RSR)2H algorithm I try to
replicate.
# Data
x1 <- c(4, 1, 3, 6, 6, 4, 1, 6, 2, 4, 2)
# 4
out = NULL
for (i in 1:11) {out[i] = median(x1[i:(i+3)])}
out[is.na(out)] = x1[is.na(out)]
out
# (3RSR)
x2 = smooth(out, "3RSR", twiceit = F)
x2
# 2
out2 = NULL
for (i in 1: 11) {out2[i] = median(x2[i:(i+1)])}
out2[is.na(out2)] = x2[is.na(out2)]
out2
# H
filter(out2, filter = c(1/4, 1/2, 1/4), sides = 2)
[[alternative HTML version deleted]]
> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Nicola > Sturaro Sommacal (Quantide srl) > Sent: Wednesday, November 03, 2010 10:41 AM > To: r-help at r-project.org > Subject: [R] smooth: differences between R and S-PLUS > > Hi! > > I am studying differences between R and S-PLUS smooth() > functions. I know > from the help that they worked differently, so I ask: > - exist a package that permit to have the same results? > - alternatively, someone know how can I obtain the same > results in R, using > a self made script? > > I know that S-PLUS use the 4(3RSR)2H running median smoothing > and I try to > implement it with the code below. I obtain some result equal > to the S-PLUS > one, so I think the main problem is understand how NA value > from moving > median are treated. > > The R result is: > [1] NA NA 4.6250 4.9375 4.7500 4.0000 3.2500 3.0000 > [9] 2.8750 2.5000 2.1250 > > the S-PLUS one is: > [1] * * * 4.6250 4.9375 4.7500 4.0000 3.2500 3.0000 * *In S+ I get: > x1 <- c(4, 1, 3, 6, 6, 4, 1, 6, 2, 4, 2) > smooth(x1) 1: 2.404297 3.283203 4.140625 4.789063 5.093750 4.886719 7: 4.078125 3.269531 3.000000 3.000000 3.000000 start deltat frequency 1 1 1 > smooth(x1, twiceit=FALSE) 1: 2.03125 3.00000 3.93750 4.62500 4.93750 4.75000 4.00000 8: 3.25000 3.00000 3.00000 3.00000 start deltat frequency 1 1 1 Tukey's EDA book (1977) may give the details on how to deal with the ends. The code in S+ is unchanged since that era, aside from being converted from single to double precision. There are many better smoothers out there. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com> > where * stand for a number different from the R one that I > don't remember. > Unfortunately I cannot give more details about the S-PLUS > function now, > because I am working on a machine without this software. If > someone can help > me, tomorrow (CET time), I will provide more details. > > Thanks in advance. > > Nicola > > > ### EXAMPLE > # Comments indicates which step of the 4(3RSR)2H algorithm I try to > replicate. > > # Data > x1 <- c(4, 1, 3, 6, 6, 4, 1, 6, 2, 4, 2) > > # 4 > out = NULL > for (i in 1:11) {out[i] = median(x1[i:(i+3)])} > out[is.na(out)] = x1[is.na(out)] > out > > # (3RSR) > x2 = smooth(out, "3RSR", twiceit = F) > x2 > > # 2 > out2 = NULL > for (i in 1: 11) {out2[i] = median(x2[i:(i+1)])} > out2[is.na(out2)] = x2[is.na(out2)] > out2 > > # H > filter(out2, filter = c(1/4, 1/2, 1/4), sides = 2) > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >