bmreg:

Usage Arguments Examples

Usage

1
bmreg(x, y, iter = 20, bend = 2 * sqrt((ncol(x) + 1)/nrow(x)), xout = FALSE, outfun = outpro, ...)

Arguments

x
y
iter
bend
xout
outfun
...

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
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (x, y, iter = 20, bend = 2 * sqrt((ncol(x) + 1)/nrow(x)), 
    xout = FALSE, outfun = outpro, ...) 
{
    x <- as.matrix(x)
    p1 <- ncol(x) + 1
    p <- ncol(x)
    xy <- cbind(x, y)
    xy <- elimna(xy)
    x <- xy[, 1:p]
    y <- xy[, p1]
    if (xout) {
        m <- cbind(x, y)
        flag <- outfun(x, plotit = FALSE, ...)$keep
        m <- m[flag, ]
        x <- m[, 1:p]
        y <- m[, p1]
    }
    x <- as.matrix(x)
    init <- lsfit(x, y)
    resid <- init$residuals
    x1 <- cbind(1, x)
    nu <- sqrt(1 - hat(x1))
    low <- ncol(x) + 1
    for (it in 1:iter) {
        ev <- sort(abs(resid))
        scale <- median(ev[c(low:length(y))])/qnorm(0.75)
        rov <- (resid/scale)/nu
        psi <- ifelse(abs(rov) <= bend, rov, bend * sign(rov))
        wt <- nu * psi/(resid/scale)
        new <- lsfit(x, y, wt)
        if (max(abs(new$coef - init$coef)) < 1e-04) 
            break
        init$coef <- new$coef
        resid <- new$residuals
    }
    resid <- y - x1 %*% new$coef
    if (max(abs(new$coef - init$coef)) >= 1e-04) 
        paste("failed to converge in", iter, "steps")
    list(coef = new$coef, residuals = resid, w = wt)
  }

musto101/wilcox_R documentation built on May 23, 2019, 10:52 a.m.