12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- function [p,D]=bootsigmoid(A,B,varargin)
- % [p,D]=bootsigmoid(A,B,varargin)
- % Takes two sets of N x 2 binomial data A and B, and fits sigmoids to them
- % both. It then uses the mean and covariance of the fits to calculate the
- % distance (using the projection of the fits onto fisher's linear
- % discriminant) of the fits.
- % Then we permute the rows of A and B to generate permuted data sets and
- % perform the same fits and estimates of "distance". Finally, the distance
- % between A and B fits are compared to the distribution of distances
- % generated by permuting A and B.
- BOOTS=100000;
- utils.overridedefaults(who,varargin);
- import stats.*
- [dAB, D]=get_dist(A,B);
- n_A=size(A,1);
- n_B=size(B,1);
- permAB=nan(BOOTS,1);
- M=[A;B];
- parfor bx=1:BOOTS
-
- rperm=randperm(n_A+n_B);
- rA=M(rperm(1:n_A),:);
- rB=M(rperm((n_A+1):end),:);
-
-
- permAB(bx)=get_dist(rA,rB);
-
- end
- p= stats.get_p(dAB,permAB);
- D.permAB=permAB;
- D.p=p;
- end %sfunction
- function [dAB,D]=get_dist(A,B)
- n_A=size(A,1);
- n_B=size(B,1);
- aidx=randperm(n_A);
- bidx=randperm(n_B);
- Alim=floor(n_A/2);
- Blim=floor(n_B/2);
- trainAdx=aidx(1:Alim);
- trainBdx=bidx(1:Blim);
- testAdx=aidx(Alim+1:end);
- testBdx=bidx(Blim+1:end);
- [nbetaA,~,~,covA,~]=nlinfit(A(trainAdx,1),A(trainAdx,2),@sig4,[0 1 0 10]);
- [nbetaB,~,~,covB,~]=nlinfit(B(trainBdx,1),B(trainBdx,2),@sig4,[0 1 0 10]);
- vAB=flda(nbetaA,nbetaB,covA,covB,Alim,Blim);
- [betaA,~,~,~,~]=nlinfit(A(testAdx,1),A(testAdx,2),@sig4,[0 1 0 10]);
- [betaB,~,~,~,~]=nlinfit(B(testBdx,1),B(testBdx,2),@sig4,[0 1 0 10]);
- dAB=abs(betaA*vAB-betaB*vAB);
- D.trainbetaA=nbetaA;
- D.trainbetaB=nbetaB;
- D.testbetaA=betaA;
- D.testbetaB=betaB;
- D.covA=covA;
- D.covB=covB;
- D.vAB=vAB;
- D.dAB=dAB;
- end % subfunction
|