我试图在" training1"上运行PCA。下面创建的数据集:
SKEffectNode
然后,当我运行以下功能时:
UIVisualEffectView
我收到以下错误:
library(AppliedPredictiveModeling); data(AlzheimerDisease); library(caret)
adData <- data.frame(diagnosis, predictors)
inTrain <- createDataPartition(y = adData$diagnosis, p = .75)[[1]]
training <- adData[inTrain, ]
keep <- subset(data.frame(x = substr(as.character(colnames(training)), 1, 2), y = c(1:ncol(training))), x == "IL")
training1 <- cbind(training[, c(keep[1, 2]:keep[nrow(keep), 2])], training[c("diagnosis")])
但是,然后我运行以下两个函数来证明可以计算两个变量的标准偏差,它表示它不能计算它们:
preProc <- preProcess(log10(training1[, -13]+1), method = "pca", pcaComp = 2)
然后运行以下函数来证明我没有任何零方差的变量。
Warning in preProcess.default(log10(training1[, -13] + 1), method = "pca", :
Std. deviations could not be computed for: IL_1alpha, IL_3
Error in prcomp.default(x[, method$pca, drop = FALSE], scale = TRUE, retx = FALSE) :
cannot rescale a constant/zero column to unit variance
看起来R中PCA的其他人的问题是零差异列,但是因为我可以证明我在这里没有这个问题,任何想法可能导致这个问题?< / p>
答案 0 :(得分:2)
很抱歉,我没有代表发表评论,所以发帖作为答案,但在运行代码后,特别是这一行:
log10(training1[, -13]+1)
在某些列中返回NaN
个值(实际为IL_1alpha
和IL_3
):
Warning messages:
1: In lapply(X = x, FUN = .Generic, ...) : NaNs produced
所以这似乎是错误的根源。也许你不应该记录负数的对数并考虑其他转换(或者是否有必要)?