smoothM: Smooth: wrapper function

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Generate fits of a smoothing function for multiple y's. Smooths can be calculated within given groups.

Usage

1
2
3
4
  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, ...)

Arguments

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

y will be raised to power before smoothing. Results will be back-transformed. (Useful for smoothing absolute values for a 'scale plot', for which power=0.5 is recommended.)

resid

Which residuals be calculated? resid=1 or ="difference" means usual residuals; resid=2 or ="ratio" means $y_i/\hat y_i$, which is useful to get scaled y's (regression residuals) according to a smooth fit in the scale plot.

par, parband

argument to be passed to the smoothing function, parband when calculating "band" smooths

iterations

argument passed on to the smoothing function.

...

Further arguments, passed to the smoothing function.

Details

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.

Value

smoothM: A list with components:

x

vector of x values, sorted, within levels of group if grouping is actif.

y

matrix with 1 or more columns of corresponding fitted values of the smoothing.

group

grouping factor, sorted, if actif. NULL otherwise.

index

vector of indices of the argument x used for sorting. This is useful to relate the results to the input. Use ysmoothed[value$index,] <- value$y to get values corresponding to input y.

xorig

original x values

ysmorig

corresponding fitted values

residuals

if required by the argument resid, residuals from the smooth fit are provided in the original order, i.e. value$resid[i,j] corresponds to the input value$y[i,j].

If band==TRUE,

yband

vector of low and high smoothed values (for the first column of y)

ybandindex

Indicator if yband is a high value

Author(s)

Werner A. Stahel, ETH Zurich

See Also

smoothRegr

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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)
  }

regr0 documentation built on May 2, 2019, 4:52 p.m.

Related to smoothM in regr0...