PCA示例中的椭圆类型

时间:2016-12-09 08:03:16

标签: r probability ellipse confidence-interval

this example中,作者使用ggbiplot可视化虹膜数据的PCA。他还在群体周围绘制椭圆。我的问题 - 那些椭圆是什么类型(概率椭圆,置信椭圆等)?它们代表什么?

原文:

enter image description here

我从虹膜数据集(setosa)中提取了一个组。

log.ir <- log(iris[1:49, 1:4]) # only setosa
ir.species <- iris[1:49, 5]

使用相同的 ggbiplot 函数绘制它(我使用红色椭圆作为“它应该看起来像”与其他库一样。注意:ggbiplot默认的ellipse.prob概率默认为 68%):

代码

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)

结果

enter image description here

尝试使用 stat_ellipse

代码

log.ir <- log(iris[1:49, 1:4]) # only setosa

ir.species <- iris[1:49, 5]

# apply PCA - scale. = TRUE is highly 
# advisable, but default is FALSE. 
ir.pca <- prcomp(log.ir,
                 center = TRUE,
                 scale. = TRUE)

pca1_x <- ir.pca$x[, 1]

pca2_y <- ir.pca$x[, 2]

# create data
set.seed(101)
n <- 1000
x <- rnorm(pca1_x, mean = 2)
y <- rnorm(pca2_y, mean = 2)
df <- data.frame(x = x, y = y, group = "A")

qplot(data = df, x = x, y = y) + stat_ellipse(level = 0.68)

结果

enter image description here

Momocs

代码

log.ir <- log(iris[1:49, 1:4]) # only setosa
ir.species <- iris[1:49, 5]

pca1_x <- ir.pca$x[, 1]
pca2_y <- ir.pca$x[, 2]

plot(pca1_x, pca2_y, asp = 1)

library(Momocs)
ce068 <- conf_ell(pca1_x, pca2_y, conf = 0.68)
cols <- col_hot(10)

lines(ce068$ell, col = cols[9])

结果

enter image description here

在所有情况下,我使用68%像ggbiplot一样使用,但在所有情况下我都有不同的椭圆。我在这里缺少什么?

0 个答案:

没有答案