简体   繁体   中英

R PCA plot using Hotelling's T2 for a confidence interval

For my test data, I calculated the first two principal components using the prcomp function. I then plotted the first 2 components using the plot function.

df <- data.frame(x1 = runif(10), x2 = runif(10), x3 = runif(10), x4 = runif(10))
rownames(df) <- letters[1:10]

res <- prcomp(df, center = TRUE, scale = TRUE, na.action = na.omit)

plot(res$x, xlim = c(-5, 5), ylim = c(-5, 5))

I now would like to place an ellipse around the data that represens a 95% confidence interval using Hotelling's T2 statistic.

The SensoMineR package in particular the panellipse function seems to be what I am looking for. However, my R knowledge is still quite limited and I was therefore wondering if you could point me in the right direction on to construct such a confidence interval.

Many thanks! Jacky

SensoMineR is good.

There is another package called Package 'Hotelling' which is easy to place an ellipse around the data.

Package 'Hotelling'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM