How to adjust ellipses overlap calculation in overlap{siar} to match normal probability ellipsoids in ggbiplot?

余生颓废 提交于 2019-12-11 00:12:03

问题


Going back to this thread, I was calculating the intersection between two ellipses e.g. the volume of the intersection between versicolor and virginca: using the following 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)

I then calculate the ellipsoids using overlap{siar} as follows:

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

which apparently is much less than illustrated in the Figure 2 above.

As the ggbiplot code on line 50 indicates, ggbiplot calculates the normal probability ellipsoids with a probability of "ellipse.prob = 0.68" by default, what is used in the plot above.

Due to the documentation overlap {siar} calculates the ellipses as "small sample size corrected standard ellipses".

Hence I was asking myself how overlap{siar} could be modified to calculate an normal probability ellipsoid similar to the one plotted/calculated in ggbiplot.


回答1:


the latest version of SIBER available from https://github.com/AndrewLJackson/SIBER includes two new functions to calculate overlap of ellipses of a user defined size (i.e. different quantiles).

maxLikOverlap()

and

bayesianOverlap()

I suggest you install from the master branch using

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

And follow the vignette "Ellipse-Overlap". If the vignettes do not install for you, you can download them directly from the github repository https://github.com/AndrewLJackson/SIBER/tree/master/vignettes



来源:https://stackoverflow.com/questions/37349878/how-to-adjust-ellipses-overlap-calculation-in-overlapsiar-to-match-normal-prob

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!