NMR Batch Correction Example Script: Difference between revisions

From Powers Wiki
(LearningSorting)
No edit summary
 
Line 1: Line 1:
== PLS Fit Model ==  
== PLS Fit Model ==  
   X = whole dataset (first & second);clsD = class info (dummy matrix).
  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);
   result = pls(X, clsD, @suv, [7,1], 1);
   mn = result.mean.X;sd = result.scale.X;
   mn = result.mean.X;
  sd = result.scale.X;
   Xscaled = (X-(repmat(mn,[size(X,1),1])))./(repmat(sd,[size(X,1),1]));%size(Xscaled)
   Xscaled = (X-(repmat(mn,[size(X,1),1])))./(repmat(sd,[size(X,1),1]));%size(Xscaled)
   XPLSfit = result.T*result.P';
   XPLSfit = result.T*result.P';
Line 21: Line 25:
Note: mean can be replaced with median in a median of median model.
Note: mean can be replaced with median in a median of median model.


[[category:Protocols]]
 
[[category:Data_Processing_and_Analysis]]
[[category:Data_Processing_and_Analysis]]

Latest revision as of 05:31, 20 January 2022

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.