runmean | R Documentation |
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.
runmean(x, y, fr = 1, tr = 0.2, ...)
rungen(x, y, fr = 1, est = "mom", ...)
runmbo(x, y, fr = 1, est = "mom", nboot = 40, ...)
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 ( |
nboot |
number of bootstrap samples |
... |
currently ignored. |
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.
Returns the fitted values.
Wilcox, R. (2012). Introduction to Robust Estimation and Hypothesis Testing (3rd ed.). Elsevier.
ancova
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.