1 |
x |
|
y |
|
plotit |
|
SEED |
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, plotit = TRUE, SEED = TRUE)
{
library(MASS)
xy = elimna(cbind(x, y))
x = as.matrix(x)
p = ncol(x)
p1 = p + 1
x = xy[, 1:p]
y = xy[, p1]
plotit <- as.logical(plotit)
if (SEED)
set.seed(12)
x <- as.matrix(x)
res <- lmsreg(x, y)$resid
sighat <- sqrt(median(res^2))
sighat <- 1.4826 * (1 + (5/(length(y) - ncol(x) - 1))) *
sighat
stanres <- res/sighat
set.seed(12)
if (ncol(x) >= 2)
mve <- cov.mve(x)
if (ncol(x) == 1) {
mve <- vector("list")
mve$center <- median(x)
mve$cov <- mad(x)^2
}
dis <- mahalanobis(x, mve$center, mve$cov)
dis <- sqrt(dis)
crit <- sqrt(qchisq(0.975, ncol(x)))
chk <- ifelse(dis > crit, 1, 0)
vec <- c(1:nrow(x))
id <- vec[chk == 1]
chkreg <- ifelse(abs(stanres) > 2.5, 1, 0)
idreg <- vec[chkreg == 1]
if (plotit) {
plot(dis, stanres, xlab = "Robust distances", ylab = "standardized residuals")
abline(-2.5, 0)
abline(2.5, 0)
abline(v = crit)
}
list(levpoints = id, regout = idreg, dis = dis, stanres = stanres,
crit = crit)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.