1 |
x |
|
y |
|
plotit |
|
HD |
|
OPT |
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 | ##---- 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 = FALSE, HD = FALSE, OPT = TRUE)
{
temp <- matrix(c(x, y), ncol = 2)
temp <- elimna(temp)
x <- temp[, 1]
y <- temp[, 2]
ord <- order(x)
xs <- x[ord]
ys <- y[ord]
vec1 <- outer(ys, ys, "-")
vec2 <- outer(xs, xs, "-")
v1 <- vec1[vec2 > 0]
v2 <- vec2[vec2 > 0]
if (!HD)
slope <- median(v1/v2, na.rm = TRUE)
if (HD)
slope <- hd(v1/v2, na.rm = TRUE)
if (OPT) {
if (!HD)
coef <- median(y, na.rm = TRUE) - slope * median(x,
na.rm = TRUE)
if (HD)
coef <- hd(y, na.rm = TRUE) - slope * hd(x, na.rm = TRUE)
}
if (!OPT) {
if (!HD)
coef <- median(y - slope * x, na.rm = TRUE)
if (HD)
coef <- hd(y - slope * x, na.rm = TRUE)
}
names(coef) <- "Intercept"
coef <- c(coef, slope)
if (plotit) {
plot(x, y, xlab = "X", ylab = "Y")
abline(coef)
}
res <- y - slope * x - coef[1]
list(coef = coef, residuals = res)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.