0001 function pval = chi2test(J1,Var1,J2,Var2,Norient)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 if nargin < 2
0021 help chi2test;
0022 return;
0023 end
0024
0025 if nargin < 5
0026 Norient = 1;
0027 end
0028
0029 [Nvall,Nt]= size(J1);
0030 Nv = Nvall/Norient;
0031
0032 if nargin < 3 | isempty(J2) | isempty(Var2)
0033 fprintf('--- P-value of one population away from zeros using Chi2 statistics \n');
0034 J2 = zeros(Nvall,Nt);
0035 Var2 = zeros(Nvall,Nt);
0036 else
0037 fprintf('--- P-value of two populations difference using Chi2 statistics \n');
0038 end
0039
0040
0041 switch Norient
0042 case 1,
0043
0044 Jx = J1-J2;
0045 Varx = Var1+Var2;
0046 tmp = Jx.^2./Varx;
0047 XX2 = sum(tmp,2);
0048
0049 pval=spm_Gcdf(XX2,Nt/2,1/2);
0050 case 2,
0051
0052 Jx = J1([1:Nv],:)-J2([1:Nv],:);
0053 Jy = J1([1:Nv]+Nv,:)-J2([1:Nv]+Nv,:);
0054 Varx = Var1([1:Nv])+Var2([1:Nv]);
0055 Vary = Var1([1:Nv]+Nv)+Var2([1:Nv]+Nv);
0056 tmp = (Jx.^2./Varx)+ (Jy.^2./Vary);
0057 XX2 = sum(tmp,2);
0058
0059 pval=spm_Gcdf(XX2,2*Nt/2,1/2);
0060 case 3,
0061
0062 Jx = J1([1:Nv],:)-J2([1:Nv],:);
0063 Jy = J1([1:Nv]+Nv,:)-J2([1:Nv]+Nv,:);
0064 Jz = J1([1:Nv]+2*Nv,:)-J2([1:Nv]+2*Nv,:);
0065 Varx = Var1([1:Nv])+Var2([1:Nv]);
0066 Vary = Var1([1:Nv]+Nv)+Var2([1:Nv]+Nv);
0067 Varz = Var1([1:Nv]+2*Nv)+Var2([1:Nv]+2*Nv);
0068 tmp = (Jx.^2./Varx)+(Jy.^2./Vary)+(Jz.^2./Varz); ;
0069 XX2 = sum(tmp,2);
0070
0071 pval=spm_Gcdf(XX2,3*Nt/2,1/2);
0072 end