包含R中给定点的百分比的椭圆 [英] Ellipse containing percentage of given points in R

查看:117
本文介绍了包含R中给定点的百分比的椭圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在绘制F1/F2元音图(一个例子在这里).每个元音都有几个点/值,我想在这些点周围画一个椭圆,这样:

I'm drawing F1/F2 vowel graph (an example is here). Each vowel has several points/values, and I'd like to draw an ellipse around the points, so that:

  • 椭圆至少覆盖了80%的点(即,上图中的"i"具有多个值,但它们包含在椭圆中).
  • 在最小/最大值方向上定位.

我可能会使事情变得复杂,但是三角学和数学对我来说是希腊文.以下是我尝试过的方法.

I may be complicating the stuff, but trigonometry and maths are Greek to me. Below is what I've tried.

Ellipsoidhull()

Ellipsoidhull()是在包"cluster"中.如果我将具有F1和F2的矩阵传递给函数,似乎可以计算椭圆的中心,但是方向值很大.例如:

Ellipsoidhull() is in the package package "cluster". If I pass to a function a matrix with F1 and F2, it seems to calculate the center of the ellipse, but the directional values are huge. For example:

> 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

如果传递给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 

我想不难理解如何绘制椭圆,但是形状矩阵"(最大/最小半径值?)太高了.顺便说一句,感谢Freednode上的#R提供了提示.

I guess it wouldn't be hard to figure out how to draw an ellipse, but the "shape matrix" (max/min radius values?) is too high. Btw, thanks to #R on Freednode for the tips.

EMU-R的源代码

然后,我研究了与 EMU 尤其可以用椭圆形绘制F1/F2.似乎执行此操作的代码是此处,但我不知道如何绘制椭圆.

Then, I've taken a look into the code of EMU-R, R package that works with EMU that can, amongst other things, draw F1/F2 with ellipsoids. The code that seems to do that is here but I don't understand how the ellipse is drawn.

任何帮助表示赞赏.

推荐答案

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

关于您的数据:

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

另一个软件包mixtools具有相似的功能,但使用的是alpha级别而不是1-alpha:

Another package, mixtools, has similar capabilities but uses the alpha level rather than the 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)

这将用新的估算值覆盖较早的绘图(在这种情况下,该估算值会略窄.

Which would overlay the earlier plot with the new estimate (which is slightly narrower in this case.

这篇关于包含R中给定点的百分比的椭圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆