1 | mbareg(x, y, nsamp = 7)
|
x |
|
y |
|
nsamp |
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 | ##---- 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, nsamp = 7)
{
x <- as.matrix(x)
n <- dim(x)[1]
q <- dim(x)[2]
vals <- c(q + 3 + floor(n/100), q + 3 + floor(n/40), q +
3 + floor(n/20), q + 3 + floor(n/10), q + 3 + floor(n/5),
q + 3 + floor(n/3), q + 3 + floor(n/2))
covv <- diag(q)
centers <- sample(n, nsamp)
temp <- lsfit(x, y)
mbaf <- temp$coef
critf <- median(temp$residuals^2)
for (i in 1:nsamp) {
md2 <- mahalanobis(x, center = x[centers[i], ], covv)
smd2 <- sort(md2)
for (j in 1:7) {
temp <- lsfit(x[md2 <= smd2[vals[j]], ], y[md2 <=
smd2[vals[j]]])
res <- y - temp$coef[1] - x %*% temp$coef[-1]
crit <- median(res^2)
if (crit < critf) {
critf <- crit
mbaf <- temp$coef
}
}
}
list(coef = mbaf, critf = critf)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.