我正在尝试在以下数据集中进行主成分分析。我尝试通过 prcomp 函数和插入符预处理函数。
library(caret)
library(AppliedPredictiveModeling)
set.seed(3433)
data(AlzheimerDisease)
adData = data.frame(diagnosis,predictors)
inTrain = createDataPartition(adData$diagnosis, p = 3/4)[[1]]
training = adData[ inTrain,]
testing = adData[-inTrain,]
# from prcomp
names1 <-names(training)[substr(names(training),1,2)=="IL"]
prcomp.data <- prcomp(training[,names1],center=TRUE, scale=TRUE)
prcomp.data$sdev
## from caret package
preProcess(training[, names1], method=c("center", "scale", "pca"))$std
我想知道为什么 sdev 值在上述过程中不同。 谢谢
最佳答案
第一种方法是为您提供 12 个主要成分的标准偏差(您可以使用 prcomp.data$rotation
查看)。
另外,sdev
值的文档中提到了这一点:
the standard deviations of the principal components (i.e., the square roots of the eigenvalues of the covariance/correlation matrix, though the calculation is actually done with the singular values of the data matrix).
第二个是为您提供预处理输入数据的标准偏差(因此变量名称与每个标准偏差相关联)。
一个小的旁注 -- caret
除非另有说明,否则 PCA 会自动缩放和居中。
关于r - 主成分对象的标准值在 prcomp 和 caret 中不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38772017/