[hyperSpec-help] examples for doing pls and cross validation using hyperSpec

beleites,claudia claudia.beleites at ipht-jena.de
Wed Jul 25 12:19:03 CEST 2012


Dear Renuka,

about *pls*:
you can do pls for hyperSpec objects just in the same way you do other kinds of modelling
pls::plsr expects the data to be in a data.frame. as.data.frame (hyperSpecobject) does this, and you can also use the $. shortcut:
plsr (c ~ spc, data = flu$.)
Note that this is exacty the same approach as in the PCA example.

Also *cross validation* is independent of hyperSpec. You can either use the builtin cross validation of plsr (if your spectra are independent), use dedicated packages like e.g. boot or Andreas Alfons' cvTools, or write your own cross validation loop.

Regarding the questions you sent off-list:

*plotting multiple spectra in one plot*:
please do your homework first and look into the plotting vignette and the help for plotspc.


*In PCA plot: I had used .class to pair my first two scores. Now how do I know which symbol represents which class?*:
This again has nothing to do with hyperSpec. The symbols are in their usual order.
You can see their order e.g. by: 
> classes <- unique (chondro$clusters)
> classes
[1] matrix lacuna <NA>   cell  
Levels: matrix lacuna cell
> plot (seq_along (classes), classes, pch = as.numeric (classes))

*error in map.identify*
map.identify is for identifying spectra in a false-colour map plot. You try to run this command on a pairs plot which is something completely different (and again outside the scope of hyperSpec). What you are looking for is the identify function for pairs plots. I have no idea whether such a function exists already, but I posted the question on stackoverflow: http://stackoverflow.com/q/11647331/755257
However, the functionality exists with lattice graphics:
> splom (matrix (rnorm (30), 10))
> trellis.focus ()
> panel.link.splom ()
[1] 7

*error in plotmap with cluster results*
Two problems here. The error message you got tells you that your call doesn't obey the syntax of plotmap. But: plotmap is for false colour _maps_, i.e. you need to specify _two_ extra data columns (like the x and y coordinates of the chondro object. Your lignin object does not have such columns. So plotmap is the wrong function anyways. 

You can plot the clusters over the rows, e.g.

plot (seq_along (chondro), chondro$clusters)



More information about the hyperspec-help mailing list