1 |
x |
|
y |
|
xout |
|
eout |
|
outfun |
|
epow.cov |
|
RES |
|
... |
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 | ##---- 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, xout = FALSE, eout = FALSE, outfun = outpro,
epow.cov = mcdcov, RES = FALSE, ...)
{
if (eout) {
flag = outfun(cbind(x, y), ...)$keep
x = x[flag, ]
y = y[flag, ]
}
if (xout) {
flag = outfun(x, ...)$keep
x = x[flag, ]
y = y[flag, ]
}
npar = (ncol(x) + 1) * ncol(y)
xy = elimna(cbind(x, y))
x = xy[, 1:ncol(x)]
for (i in 1:ncol(x)) x[, i] = (x[, i] - mean(x[, i]))/sqrt(var(x[,
i]))
p1 = ncol(x) + 1
y = xy[, p1:ncol(xy)]
INIT = as.vector(lsfit(x, y)$coef)
xx = c(nrow(x), ncol(x), ncol(y), as.vector(x), as.vector(y))
Bs = nelderv2(xx, npar, Mreglde.sub, START = INIT)
Bs = matrix(Bs, ncol = ncol(y))
dimnames(Bs) <- list(c("INTER", rep("SLOPE", ncol(x))), rep("Y",
ncol(Bs)))
yhat = matrix(NA, nrow = nrow(y), ncol = ncol(y))
for (i in 1:nrow(y)) {
z = as.matrix(x[i, ])
yhat[i, ] = t(Bs[2:nrow(Bs), ]) %*% z
}
yhat = yhat + Bs[1, ]
res = NULL
if (RES)
res = y - yhat
list(coef = Bs, residuals = res)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.