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.
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).
and
I suggest you install from the master branch using
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