Home > vbmeg > functions > tool_box > statistical_test > chi2test.m

chi2test

PURPOSE ^

chi2 test under null hypothesis of two populations have equal means

SYNOPSIS ^

function pval = chi2test(J1,Var1,J2,Var2,Norient)

DESCRIPTION ^

 chi2 test under null hypothesis of two populations have equal means

 --- syntax
 pval = chi2test(J1,Var1)        *** H0 : J1=0
 pval = chi2test(J1,Var1,J2,Var2)   *** H0 : J1=J2
 pval = chi2test(J1,Var1,[],[],2)
 
 --- input
 J1, Var1 :
 J2, Var2 :
 
 --- optional
 Norient : number of dipole orientation to be estimated

 "chi2cdf" is requried!! --> spm_Gcdf() is required !

 2005-07-20 O.Y

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function pval = chi2test(J1,Var1,J2,Var2,Norient)
0002 % chi2 test under null hypothesis of two populations have equal means
0003 %
0004 % --- syntax
0005 % pval = chi2test(J1,Var1)        *** H0 : J1=0
0006 % pval = chi2test(J1,Var1,J2,Var2)   *** H0 : J1=J2
0007 % pval = chi2test(J1,Var1,[],[],2)
0008 %
0009 % --- input
0010 % J1, Var1 :
0011 % J2, Var2 :
0012 %
0013 % --- optional
0014 % Norient : number of dipole orientation to be estimated
0015 %
0016 % "chi2cdf" is requried!! --> spm_Gcdf() is required !
0017 %
0018 % 2005-07-20 O.Y
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 %% test statistics (sum of squres)  H0: J1(t)=J2(t) forall t
0041 switch Norient
0042     case 1,
0043         %fprintf('--- Number of Dipoles Orientations : %d \n', Norient);
0044         Jx = J1-J2;
0045         Varx = Var1+Var2; 
0046         tmp = Jx.^2./Varx;
0047         XX2 = sum(tmp,2); %% follows chi2 of freedom Nt
0048        % pval=chi2cdf(XX2, Nt);
0049         pval=spm_Gcdf(XX2,Nt/2,1/2);
0050     case 2,
0051         %fprintf('--- Number of Dipoles Orientations : %d \n', Norient);
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); %% follows chi2 of freedom 2*Nt
0058        % pval=chi2cdf(XX2, 2*Nt);
0059         pval=spm_Gcdf(XX2,2*Nt/2,1/2);
0060     case 3,
0061         %fprintf('--- Number of Dipoles Orientations : %d \n', Norient);
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); %% follows chi2 of freedom 3*Nt
0070        % pval=chi2cdf(XX2, 3*Nt);
0071         pval=spm_Gcdf(XX2,3*Nt/2,1/2);
0072 end

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005