Skip to content

data structure for plsr

2 messages · Emma Jones, Bjørn-Helge Mevik

#
Emma Jones <evjones at ualberta.ca> writes:
Yes, you need to transpose the data so a coloumn corresponds to a
variable (response or predictor).
It is best to put all predictors (wavelengths) together in one matrix,
yes.  The same for the responses, if you have more than one response
coloumn.

This is untested, so there might be errors:

Assuming that your spectroscopic data is read into a data frame called
origspec:

## This should create a matrix with the wavelengths as coloumns:
spec <- t(as.matrix(origspec))

I don't know what your response is, so I'm just assuming it is in a
vector called resp.

# This would create a data frame suitable for plsr():
mydata <- data.frame(resp = resp, spec = I(spec))

Then you can analyse like this:

plsr(resp ~ spec, data = mydata, ....)