Skip to main content
  • Description
  • Performs a statistical analysis of the time-frequency representation of single-trials computed from an .eeg file. Two statistical tests are proposed on the TF power averaged over regions of interest defined in the time-frequency domain.
    - a Wilcoxon test (non-parametric paired comparison) for the detection of an emerging TF component with respect to a baseline period. The test is performed indepedantly for each event code and each channel.
    - a Kruskal-Wallis test (one-way analysis of variance by ranks) for the statistical comparison of the time-frequency activities across different event codes.
    The region of interest is defined by its size and a moving step (in Hz x ms) to cover the whole time-frequency domain. This program creates .tf files representing the statistical values (Z for Wilcoxon, H for Kruskal-Wallis and their related probability values p) computed in each time-frequency window. They can be viewed by tfviz as time-frequency plots.
    The False Detection Rate (FDR) procedure is also possible on the Wilcoxon or Kruskal-Wallis statistical results (see comments).


  • Usage
  • tfstat myeegfile.eeg myeventfile.pos myparfile.par

    with :

    • myeegfile.eeg : input EEG file name (with extension).
    • myeventfile.pos : event position file (with extension) (this is usually the output pos file of eegavg, after artifact rejection).
    • myparfile.par: text file containing computation parameters (with extension).


  • Fields of parameter file and example
  • fileprefix myfilename Prefix of the output TF files.
    nb_eventcode 2 Number of event codes to process.
    list_eventcode 2 5 List of the event codes to process.
    prestim_nbsample 400 400 List of the numbers of samples in the prestimulus period; one value for each event code.
    poststim_nbsample 1000 1000 List of the numbers of samples in the poststimulus period; one value for each event code; the total number of samples of the analysis is prestim_nbsample + poststim_nbsample + 1, the extra sample corresponds to the event itself.
    tf_channel_flag 1 1 0 1 0 0 0 List of the channels to process: 1/0 for selected/unselected channels; the total number of flags is N+2, N being the number of recorded channels in myeegfile.eeg file; the last 2 flags should be set to 0.
    In this example, N=5, and only channels number 1, 2, 4 will be processed.
    tf_channel_ref 0 3 0 5 0 0 0 List of the new reference for each channel before processing (bipolar montage for instance):
    0: no change of the reference,
    ≠0: electrode number (rank) to which the current channel should be re-referenced.
    The total number of values is N+2, N being the number of recorded channels in myfile.eeg file; the last 2 flags should be set to 0.
    If omitted, the channels are not modified.
    In this example, N=5, and channel 1 is unchanged, channel 2 is referenced to channel 3, and channel 4 re-referenced to channel 5.
    tf_freq_start 10 10 List of the starting frequencies (in Hz) for the time-frequency analysis (one value for each event code).
    tf_freq_stop 80 80 List of the ending frequencies (in Hz) for the time-frequency analysis (one value for each event code).
    tf_freq_step 2 2 List of the frequency steps (in Hz) for the time-frequency analysis (one value for each event code).
    tf_nb_sample_blackman 100 100 List of the number of samples in the rise or fall time period of the blackman window applied on the single trials before the wavelet transform (one value for each event code).
    tf_wavelet_type 1 1 List of the types of wavelet used for the time-frequency analysis (one value for each event code):
    1: Morlet wavelet.
    2: Gabor wavelet.
    tf_morlet_m 7 7 In case of Morlet wavelet, list of the m ratio used for the time-frequency analysis (one value for each event code): m=f0/sigmaf
    Suggested values for m: m>5, usually m=7.
    This determines the number of cycles of the wavelet.
    tf_gabor_sigmat 100 100 In case of Gabor wavelet, list of the half-window durations of the wavelets (in msec) irrespective of the frequency band (one value for each event code).
    tf_type_stat 2 Type of statistical analysis based on single-trial time-frequency regions of interest:
    1: Wilcoxon test on each moving time-frequency region of interest with respect to a baseline period.
    2: Kruskal-Wallis test on each moving time-frequency region of interest between the different event codes.
    tfstat_baseline_flag 1 1 List of flags by event code for applying a baseline correction on single-trials prior to the Kruskal-Wallis test:
    0: no baseline correction.
    1: baseline correction applied.
    If omitted, the default value is 0.
    tfstat_freq_hw 10 10 List of the frequency half-windows (in Hz) by event code, used to defined the moving time-frequency regions of interest on which statistical analysis will be performed.
    tfstat_freq_step 5 5 List of the frequency steps (in Hz) by event code, used to define the moving step of the time-frequency regions of interest on which statistical analysis will be performed.
    tfstat_time_hw 200 200 List of the time half-windows (in ms) by event code, used to define the moving time-frequency regions of interest on which statistical analysis will be performed.
    If = 0, then all time points are considered in the analysis.
    tfstat_time_step 50 50 List of the time steps (in ms) by event code, used to defined the moving step of the time-frequency regions of interest on which statistical analysis will be performed.
    tfstat_baseline_start -300 -300 List of the baseline start latencies (in ms) by event code.
    Required when tfstat_type_stat=1 (Wilcoxon test) or (tfstat_type_stat=2 and tfstat_baseline_flag=1).
    If omitted, the start latency is the first point of the pre-stimulus baseline defined by prestim_nbsample.
    tfstat_baseline_stop -100 -100 List of the baseline end latencies (in ms) by event code.
    Required when tfstat_type_stat=1 (Wilcoxon test) or (tfstat_type_stat=2 and tfstat_baseline_flag=1).
    If omitted, the stop latency is 0 ms.
    tf_flag_log 0 Statistical test on the power or the log of the power in the TF domain:
    0: statistics on power
    1: statistics on the log10 of the power.
    If omitted, the default value is 0.
    tfstat_flag_fdr 0 Flag allowing to compute False Detection Rate (FDR) after the statistical test:
    0: no FDR computation
    1: FDR computation, and generation of a TF file with a mask of the statistical results (Z or H) with the computed FDR (see output files below). This requires a probability (p) threshold value (tfstat_threshold_fdr).
    If omitted, the default value is 0.
    tfstat_threshold_fdr 0.05 To be used in case of tfstat_flag_fdr = 1.
    Defines the probability (p) threshold value to be used for masking the statistical results (Z or H) by the threshold FDR statistics.
    tfstat_kruskal_modified 0 In case of Kruskal-Wallis test with 2 conditions (2 event codes), this flag allows to indicate that all TF windows related to event code #2 is compared to a baseline window related to event code #1. For the definition of the baseline, see tfstat_kruskal_modified_baseline_beg_msec and tfstat_kruskal_modified_baseline_end_msec.
    Possible values are:
    0: standard case (no comparison of event code #2 to the baseline of even code #1)
    1: comparison of event code #2 to the baseline of event code #1
    If omitted, the default value is 0.
    tfstat_kruskal_modified_baseline_beg_msec -300 To be used if tfstat_kruskal_modified = 1.
    Latency of the beginning of the baseline period (in msec) relative to event code #1.
    tfstat_kruskal_modified_baseline_end_msec -50 To be used if tfstat_kruskal_modified = 1.
    Latency of the end of the baseline period (in msec) relative to event code #1.
    tf_substract_epfile ep.2.p ep.5.p List of the EP file names with extension (.p) used for substracting an averaged response to each single trial prior to time-frequency computation (one string for each event code). These .p files should be compatible to the time-frequency analysis parameters (number of channels, number of samples pre and post-stimulus). If omitted, no .p file is substracted to the single trials.
    tfstat_wilcox_modified 0 In case of Wilcoxon test with 2 conditions (2 event codes), this flag allows to indicate that all TF windows related to event code #2 is compared to a baseline window related to event code #1. Events must be paired.
    Possible values are:
    0: standard case (no comparison of event code #2 to the baseline of even code #1)
    1: comparison of event code #2 to the baseline of event code #1
    If omitted, the default value is 0.


  • Examples
  • In this example, all trials with codes 2 and 5 be processed with a time window ranging from 400 samples prior to 1000 samples after event code. The evoked potential read from respectively ep.2.p and ep.5.p are substracted to single trials. The time-frequency analysis will be performed on channels 1 (not re-referenced), 2 (re-referenced to channel 3),and 4 (re-referenced to channel 5), from 10 to 80 Hz by steps of 2 Hz with a Blackman window having 100 samples for the rise- and for the fall-time, and with Morlet wavelets with a m ratio set to 7. The statistical analysis is here a Kruskal-Wallis test between event codes 2, 5 and 8. On each trial, the time-frequency analysis is performed with a baseline correction defined between –300 and –100 ms and over a time-frequency region of interest of 20 Hz x 400 ms (2x10 Hz x 2x200 ms) moving by step of 5 Hz x 50 ms.

    Output files :

    Name Comments#
    myfilename.2.wil.Z.tf
    myfilename.5.wil.Z.tf
    myfilename.8.wil.Z.tf
    For the Wilcoxon test:
    TF files of the Z value of the Wilcoxon test for each event code.
    myfilename.2.wil.p.tf
    myfilename.5.wil.p.tf
    myfilename.8.wil.p.tf
    For the Wilcoxon test:
    TF files of the probability value (p) of the Wilcoxon test for each event code.
    myfilename.2.5.8.KW.H.tf For the Kruskal-Wallis test:
    TF file of the H value of the Kruskal-Wallis test computed on the 3 event codes (2, 5, 8).
    myfilename.2.5.8.KW.p.tf For the Kruskal-Wallis test:
    TF file of the probability value (p) of the Kruskal-Wallis test computed on the 3 event codes (2, 5, 8).
    myfilename.2.Z.fdr.tf For the Wilcoxon test:
    TF file of the Wilcoxon Z value masked by the thresholded probability value (p) of the FDR procedure.
    myfilename.2.5.8.H.fdr.tf For the Kruskal-Wallis test:
    TF file of the Kruskal-Wallis H value masked by the thresholded probability value (p) of the FDR procedure.


  • Comments
    1. tfstat_kruskal_modified : This option allows, for instance, to compare each position in the TF domaine related to an active condition (related to event code #2) to a resting state defined by the mean TF computed for each frequency in a given time-window (related to event code #1).
    2. tfstat_flag_fdr : This option allows to compute the False Detection Rate statistics after a Wilcoxon or a Kruskal-Wallis test. This is a possible solution for multiple testing problem. See: Genovese, C. R., N. A. Lazar, et al. (2002). "Thresholding of statistical maps in functional neuroimaging using the false discovery rate." Neuroimage 15(4): 870-8.


  • Current version
  • 1.30 22-09-2014

  • History
    • 1.00 18-09-2002 (PEA) : 1st documented version.
    • 1.01 22-10-2002 (PEA) : adds Kruskal-Wallis test.
    • 1.02 17-02-2003 (PEA) : changes tfmval... parameters to tfstat....
    • 1.03 26-09-2003 (PEA) : changes in physical values of EEG.
    • 1.04 03-10-2003 (PEA) : minor modification (removes debug informations).
    • 1.05 08-10-2003 (PEA) : fixes time window definition.
    • 1.06 13-10-2003 (PEA) : fixes time window definition.
    • 1.07 26-11-2003 (PEA) : supports 32 bits EEG.
    • 1.08 17-12-2003 (PEA) : fixes time window definition.
    • 1.09 08-01-2004 (PEA) : fixes time window definition.
    • 1.10 07-04-2005 (OB) : minor modification (event file reading).
    • 1.11 03-10-2005 (OB) : minor modification.
    • 1.12 30-10-2005 (OB) : limits display. Checks for compatiblity of baseline with pre and post-stimulus.
    • 1.14 18-04-2006 (OB) : fixes time window size and steps.
    • 1.15 17-10-2006 (PEA) : adds tfstat_kruskal_modified parameter.
    • 1.17 04-10-2007 (PEA) : adds ability to work on log10 of power.
    • 1.18 16-07-2008 (PEA) : adds FDR support.
    • 1.19 09-09-2008 (PEA) : minor modification (same shell_sort_float function as eegstat).
    • 1.20 02-02-2009 (PEA) : changes FDR output filename for Kruskal-Wallis test (adss all event codes to the filename).
    • 1.21 02-03-2010 (PEA) : adds tf_substract_epfile (as in tfavg) to substract evoked potential to all single trials before time-frequency transformation.
    • 1.22 11-05-2010 (PEA) : adds tfstat_wilcox_modified parameter to use baseline of 1st event in case of Wilcoxon test. Events must be paired.
    • 1.23 16-02-2011 (PEA) : updates to use cmake and free release of Elan. Fixes memory allocations.
    • 1.24 15-04-2011 (PEA) : changes Shell sort to Heap sort in FDR (faster algorithm).
    • 1.25 21-06-2011 (PEA) : uses threads to compute TF transform (TF transform function of libelansignal). Fixes number of frequencies problem.
    • 1.26 07-10-2011 (PEA) : adds test for at least 2 samples to test in Wilcoxon test.
    • 1.27 12-06-2012 (PEA) : minor modification for available memory for MAC OS X.
    • 1.28 17-07-2012 (PEA) : fixes an error in wilcox function of libstat when all samples are ties.
    • 1.29 25-03-2014 (PEA) : fixes an error appeared with 1.24 with 16 bits EEG data reference change. Change EEG data handling.
    • 1.30 22-09-2014 (PEA) : fixes an error baseline handling for Kruskal-Wallis test.


  • Files
  • $ELANPATH/bin/tfstat

  • See also
  • tfavg