title: fitcdiscr function in MatLab
body: <p>I'm attempting to use the fitcdiscr class to reproduce SAS results, but I'm evidently not using the function correctly.  I've been through the MatLab documentation on the subject repeatedly, but can't seem to figure out what I'm specifying incorrectly.  I'll first post the data, then the SAS code that is specifying the correct linear discriminant functions, then the MatLab code that I'm struggling with.  Any help would be appreciated.</p>
  
  <p>Data:</p>
  
  <pre><code>a 191 131 53
  a 185 134 50
  a 200 137 52
  a 173 127 50
  a 171 128 49
  a 160 118 47
  a 188 134 54
  a 186 129 51
  a 174 131 52
  a 163 115 47
  b 186 107 49
  b 211 122 49
  b 201 144 47
  b 242 131 54
  b 184 108 43
  b 211 118 51
  b 217 122 49
  b 223 127 51
  b 208 125 50
  b 199 124 46
  </code></pre>
  
  <p>SAS:</p>
  
  <pre><code>options ls=78;
  title "Discrimant Analysis - Insect Data";
  data insect;
  infile "C:\Users\Zach\Documents\Classes\Penn State\STAT 505\Data\insect.txt";
  input species $ joint1 joint2 aedeagus;
  run;
  data test;
  input joint1 joint2 aedeagus;
  cards;
  194 124 49
  ;
  proc discrim data=insect pool=test crossvalidate testdata=test testout=a;
  class species;
  var joint1 joint2 aedeagus;
  run;
  proc print;
  run;
  </code></pre>
  
  <p>MatLab:</p>
  
  <pre><code>path = 'C:\Users\Zach\Documents\Classes\Penn State\STAT 505\Data';
  file = 'insect.txt';
  
  fid = fopen(fullfile(path,file));
  X = textscan(fid, '%s%f%f%f','Delimiter');
  fclose(fid); clear fid
  
  data = cell2mat(X(:,2:4));%data
  grps = X{:,1};%group a or b
  prednames = {'joint 1', 'joint 2', 'aedeagus'};
  
  M = fitcdiscr(data,grps,'PredictorNames',prednames,...
      'Prior','uniform','DiscrimType','linear');
  </code></pre>
  
  <p>The linear functions are specified using variants of</p>
  
  <pre><code>M.Coeffs(1,2).Linear  and  M.Coeffs(1,2).Const
  </code></pre>
  
  <p>The two functions I'm expecting are:</p>
  
  <p>da = -247 -1.4x1 + 1.5x2 10.9x3</p>
  
  <p>db = -193 - .74x1 + 1.1x2 + 8.3x3</p>
  
  <p>Thanks for the help.</p>
  
  <p>Edit:</p>
  
  <p>Using "Applied Multivariate Statistical Analysis, 6th ed" by Johnson and Wichern, section 11.3, I've produced the following code that gives me the SAS results:</p>
  
  <pre><code>xbar = M.Mu;
  S = M.Sigma;
  Sinv = inv(S);
  for ii = 1:2
      d0(ii,:) = -1/2*xbar(ii,:)*Sinv*xbar(ii,:)';
      d(ii,:) = xbar(ii,:)*Sinv;
  end
  </code></pre>
  
  <p>I'm still left wondering just what fitcdiscr is doing.</p>