function Chi2_plot(data)

  [n,p]=size(data);
  
  x=data;
  
  S=cov(x);
  
  for i=1:n
   d(i)=(x(i,:)-mean(x))*inv(S)*(x(i,:)-mean(x))';
  end
  
  
  d_sort=sort(d);
  
  q_Q=((1:1:n)-1/2)/n;
  
  Quantile=chi2inv(q_Q,p);
  
  scatter(Quantile,d_sort);
  
  ylabel('d(j)');
  
  xlabel('q_{c,2}(j)');
 