xy <- matrix(round(rnorm(100, 0, 5), 2), ncol=2)
(ce <- getConfEll(xy, level=0.5, dstTarget=25,
conversion='m2cm'))
# plot points, center, parametric confidence
# ellipse, and its axes
ctr <- colMeans(xy) # center point
eigVec <- eigen(cov(xy))$vectors # eigenvectors
eigScl <- eigVec %*% diag(ce$size["unit", ])
# matrix with scaled ellipse axes
xMat <- rbind(ctr[1] + eigScl[1, ], ctr[1] - eigScl[1, ])
yMat <- rbind(ctr[2] + eigScl[2, ], ctr[2] - eigScl[2, ])
plot(xy, asp=1, pch=16)
drawEllipse(ctr, cov(xy), radius=ce$magFac, fg="blue")
matlines(xMat, yMat, lty=1, col="blue")
points(ctr[1], ctr[2], pch=4, col="red", cex=2)
Run the code above in your browser using DataLab