1

I have been finding HyperSpec to very useful, however, I continue to receive errors when running through "Outlier Removal by Principal Component Analysis (PCA)" following the steps in the Chondro tutorial . The code I'm running is below:

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)

This results in a plot of the first 20 score pairs as expected. When I try to identify spectra:

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

I receive the following error:

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

Any suggestions would be greatly appreciated.

Thank you Haley

**edit

I've added an example file. Here is the code I used to import and pre-process the file:

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])

file example: t0_CA_bln_adj

Haley Sapers
  • 103
  • 10

0 Answers0