smoothM {regr0} | R Documentation |
Generate fits of a smoothing function for multiple y's
(smoothM
) and multiple x's (smoothMM
).
Smooths can be calculated within given groups.
smoothM(x, y, weights = NULL, band = FALSE, group = NULL, power = 1, resid = FALSE, par = 5 * length(x)^log10(1/2), parband = par*2^log10(2), iterations = 50) smoothMM(x, y, y2 = NULL, weights = NULL, band = FALSE, group = NULL, power = 1, resid = FALSE, par = 5 * NROW(x)^log10(1/2), parband = par*2^log10(2), iterations = 50)
x |
vector ( |
y |
vector or matrix ( |
y2 |
( |
weights |
vector of weights to be used for fitting. |
group |
NULL or a factor that defines the groups for which the smooth is calculated. |
band |
logical: Should a band consisting of low and high smooth be calculated? |
power |
|
resid |
Should residuals be calculated?
|
par, parband |
argument to be passed to |
iterations |
argument passed on 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.
(smoothMM
) is the wrapper for multivariate regression.
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
).
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 |
If band==TRUE
,
yband |
vector of low and high smoothed values (for the first
column of |
ybandind |
Indicator if |
resid |
if required by the argument |
For smoothMM
, the value is a list of such lists, with a component
for each column of x
.
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) } } ## use of simresiduals is missing ## multivariate regression data(d.fossiles) r.mregr <- regr(cbind(sAngle,lLength,rWidth)~SST.Mean+Salinity+lChlorophyll+region+N, data=d.fossiles) r.msmooth <- smoothMM( fitted(r.mregr), residuals(r.mregr), resid=TRUE ) showd(r.msmooth[[2]]$resid) r.msmresid <- sapply(r.msmooth, function(x) x$resid) ## row.names are lost by sapply showd(r.msmresid)