wreg:

Usage Arguments Examples

Usage

1
wreg(x, y, iter = 10)

Arguments

x
y
iter

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
##---- 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 = 10) 
{
    temp <- NA
    x <- as.matrix(x)
    if (ncol(x) == 1) {
        temp1 <- wsp1reg(x, y)
        coef <- temp1$coef
        res <- temp1$res
    }
    if (ncol(x) > 1) {
        for (p in 1:ncol(x)) {
            temp[p] <- wsp1reg(x[, p], y)$coef[2]
        }
        res <- y - x %*% temp
        alpha <- median(res)
        r <- matrix(NA, ncol = ncol(x), nrow = nrow(x))
        tempold <- temp
        for (it in 1:iter) {
            for (p in 1:ncol(x)) {
                r[, p] <- y - x %*% temp - alpha + temp[p] * 
                  x[, p]
                temp[p] <- wsp1reg(x[, p], r[, p], plotit = FALSE)$coef[2]
            }
            alpha <- median(y - x %*% temp)
            if (max(abs(tempold - temp)) < 1e-04) 
                break
            tempold <- temp
        }
        coef <- c(alpha, temp)
        res <- y - x %*% temp - alpha
    }
    list(coef = coef, residuals = res)
  }

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