jackknife.m 793 B

1234567891011121314151617181920212223242526272829
  1. function [m,jsd]=jackknife(x)
  2. % Compute jackknife estimates of the mean and standard deviation of input data x
  3. % Usage: [m,jsd]=jackknife(x)
  4. %
  5. % Inputs:
  6. % x : data in the form samples x trials
  7. %
  8. % Outputs:
  9. % m : estimate of the mean (across trials)
  10. % jsd: jackknife estimate of the standard deviation (across trials)
  11. [N,C]=size(x);
  12. if C==1; error('Need multiple trials'); end;
  13. m=mean(x,2);
  14. theta=zeros(N,C);
  15. for tr=1:C;
  16. i=setdiff((1:C),tr); % drop 1 trial
  17. y=sum(x(:,i),2)/(C-1); % mean over remaining trials
  18. theta(:,tr)=C*m-(C-1)*y; % pseudo values
  19. % yy(:,tr)=y;
  20. end;
  21. jm=mean(theta,2);
  22. jm=repmat(jm,[1 C]);
  23. % jm2=mean(yy,2);
  24. % jm2=repmat(jm2,[1 C]);
  25. jsd=sqrt(sum((theta-jm).^2,2)/(C*(C-1)));
  26. % jsd2=sqrt((C-1)*sum((yy-jm2).^2,2)/C);
  27. % jsd
  28. % jsd2