NMR Batch Correction Example Script
From Powers Wiki
PLS Fit Model
first_value = your_choice1 %%You choose here second_value = your_choice2 %%You choose here too X = whole_dataset ([first_value:second_value],:); %%This selects a subset of data from your first choice to your second choice clsD = class_info (dummy_matrix); result = pls(X, clsD, @suv, [7,1], 1); mn = result.mean.X; sd = result.scale.X; Xscaled = (X-(repmat(mn,[size(X,1),1])))./(repmat(sd,[size(X,1),1]));%size(Xscaled) XPLSfit = result.T*result.P'; XscaledNew = Xscaled - XPLSfit; XNew = (XscaledNew.*(repmat(sd,[size(XscaledNew,1),1]))) + (repmat(mn,[size(XscaledNew,1),1]));
Mean of Mean Model
Xall = [Xtrain;Xtest]; refX = median(median(Xall)); mnXtrain = mean(mean(Xtrain)); newXtrain = Xtrain/repmat(mnXtrain, [size(Xtrain, 1), size(Xtrain, 2)]); newXtrain = newXtrain*repmat(refX, [size(Xtrain, 1), size(Xtrain, 2)]); mnXtest = mean(mean(Xtest)); newXtest = Xtest/repmat(mnXtest, [size(Xtest, 1), size(Xtest, 2)]); newXtest = newXtest*repmat(refX, [size(Xtest, 1), size(Xtest, 2)]);
Note: mean can be replaced with median in a median of median model.