1 |
x |
|
center |
|
cov |
|
alph |
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, center = apply(x, 2, mean), cov = var(x), alph = 0.95)
{
mu1 <- center[1]
mu2 <- center[2]
w <- solve(cov)
w11 <- w[1, 1]
w12 <- w[1, 2]
w22 <- w[2, 2]
tem <- x[, 2] - mu2
y2 <- seq(min(tem), max(tem), length = 100)
xc <- qchisq(alph, 2)
el <- matrix(0, 2, 2)
ind <- 0
for (i in 1:100) {
j1 <- (y2[i] * w12)^2
j2 <- w11 * ((y2[i])^2 * w22 - xc)
if ((j1 - j2) >= 0) {
ind <- ind + 2
tem <- (y2[i] * w12)^2
tem <- tem - w11 * ((y2[i])^2 * w22 - xc)
tem <- sqrt(tem)
term <- (-y2[i] * w12 + tem)/w11
el <- rbind(el, c((term + mu1), (y2[i] + mu2)))
term <- (-y2[i] * w12 - tem)/w11
el <- rbind(el, c((term + mu1), (y2[i] + mu2)))
}
}
el <- el[3:ind, ]
nn <- dim(x)[1]
if ((ind - 2) > nn) {
tem <- sample((ind - 2), nn)
el <- el[tem, ]
}
xt <- cbind(x[, 1], el[, 1])
yt <- cbind(x[, 2], el[, 2])
matplot(xt, yt)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.