smoothM {regr0} | R Documentation |
Generate fits of a smoothing function for multiple y's. Smooths can be calculated within given groups.
smoothM(x, y, weights = NULL, band = FALSE, group = NULL, power = 1, resid = "difference", par = 5 * length(x)^log10(1/2), parband = par*2^log10(2), iterations = 50, ...)
x |
vector of x values. |
y |
vector or matrix of y values. |
weights |
vector of weights to be used for fitting. |
band |
logical: Should a band consisting of low and high smooth be calculated? |
group |
NULL or a factor that defines the groups for which the smooth is calculated. |
power |
|
resid |
Which residuals be calculated?
|
par, parband |
argument to be passed to the smoothing function,
|
iterations |
argument passed on to the smoothing function. |
... |
Further arguments, passed to the smoothing function. |
These functions are useful for generating the smooths enhancing
residual plots. (smoothM
) generates a smooth for a single x
variable and multiple y's. It is used to draw smooths from simulated
residuals.
If argument group
is specified, the smooths will be calculated
within the specified groups.
NA's in either x
or any column of y
cause dropping the
observation (equivalent to na.omit
).
The smoothing function used to produce the smooth is
smoothRegr
, which relies loess
by default.
This may be changed via options(smoothFunction = func)
where
func
is a smoothing function with the same arguments as
smoothRegr
.
smoothM
: A list with components:
x |
vector of x values, sorted, within levels of |
y |
matrix with 1 or more columns of corresponding fitted values of the smoothing. |
group |
grouping factor, sorted, if actif. |
index |
vector of indices of the argument |
xorig |
original |
ysmorig |
corresponding fitted values |
residuals |
if required by the argument |
If band==TRUE
,
yband |
vector of low and high smoothed values (for the first
column of |
ybandindex |
Indicator if |
Werner A. Stahel, ETH Zurich
data(d.blast) r.blast <- regr(log10(tremor)~location+log10(distance)+log10(charge), data=d.blast) r.smooth <- smoothM( fitted(r.blast), residuals(r.blast)) showd(r.smooth$y) plot(fitted(r.blast), resid(r.blast), main="Tukey-Anscombe Plot") abline(h=0) lines(r.smooth$x,r.smooth$y, col="red") ## grouped data r.smx <- smoothM( d.blast$dist, residuals(r.blast), group=d.blast$location) plot(d.blast$dist, resid(r.blast), main="Residuals against Regressor") abline(h=0) for (lg in 1:length(levels(r.smx$group))) { li <- as.numeric(r.smx$group)==lg lines(r.smx$x[li],r.smx$y[li], col=lg+1, lwd=3) } ## example with data from stats data(swiss) plot(Fertility~Agriculture, swiss) r.sm <- smoothM( swiss$Agriculture, swiss$Fertility ) lines(r.sm) r.sm <- smoothM( swiss$Agriculture, swiss$Fertility, band=TRUE ) li <- r.sm$ybandind lines(r.sm$x[li], r.sm$yband[li], lty=2) lines(r.sm$x[!li], r.sm$yband[!li], lty=2) ## example with groups and band t.group <- swiss$Catholic>70 plot(Fertility~Agriculture, swiss, pch=2+t.group, col=2+t.group) r.sm <- smoothM( swiss$Agriculture, swiss$Fertility, group=t.group, band=TRUE ) for (lg in c(FALSE,TRUE)) { lig <- which(r.sm$group==lg) lines(r.sm$x[lig], r.sm$y[lig], lty=1, col=2+lg) li <- r.sm$ybandind[lig] ligh <- lig[li] ligl <- lig[!li] lines(r.sm$x[ligh], r.sm$yband[ligh], lty=2+2*lg, col=2+lg) lines(r.sm$x[ligl], r.sm$yband[ligl], lty=2+2*lg, col=2+lg) }