在HyperSpec中使用PCA异常值检测时出错

时间:2018-03-04 07:28:03

标签: r hyperspec

我一直认为HyperSpec非常有用,但是,按照Chondro 教程中的步骤执行“通过主成分分析(PCA)进行异常删除”后,我仍然会收到错误。我正在运行的代码如下:

pca <- prcomp (spc_N2, center = TRUE)
scores <- decomposition (spc_N2, pca$x, label.wavelength="PC",label.spc_N2="score/a.u.")
loadings <- decomposition (spc_N2, t(pca$rotation), scores = FALSE,label.spc_N2="laoding I/a.u.") 
pairs (scores [[,,1:20]], pch = 19, cex = 0.5)

这导致前20个分数对的图表如预期的那样。当我尝试识别光谱时:

out <- map.identify (scores [,,5])

我收到以下错误:

Error in eval(modelRHS[[2]], data, env) : object 'x' not found

任何建议都将不胜感激。

谢谢 哈利

**编辑

我添加了一个示例文件。这是我用来导入和预处理文件的代码:

library(hyperSpec)

#import file
file <- read.table ("t0_CA_bln_adj.csv", header = TRUE, dec = ".", sep = ",")
spc <- new ("hyperSpec", wavelength = file [,1], spc = t (file [, -1]), data = data.frame (sample = colnames (file [, -1])), labels = list ((.wavelength = "cm-1"), spc = "I"))

#initial plot
plot (spc)

#intensity standardize to mean of N2 peak
factors_N2 <- 1/apply(spc[, , 2200~2400],1,mean)
spc_N2<-sweep(spc,1,factors_N2,"*")
plot(spc_N2)

#PCA
pca <- prcomp (spc_N2, center = TRUE)
scores <- decomposition (spc_N2, pca$x, label.wavelength="PC",label.spc_N2="score/a.u.")
loadings <- decomposition (spc_N2, t(pca$rotation), scores = FALSE,label.spc_N2="laoding I/a.u.") 

#plot score plots of the first 20 and first 5 PCs
pairs (scores [[,,1:20]], pch = 19, cex = 0.5)
pairs (scores [[,,1:5]], pch = 19, cex = 0.5)

#attempt to identify outliers
out <- map.identify (scores [,,5])

文件示例:t0_CA_bln_adj

0 个答案:

没有答案