Home > matlabmk > fast_t1.m

fast_t1

PURPOSE ^

fast_t1 - Computes a 2D matrix of one sample/repeated measures t-tests

SYNOPSIS ^

function [p_values, t_scores, mn, stder]=fast_t1(data,tail,verblevel)

DESCRIPTION ^

 fast_t1 - Computes a 2D matrix of one sample/repeated measures t-tests 
           relatively quickly.

 Usage:
 [p_values, t_scores, mn, stder]=fast_t1(data,tail,verblevel);

 Inputs:
  data   - 3D matrix of data (Channel x Time x Participant)

 Optional Inputs:
  tail        - [1 | 0 | -1] If tail=1, the alternative hypothesis is that the
                mean of data is greater than 0 (upper tailed test).  If tail=0,
                the alternative hypothesis is that the mean of data is different
                than 0 (two tailed test).  If tail=-1, the alternative hypothesis
                is that the mean of the data is less than 0 (lower tailed test).
                {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 at each time point and electrode (no correction
                for multiple comparisons)
  t_scores    - t-score at each time point and electrode
  mn          - mean voltage at each time point and electrode
  stder       - standard error of the mean voltage at each time point and 
                electrode

 Author:
 David Groppe
 May, 2010
 Kutaslab, San Diego

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % fast_t1 - Computes a 2D matrix of one sample/repeated measures t-tests
0002 %           relatively quickly.
0003 %
0004 % Usage:
0005 % [p_values, t_scores, mn, stder]=fast_t1(data,tail,verblevel);
0006 %
0007 % Inputs:
0008 %  data   - 3D matrix of data (Channel x Time x Participant)
0009 %
0010 % Optional Inputs:
0011 %  tail        - [1 | 0 | -1] If tail=1, the alternative hypothesis is that the
0012 %                mean of data is greater than 0 (upper tailed test).  If tail=0,
0013 %                the alternative hypothesis is that the mean of data is different
0014 %                than 0 (two tailed test).  If tail=-1, the alternative hypothesis
0015 %                is that the mean of the data is less than 0 (lower tailed test).
0016 %                {default: 0}
0017 %  verblevel   - An integer specifiying the amount of information you want
0018 %                this function to provide about what it is doing during runtime.
0019 %                 Options are:
0020 %                    0 - quiet, only show errors, warnings, and EEGLAB reports
0021 %                    1 - stuff anyone should probably know
0022 %                    2 - stuff you should know the first time you start working
0023 %                        with a data set {default value}
0024 %                    3 - stuff that might help you debug (show all
0025 %                        reports)
0026 %
0027 % Outputs:
0028 %  p_values    - p-value at each time point and electrode (no correction
0029 %                for multiple comparisons)
0030 %  t_scores    - t-score at each time point and electrode
0031 %  mn          - mean voltage at each time point and electrode
0032 %  stder       - standard error of the mean voltage at each time point and
0033 %                electrode
0034 %
0035 % Author:
0036 % David Groppe
0037 % May, 2010
0038 % Kutaslab, San Diego
0039 
0040 %%%%%%%%%%%%%%%% REVISION LOG %%%%%%%%%%%%%%%%%
0041 %
0042 
0043 
0044 function [p_values, t_scores, mn, stder]=fast_t1(data,tail,verblevel)
0045 
0046 if nargin<1,
0047     error('You need to provide data.');
0048 end
0049 
0050 if nargin<2,
0051     tail=0; %default two-tailed test
0052 elseif (tail~=0) && (tail~=1) && (tail~=-1),
0053     error('Argument ''tail'' needs to be 0,1, or -1.');
0054 end
0055 
0056 if nargin<3,
0057    verblevel=2; 
0058 end
0059 
0060 [n_chan, n_pts, n_subs]=size(data);
0061 df=n_subs-1;
0062 if n_subs<2,
0063     error('You need data from at least two observations (e.g., participants) to perform a hypothesis test.')
0064 end
0065 
0066 if verblevel~=0,
0067     fprintf('fast_t1: Number of channels: %d\n',n_chan);
0068     fprintf('fast_t1: Number of time points: %d\n',n_pts);
0069     fprintf('fast_t1: Total # of comparisons: %d\n',n_pts*n_chan);
0070     fprintf('fast_t1: Number of participants: %d\n',n_subs);
0071     fprintf('t-score degrees of freedom: %d\n',df);
0072 end
0073 
0074 sm=sum(data,3);
0075 mn=sm/n_subs;
0076 sm_sqrs=sum(data.^2,3)-(sm.^2)/n_subs;
0077 stder=sqrt(sm_sqrs/(n_subs*df));
0078 t_scores=mn./stder;
0079 if tail<0,
0080     %lower tailed test
0081     p_values=tcdf(t_scores,df);
0082 elseif tail>0,
0083     %upper tailed test
0084     p_values=1-tcdf(t_scores,df);
0085 else
0086     %two tailed test
0087     p_values=tcdf(t_scores,df);
0088     ids=find(p_values>.5); %t-scores above zero
0089     p_values(ids)=1-p_values(ids); 
0090     p_values=p_values*2; %double for two tailed test
0091 end
0092

Generated on Tue 10-May-2016 16:37:45 by m2html © 2005