r - 如何调整重叠{siar}中的椭圆重叠计算以匹配ggbiplot中的正态概率椭圆体?

标签 r overlap ellipse ggbiplot

回到这个thread ,我正在计算两个椭圆之间的交点,例如versicolor 和 virginca 交集的体积: PCA on iris dataset 使用以下 mwe:

data(iris)
log.ir <- log(iris[, 1:4])
ir.species <- iris[, 5]
ir.pca <- prcomp(log.ir, center = TRUE, scale. = TRUE)

library(ggbiplot)
g <- ggbiplot(ir.pca, obs.scale = 1, var.scale = 1, 
          groups = ir.species, ellipse = TRUE,
          circle = TRUE)
g <- g + scale_color_discrete(name = '')
g <- g + theme(legend.direction = 'horizontal', 
           legend.position = 'top')
print(g)

然后我使用重叠{siar}计算椭球体,如下所示:

library(siar)
setosa <- ir.pca$x[ir.species=="setosa",]
versicolor <- ir.pca$x[ir.species=="versicolor",]
virginica <- ir.pca$x[ir.species=="virginica",]

tmp <- overlap(versicolor[,1], versicolor[,2], virginica[,1], virginica[,2], steps = 5)
virginica.percentage <- round(x=(tmp$overlap/tmp$area2*100), digits = 2)
versicolor.percentage <- round(x=(tmp$overlap/tmp$area1*100), digits = 2)
> virginica.percentage [1] 1.54
> versicolor.percentage[1] 1.56

这显然比图中所示的要少得多 2如上所述。

作为ggbiplot code on line 50表示,ggbiplot 默认计算正态概率椭球,概率为“ellipse.prob = 0.68”,即上图中使用的值。

由于documentation重叠 {siar} 将椭圆计算为“小样本量校正标准椭圆”。

因此,我问自己如何修改重叠{siar}来计算类似于 ggbiplot 中绘制/计算的正态概率椭球体。

最佳答案

最新版本的 SIBER 可从 https://github.com/AndrewLJackson/SIBER 获取包括两个新函数来计算用户定义大小的椭圆重叠(即不同的分位数)。

maxLikOverlap()

bayesianOverlap()

我建议您使用

从 master 分支安装
  # install.packages("devtools") # install if necessary
  devtools::install_github("andrewljackson/SIBER@master",
  build_vingettes = TRUE)
  library(SIBER)

并遵循小插图“椭圆重叠”。如果没有为您安装小插图,您可以直接从 github 存储库下载它们 https://github.com/AndrewLJackson/SIBER/tree/master/vignettes

关于r - 如何调整重叠{siar}中的椭圆重叠计算以匹配ggbiplot中的正态概率椭圆体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37349878/

相关文章:

r - 将具有交替缺失值的两个字符串列合并为一个

r - ggplot2 饼图和圆环图在同一图上

sql - 计数最大值每天并发用户 session 数

r - 如何获得椭圆的半轴长度?在 R

c# - 如何随着窗口大小的变化动态测量wpf中的网格宽度/高度

r - 如果第 x 行中的 A 列具有值,如何将第 B 列保留在第 x 行中

html - 如何将我的 YAML 标题置于 R markdown html 文档的中心?

java - 使两个 BufferedImage 重叠且透明

sql - 使用 ifs 包含无限间隔的日期范围

matlab - 在 3D 空间中拟合椭圆的数据