runmean: Running Interval Smoother

Description Usage Arguments Details Value References See Also Examples

View source: R/runmean.R

Description

The runmean implements a running interval smoother on the trimmed mean, rungen uses general M-estimators, runmbo performs interval smoothing on M-estimators with bagging.

Usage

1
2
3
runmean(x, y, fr = 1, tr = 0.2, ...)
rungen(x, y, fr = 1, est = "mom", ...)
runmbo(x, y, fr = 1, est = "mom", nboot = 40, ...)

Arguments

x

a numeric vector of data values (predictor)

y

a numeric vector of data values (response)

fr

smoothing factor (see details)

tr

trim level for the mean

est

type of M-estimator ("mom", "onestep", or "median")

nboot

number of bootstrap samples

...

currently ignored.

Details

The larger the smoothing factor, the stronger the smoothing. Often the choice fr = 1 gives good results; the general strategy is to find the smallest constant so that the plot looks reasonably smooth.

Value

Returns the fitted values.

References

Wilcox, R. (2012). Introduction to Robust Estimation and Hypothesis Testing (3rd ed.). Elsevier.

See Also

ancova

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## trimmed mean smoother
fitmean <- runmean(Pygmalion$Pretest, Pygmalion$Posttest)
## MOM smoother
fitmest <- rungen(Pygmalion$Pretest, Pygmalion$Posttest)
## median smoother
fitmed <- rungen(Pygmalion$Pretest, Pygmalion$Posttest, est = "median")
## bagged onestep smoother
fitbag <- runmbo(Pygmalion$Pretest, Pygmalion$Posttest, est = "onestep")

## plot smoothers
plot(Pygmalion$Pretest, Pygmalion$Posttest, col = "gray", xlab = "Pretest", ylab = "Posttest",
     main = "Pygmalion Smoothing")
orderx <- order(Pygmalion$Pretest)
lines(Pygmalion$Pretest[orderx], fitmean[orderx], lwd = 2)
lines(Pygmalion$Pretest[orderx], fitmest[orderx], lwd = 2, col = 2)
lines(Pygmalion$Pretest[orderx], fitmed[orderx], lwd = 2, col = 3)
lines(Pygmalion$Pretest[orderx], fitbag[orderx], lwd = 2, col = 4)
legend("topleft", legend = c("Trimmed Mean", "MOM", "Median", "Bagged Onestep"), col = 1:4, lty = 1)

Example output



WRS2 documentation built on July 20, 2021, 9:06 a.m.

Related to runmean in WRS2...