1 |
x |
|
y |
|
iter |
|
tr |
|
xout |
|
outfun |
|
... |
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 46 47 48 | ##---- 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, tr = 0.2, xout = TRUE, 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)
ma <- matrix(0, ncol(x), 1)
m <- matrix(0, ncol(x), ncol(x))
mvals <- apply(x, 2, win, tr)
for (i in 1:ncol(x)) {
ma[i, 1] <- wincor(x[, i], y, tr = tr)$cov
for (j in 1:ncol(x)) m[i, j] <- wincor(x[, i], x[, j],
tr = tr)$cov
}
slope <- solve(m, ma)
b0 <- win(y, tr) - sum(slope %*% mvals)
for (it in 1:iter) {
res <- y - x %*% slope - b0
for (i in 1:ncol(x)) ma[i, 1] <- wincor(x[, i], res,
tr = tr)$cov
slopeadd <- solve(m, ma)
b0add <- win(res, tr) - sum(slopeadd %*% mvals)
if (max(abs(slopeadd), abs(b0add)) < 1e-04)
break
slope <- slope + slopeadd
b0 <- b0 + b0add
}
if (max(abs(slopeadd), abs(b0add)) >= 1e-04)
paste("failed to converge in", iter, "iterations")
list(coef = c(b0, slope), resid = res)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.