bootsigmoid.m 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. function [p,D]=bootsigmoid(A,B,varargin)
  2. % [p,D]=bootsigmoid(A,B,varargin)
  3. % Takes two sets of N x 2 binomial data A and B, and fits sigmoids to them
  4. % both. It then uses the mean and covariance of the fits to calculate the
  5. % distance (using the projection of the fits onto fisher's linear
  6. % discriminant) of the fits.
  7. % Then we permute the rows of A and B to generate permuted data sets and
  8. % perform the same fits and estimates of "distance". Finally, the distance
  9. % between A and B fits are compared to the distribution of distances
  10. % generated by permuting A and B.
  11. BOOTS=10000;
  12. utils.overridedefaults(who,varargin);
  13. import stats.*
  14. n_A=size(A,1);
  15. n_B=size(B,1);
  16. [betaA,~,~,covA,~]=nlinfit(A(:,1),A(:,2),@sig4,[0 1 0 10]);
  17. [betaB,~,~,covB,~]=nlinfit(B(:,1),B(:,2),@sig4,[0 1 0 10]);
  18. vAB=flda(betaA,betaB,covA,covB,n_A,n_B);
  19. dAB=abs(betaA*vAB-betaB*vAB);
  20. permAB=nan(BOOTS,1);
  21. M=[A;B];
  22. parfor bx=1:BOOTS
  23. rperm=randperm(n_A+n_B);
  24. rA=M(rperm(1:n_A),:);
  25. rB=M(rperm((n_A+1):end),:);
  26. [rbetaA,~,~,rcovA,~]=nlinfit(rA(:,1),rA(:,2),@sig4,[0 1 0 10]);
  27. [rbetaB,~,~,rcovB,~]=nlinfit(rB(:,1),rB(:,2),@sig4,[0 1 0 10]);
  28. rvAB=flda(rbetaA,rbetaB,rcovA,rcovB,n_A,n_B);
  29. permAB(bx)=abs(rbetaA*rvAB-rbetaB*rvAB);
  30. end
  31. p= stats.get_p(dAB,permAB);
  32. D.ld=vAB;
  33. D.betaA=betaA;
  34. D.betaB=betaB;
  35. D.permAB=permAB;
  36. D.dAB=dAB;