我遵循this教程来创建和可视化PCA。 Im特别感兴趣的部分是为现有模型添加新的数据点。现有PCA模型的新数据点
正如本教程所示,我们将使用predict(ir.pca,newdata = tail(log.ir,2))来预测新的PC。但是,我如何将这些新观察添加到现有的情节?它看起来不像预测函数返回与ggplot函数中使用的ir.pca相同的对象。
我发现了类似的问题here和here但他们计算新的PCA评分并将它们添加到方差图(如果我理解正确的话)。
最终,我后面要看看新点是否落入使用初始数据集定义/导出的置信椭圆内。
我从教程使用的代码:
# log transform
log.ir <- log(iris[, 1:4])
ir.species <- iris[, 5]
# apply PCA - scale. = TRUE is highly
# advisable, but default is FALSE.
ir.pca <- prcomp(log.ir,
center = TRUE,
scale. = TRUE)
library(devtools)
install_github("ggbiplot", "vqv")
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)
而作为教程提示我想补充其排在同ggplot可视化现有的情节
感谢
新数据
如果您在问题中提供了[可重现的示例](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example),它会更容易帮助您本身。 – MrFlick
@MrFlick更新了 –