Learn R Programming

ChemoSpec (version 3.0-1)

makeEllipsoid: Create Ellipsoid

Description

Given at least 3 data points, this function creates either classical or robust ellipsoids at a given confidence limit, in either 2D or 3D. The ellipsoids consist of randomly generate points, which if plotted as tiny points, create a sort of transparent surface.

Usage

makeEllipsoid(data, cl = 0.95, rob = FALSE, frac.pts.used = 0.8)

Arguments

data
A matrix of at least 3 data points, with x, y and optionally z in columns. See details.
cl
The confidence limit desired.
rob
Logical, indicating if robust ellipsoids are to be computed.
frac.pts.used
If rob = TRUE, this is the fraction of points to be considered the "good" part of the data. See the documentation for cov.rob for details.

Value

  • A matrix of 2 or 3 columns, representing x, y and optionally z. These are the coordinates of points specifying an ellipse which has a likelihood of containing the true mean at the given confidence limit.

Details

If only x and y are provided, at least 3 points must be given, as 2 points defines a line, not an ellipse. For 3D data, and rob = FALSE, at least 4 points must be provided. If rob = TRUE, 5 points would be theoretically required, but the code forces 8 to avoid unusual cases which would fail. If fewer than 8 are given, the computation shifts to classical with a warning. Note that depending upon how this function is called, one may end up with classical and robust ellipsoids in the plot. Remember too that because the points are randomly generated, the x, y pairs or x, y, z triplets are not related to each other, and one cannot plot lines from point to point. See the example for a 2D ellipse. If you want a function that generates x, y points suitable for connecting to each other via lines, see plotScoresCor.

References

https://github.com/bryanhanson/ChemoSpec

See Also

cov.rob for the function that does the work.

Examples

Run this code
# 2D example
x <- rnorm(10, 2, 0.5)
y <- rnorm(10, -2, 2)
ell <- makeEllipsoid(cbind(x,y), cl = 0.99)
plot(ell[,1], ell[,2], col = "red", pch = 20, cex = 0.3)
points(x,y)

Run the code above in your browser using DataLab