r - 主成分对象的标准值在 prcomp 和 caret 中不同

标签 r statistics

我正在尝试在以下数据集中进行主成分分析。我尝试通过 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/

相关文章:

r - 如何在dplyr summarise中使用标准评估_

r - 无法让 Highcharter 绘制时间序列

r - 在 R 中拟合正态分布

mysql按组百分位排名

r - 将ggplot对象从R中的循环内存储在列表中

r - 在 R 中,如何从多个文件创建数据框,其中每个文件包含单独类别的测量值?

r - 如何使用 ddply 对特定列的数据进行子集化?

c - CUDA代码的数据收集部分意外输出“0”

python - 像普通 python 函数一样调用 scipy.stats 概率分布

actionscript-3 - Flash Player 9 或 10+