1 |
x |
|
y |
|
start |
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 | ##---- 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, start = l1fit(x, y)$coef)
{
nc <- dim(x)[2] + 1
res <- y - (x %*% start[2:nc] + start[1])
ares <- abs(res)
cov <- ceiling(length(y)/2)
m <- sort(ares, partial = cov)[cov]
old <- sum(ares[ares <= m])
new <- old - 1
ct <- 0
while (new < old) {
ct <- ct + 1
start <- l1fit(x[ares <= m, ], y[ares <= m])$coef
res <- y - (x %*% start[2:nc] + start[1])
ares <- abs(res)
m <- sort(ares, partial = cov)[cov]
new <- sum(ares[ares <= m])
if (new < old) {
old <- new
new <- new - 1
}
}
list(coef = start, ct = ct)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.