22 feb. 2015

Reducing the X matrix (Binning)


There are situations where we have spectra with a huge amount of data points and we want to reduce the number of them. There are instruments which measure spectra every 0.5 nm. This is an important advance in order to make instruments more similar one to the other in the wavelength scale, so the transferability is better, but this feature does not represent and advance when we are developing a model or calibration. In this case the normal procedure is to reduce the number of data points.
Continue using the “prospectr” package we have a function which can help us to do this task.
The steps I follow for this task, were:
1.   I exported a CAL file from Win ISI (just the NIR segment) to Excel.
2.   I copied the Matrix from Excel into the Clipboard.
3.   I use this code to imported the X matrix into R:
hsoja.X<- as.matrix(read.table("clipboard",header=FALSE))
The dimension of this X matrix is: (159,2800), the number of samples is 159 and the number of wavelengths 2800. In the case that we have used a NIR instrument which acquires data points every 2 nm, the matrix would be (159,700), so the idea is to reduce the Matrix to this size.
plot(as.numeric(colnames(hsoja.X)),hsoja.X[1,],type="l",
+ xlab="wavelength",ylab="Absorbance")
4.   Now we use the “binning” function to reduce the matrix, keeping one data points every a certain number (bin.size).In this case we will use a bin size of 4, in order to have 2800:4 = 700 data points.
hsoja.X.bin<- binning(hsoja.X,bin.size=4)
5.   Now we can work with a more reduce X matrix.

No hay comentarios:

Publicar un comentario