fast_t2 - Computes a 2D matrix of independent sample t-tests relatively quickly. Usage: [p_values, t_scores, mn_dif, stder]=fast_t2(dataA,dataB,tail,verblevel); Inputs: dataA - 3D matrix of data (Channel x Time x Participant) for Group A dataB - 3D matrix of data (Channel x Time x Participant) for Group B Optional Inputs: tail - [1 | 0 | -1] If tail=1, the alternative hypothesis is that the mean of Group A is greater than that of Group B. If tail=0, the alternative hypothesis is that the mean of the groups are different than 0 (two tailed test). If tail=-1, the alternative hypothesis is that the mean of Group A is less than that of Group B. {default: 0} verblevel - An integer specifiying the amount of information you want this function to provide about what it is doing during runtime. Options are: 0 - quiet, only show errors, warnings, and EEGLAB reports 1 - stuff anyone should probably know 2 - stuff you should know the first time you start working with a data set {default value} 3 - stuff that might help you debug (show all reports) Outputs: p_values - p-value of difference between groups at each time point and electrode (no correction for multiple comparisons) t_scores - t-score of difference between groups at each time point and electrode mn_dif - mean voltage difference between groups at each time point and electrode (Group A-Group B) stder - standard error of the mean voltage difference at each time point and electrode Author: David Groppe May, 2010 Kutaslab, San Diego
0001 % fast_t2 - Computes a 2D matrix of independent sample t-tests relatively 0002 % quickly. 0003 % 0004 % Usage: 0005 % [p_values, t_scores, mn_dif, stder]=fast_t2(dataA,dataB,tail,verblevel); 0006 % 0007 % Inputs: 0008 % dataA - 3D matrix of data (Channel x Time x Participant) for Group A 0009 % dataB - 3D matrix of data (Channel x Time x Participant) for Group B 0010 % 0011 % Optional Inputs: 0012 % tail - [1 | 0 | -1] If tail=1, the alternative hypothesis is that 0013 % the mean of Group A is greater than that of Group B. If tail=0, 0014 % the alternative hypothesis is that the mean of the groups are different 0015 % than 0 (two tailed test). If tail=-1, the alternative hypothesis 0016 % is that the mean of Group A is less than that of Group B. 0017 % {default: 0} 0018 % verblevel - An integer specifiying the amount of information you want 0019 % this function to provide about what it is doing during runtime. 0020 % Options are: 0021 % 0 - quiet, only show errors, warnings, and EEGLAB reports 0022 % 1 - stuff anyone should probably know 0023 % 2 - stuff you should know the first time you start working 0024 % with a data set {default value} 0025 % 3 - stuff that might help you debug (show all 0026 % reports) 0027 % 0028 % Outputs: 0029 % p_values - p-value of difference between groups at each time point 0030 % and electrode (no correction for multiple comparisons) 0031 % t_scores - t-score of difference between groups at each time point 0032 % and electrode 0033 % mn_dif - mean voltage difference between groups at each time point 0034 % and electrode (Group A-Group B) 0035 % stder - standard error of the mean voltage difference at each time 0036 % point and electrode 0037 % 0038 % Author: 0039 % David Groppe 0040 % May, 2010 0041 % Kutaslab, San Diego 0042 0043 %%%%%%%%%%%%%%%% REVISION LOG %%%%%%%%%%%%%%%%% 0044 % 0045 0046 0047 function [p_values, t_scores, mn_dif, stder]=fast_t2(dataA,dataB,tail,verblevel) 0048 0049 if nargin<2, 0050 error('You need to provide data.'); 0051 end 0052 0053 if nargin<3, 0054 tail=0; %default two-tailed test 0055 elseif (tail~=0) && (tail~=1) && (tail~=-1), 0056 error('Argument ''tail'' needs to be 0,1, or -1.'); 0057 end 0058 0059 if nargin<4, 0060 verblevel=2; 0061 end 0062 0063 [n_chanA, n_ptsA, n_subsA]=size(dataA); 0064 [n_chanB, n_ptsB, n_subsB]=size(dataB); 0065 if n_chanA~=n_chanB, 0066 error('dataA and dataB have a different number of channels. They need to be the same.') 0067 end 0068 if n_ptsA~=n_ptsB, 0069 error('dataA and dataB have a different number of time points. They need to be the same.') 0070 end 0071 0072 df=n_subsA+n_subsB-2; 0073 if verblevel~=0, 0074 fprintf('fast_t2: Number of channels: %d\n',n_chanA); 0075 fprintf('fast_t2: Number of time points: %d\n',n_ptsA); 0076 fprintf('fast_t2: Total # of comparisons: %d\n',n_ptsA*n_chanA); 0077 fprintf('fast_t2: Number of participants in Group A: %d\n',n_subsA); 0078 fprintf('fast_t2: Number of participants in Group B: %d\n',n_subsB); 0079 fprintf('t-score degrees of freedom: %d\n',df); 0080 end 0081 0082 smA=sum(dataA,3); 0083 mnA=smA/n_subsA; 0084 ssA=sum(dataA.^2,3)-(smA.^2)/n_subsA; 0085 0086 smB=sum(dataB,3); 0087 mnB=smB/n_subsB; 0088 ssB=sum(dataB.^2,3)-(smB.^2)/n_subsB; 0089 0090 mult_fact=(n_subsA+n_subsB)/(n_subsA*n_subsB); 0091 pooled_var=(ssA+ssB)/df; 0092 stder=sqrt(pooled_var*mult_fact); 0093 0094 mn_dif=mnA-mnB; 0095 t_scores=mn_dif./stder; 0096 0097 if tail<0, 0098 %lower tailed test 0099 p_values=tcdf(t_scores,df); 0100 elseif tail>0, 0101 %upper tailed test 0102 p_values=1-tcdf(t_scores,df); 0103 else 0104 %two tailed test 0105 p_values=tcdf(t_scores,df); 0106 ids=find(p_values>.5); %t-scores above zero 0107 p_values(ids)=1-p_values(ids); 0108 p_values=p_values*2; %double for two tailed test 0109 end 0110 0111