Ellipse containing a percentage of the given points in R

I draw a plot of F1 / F2 vowels ( example here ). Each vowel has several dots / values, and I would like to draw an ellipse around the dots, so:

  • the ellipse covers at least 80% of the points (that is, in the image above, β€œi” has several meanings, but they are contained inside the ellipse).
  • positioned in the direction of min / max values.

I can complicate the material, but trigonometry and mathematics are Greek to me. Below I have tried.

Ellipsoidhull ()

Ellipsoidhull () is in the package package "cluster". If we go to the matrix function with F1 and F2, it seems to calculate the center of the ellipse, but the direction values ​​are huge. For instance:

> olm ol.f1 ol.f2 # f1/f2 data [1,] 501.3 850.5 [2,] 488.5 906.5 [3,] 456.3 857.0 [4,] 505.8 895.3 [5,] 499.5 898.0 [6,] 431.8 891.5 [7,] 416.3 870.5 [8,] 506.0 887.8 [9,] 500.3 985.8 [10,] 513.5 955.3 [11,] 531.5 958.0 [12,] 483.0 847.3 [13,] 533.3 982.8 [14,] 480.8 881.8 [15,] 484.3 884.5 

If passed ellipsoidhull :

 > ellipsoidhull(olm) 'ellipsoid' in 2 dimensions: center = ( 480.69 904.33 ); squared ave.radius d^2 = 2 and shape matrix = ol.f1 ol.f2 ol.f1 2115.5 1449.5 ol.f2 1449.5 3558.2 hence, area = 14636 

I think it would not be easy to figure out how to draw an ellipse, but the β€œshape matrix” (maximum / minimum radius values?) Is too large. By the way, thanks to #R on Freednode for tips.

Source Code from EMU-R

Then I looked at the code for the EMU-R, R package, which works with EMU , which can, among other things, draw F1 / F2 ellipsoids. Code that seems to do it here , but I don't understand how an ellipse is drawn.

Any help was appreciated.

+6
source share
1 answer
 require(car) x=rnorm(100) y=1+.3*x+.3*rnorm(100) dataEllipse(x,y, levels=0.80) 

So your data:

 with(olm ,dataEllipse(ol.f1, ol.f2, levels=0.8) ) 

Another package, mixools, has similar capabilities, but uses an alpha level rather than 1 alpha:

  mu <- with(olm, c(mean(ol.f1), mean(ol.f2)) ) sigma <- var(olm) # returns a variance-covariance matrix. sigma # ol.f1 ol.f2 #ol.f1 1077.2098 865.9306 #ol.f2 865.9306 2090.2021 require(mixtools) #Loading required package: mixtools #Loading required package: boot # And you get a warning that ellipse from car is masked. ellipse(mu, sigma, alpha=0.2, npoints = 200, newplot = FALSE) 

To superimpose the previous graph with a new estimate (which in this case is a bit narrower. This is the comparison of the two methods

+12
source

Source: https://habr.com/ru/post/892526/


All Articles