gensmooth {plgraphics} | R Documentation |
Generate fits of a smoothing function for multiple y's. Smooths can be calculated within given groups.
gensmooth(x, y, band = FALSE, power = 1, resid = "difference", plargs=NULL, ploptions=NULL, ...)
x |
vector of x values. |
y |
vector or matrix of y values. |
band |
logical: Should a band consisting of low and high smooth be calculated? |
power |
|
resid |
Which residuals be calculated?
|
plargs, ploptions |
result of calling |
... |
Further arguments, passed to the smoothing function. |
This function is useful for generating the smooths enhancing residual plots. It generates a smooth for a single x variable and multiple y's. It is also used to draw smooths from simulated residuals.
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 ploptions(smooth.function = func)
where
func
is a smoothing function with the same arguments as
smoothRegr
.
The result of the smoothing function may carry an attribute
xtrim
. This regulates if the fitted values corresponding to
extreme x values will be suppressed when plotting:
The number of extreme x values corresponding to
ploptions("smooth.xtrim")
will be multiplied by
this attribute to obtain the number of extreme points suppressed at
each end. If the smoothing function is smoothLm
, which fits a
straight line, then trimming is suppressed since this function returns
0 as the xtrim
attribute.
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 |
This function is called by plyx
and
plmatrix
when smooth=T
is set,
as well as by
plregr
applied to model objects.
It is rarely needed to call it directly.
A band is generated only for the first columnn of y
since the
others are supposed to be simulated versions of the first one
and do not need a band.
Werner A. Stahel, ETH Zurich
smoothRegr
,
plsmooth
, plsmoothline
data(d.blast) r.blast <- lm(log10(tremor)~location+log10(distance)+log10(charge), data=d.blast, na.action=na.exclude) r.smooth <- gensmooth( 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 t.plargs <- list(pdata=data.frame("(smooth.group)"=d.blast$location)) r.smx <- gensmooth( d.blast$dist, residuals(r.blast), plargs=t.plargs) plot(d.blast$dist, residuals(r.blast), main="Residuals against Regressor") abline(h=0) plsmoothline(r.smx, d.blast$dist, resid(r.blast), plargs=t.plargs) ## or, without using plsmoothlines: ## 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) ## }