This shows you the differences between two versions of the page.

tutorial:cluster_permutation_timelock [2012/07/21 16:03] 89.156.125.19 [Plotting the results] |
tutorial:cluster_permutation_timelock [2015/03/19 16:20] (current) |
||
---|---|---|---|

Line 1: | Line 1: | ||

- | {{tag>tutorial statistics eeg meg timelock plot}} | + | {{tag>tutorial statistics eeg meg timelock plot MEG-language}} |

====== Cluster-based permutation tests on event related fields ====== | ====== Cluster-based permutation tests on event related fields ====== | ||

===== Introduction ===== | ===== Introduction ===== | ||

- | The objective of this tutorial is to give an introduction to the statistical analysis of event-related EEG and MEG data (denoted as MEEG data in the following) by means of cluster-based permutation tests. The tutorial starts with a long background section that sketches the background of permutation tests. Subsequently it is shown how to use FieldTrip to perform cluster-based permutation tests on actual axial and planar event-related fields in a between-trials and in a within-subjects design. | + | The objective of this tutorial is to give an introduction to the statistical analysis of event-related EEG and MEG data (denoted as MEEG data in the following) by means of cluster-based permutation tests. The tutorial starts with a long background section that sketches the background of permutation tests. Subsequently it is shown how to use FieldTrip to perform cluster-based permutation tests on actual axial and planar event-related fields in a between-trials (using single-subject data) and in a within-subjects design (using data from multiple subjects). |

- | In this tutorial we will continue working on the [[tutorial:shared:dataset|dataset]] described in the preprocessing tutorials. Below we will repeat code to select the trials and preprocess the data as described in the first tutorials ([[tutorial:Preprocessing|trigger based trial selection]], [[tutorial:artifacts|artifact rejection]], [[tutorial:eventrelatedaveraging|event related averaging and planar gradient]]). We assume that the preprocessing and averaging steps of the analysis are already clear for the reader. | + | |

+ | In this tutorial we will continue working on the [[tutorial:shared:dataset|dataset]] of a single subject described in the [[tutorial:preprocessing|trigger-based trial selection preprocessing tutorial]]. Below we will repeat code to select the trials and preprocess the data as described in the first tutorials ([[tutorial:Preprocessing|trigger based trial selection]], [[tutorial:artifacts|artifact rejection]], [[tutorial:eventrelatedaveraging|event related averaging and planar gradient]]). We assume that the preprocessing and averaging steps of the analysis are already clear for the reader. | ||

This tutorial is not covering statistical test on time-frequency representations. If you are interested in that, you can read the [[tutorial:cluster_permutation_freq|Cluster-based permutation tests on time-frequency data]] tutorial. If you are interested how parametric statistical tests can be used with FieldTrip, you can read the [[tutorial:eventrelatedstatistics|Parametric and non-parametric statistics on event-related fields]] tutorial. | This tutorial is not covering statistical test on time-frequency representations. If you are interested in that, you can read the [[tutorial:cluster_permutation_freq|Cluster-based permutation tests on time-frequency data]] tutorial. If you are interested how parametric statistical tests can be used with FieldTrip, you can read the [[tutorial:eventrelatedstatistics|Parametric and non-parametric statistics on event-related fields]] tutorial. | ||

Line 52: | Line 53: | ||

{{page>:tutorial:shared:preprocessing_fc_lp}} | {{page>:tutorial:shared:preprocessing_fc_lp}} | ||

- | The format of the preprocessed data is inconvenient for statistical analyses. A more convenient format is produced by **[[reference:ft_timelockanalysis|ft_timelockanalysis]]** with the option cfg.keeptrials = 'yes'. The output of **[[reference:ft_timelockanalysis|ft_timelockanalysis]]** contains an .avg field with the average event-related field, and a .trial field with the individual trial data. The output is stored in timelockFIC and timelockFC for the fully incongruent and the fully congruent condition. | + | Using the preprocessed data, we now create a data structure that is the average across trials, time-locked to a particular event, using **[[reference:ft_timelockanalysis|ft_timelockanalysis]]**. The output of **[[reference:ft_timelockanalysis|ft_timelockanalysis]]** contains an .avg field with the average event-related field, and a .trial field with the individual trial data. The output is stored in timelockFIC and timelockFC for the fully incongruent and the fully congruent condition. This output is then suitable, as well, for statististical analyses. |

- | **[[reference:ft_timelockanalysis|Ft_timelockanalysis]]** requires preprocessed data (see above), which is available from [[ftp://ftp.fcdonders.nl/pub/fieldtrip/tutorial/cluster_permutation_timelock/dataFIC_LP.mat]] and [[ftp://ftp.fcdonders.nl/pub/fieldtrip/tutorial/cluster_permutation_timelock/dataFC_LP.mat|dataFC_LP.mat]]. | + | To obtain the preprocessed data required by **[[reference:ft_timelockanalysis|ft_timelockanalysis]]** you can get it here from our ftp server:[[ftp://ftp.fieldtriptoolbox.org/pub/fieldtrip/tutorial/cluster_permutation_timelock/dataFIC_LP.mat|dataFIC_LP]] and [[ftp://ftp.fieldtriptoolbox.org/pub/fieldtrip/tutorial/cluster_permutation_timelock/dataFC_LP.mat|dataFC_LP.mat]]. |

load dataFIC_LP | load dataFIC_LP | ||

Line 65: | Line 66: | ||

==== Permutation test ==== | ==== Permutation test ==== | ||

- | Cluster-level permutation tests for event-related fields are performed by the function **[[reference:ft_timelockstatistics|ft_timelockstatistics]]**. This function takes as its arguments a configuration (cfg) and two or more data structures. These data structures must be produced by **[[reference:ft_timelockanalysis|ft_timelockanalysis]]** or **[[reference:ft_timelockgrandaverage|ft_timelockgrandaverage]]**, which all operate on preprocessed data. The argument list of **[[reference:ft_timelockstatistics|ft_timelockstatistics]]** must contain one data structure for every experimental condition. For comparing the data structures timelockFIC and timelockFC, you must call **[[reference:ft_timelockstatistics|ft_timelockstatistics]]** as follows: | + | Cluster-level permutation tests for event-related fields are performed by the function **[[reference:ft_timelockstatistics|ft_timelockstatistics]]**. This function takes as its input arguments a configuration structure(cfg) and two or more data structures. These data structures must be produced by **[[reference:ft_timelockanalysis|ft_timelockanalysis]]** or **[[reference:ft_timelockgrandaverage|ft_timelockgrandaverage]]**, which all operate on preprocessed data. The argument list of **[[reference:ft_timelockstatistics|ft_timelockstatistics]]** must contain one data structure for every experimental condition. For comparing the data structures timelockFIC and timelockFC, you must call **[[reference:ft_timelockstatistics|ft_timelockstatistics]]** as follows: |

[stat] = ft_timelockstatistics(cfg, timelockFIC, timelockFC); | [stat] = ft_timelockstatistics(cfg, timelockFIC, timelockFC); | ||

Line 73: | Line 74: | ||

cfg = []; | cfg = []; | ||

cfg.method = 'montecarlo'; % use the Monte Carlo Method to calculate the significance probability | cfg.method = 'montecarlo'; % use the Monte Carlo Method to calculate the significance probability | ||

- | cfg.statistic = 'indepsamplesT'; % use the independent samples T-statistic as a measure to | + | cfg.statistic = 'ft_statfun_indepsamplesT'; % use the independent samples T-statistic as a measure to |

% evaluate the effect at the sample level | % evaluate the effect at the sample level | ||

cfg.correctm = 'cluster'; | cfg.correctm = 'cluster'; | ||

Line 94: | Line 95: | ||

cfg.design = design; % design matrix | cfg.design = design; % design matrix | ||

- | cfg.ivar = 1; % number or list with indices, independent variable(s) | + | cfg.ivar = 1; % number or list with indices indicating the independent variable(s) |

We now describe these options one-by-one. | We now describe these options one-by-one. | ||

* With **cfg.method** = 'montecarlo' we choose the Monte Carlo method for calculating the significance probability. This significance probability is a Monte Carlo estimate of the p-value under the permutation distribution. | * With **cfg.method** = 'montecarlo' we choose the Monte Carlo method for calculating the significance probability. This significance probability is a Monte Carlo estimate of the p-value under the permutation distribution. | ||

- | * With **cfg.statistic** = 'indepsamplesT', we choose the independent samples T-statistic to evaluate the effect (the difference between the fully congruent and the fully incongruent condition) at the sample level. In cfg.statistic, many other test statistics can be specified. Which test statistic is appropriate depends on your research question and your experimental design. For instance, in a within-UO design, one must use the dependent samples T-statistic ('depsamplesT'). And if you want to compare more than two experimental conditions, you should choose an F-statistic ('indepsamplesF' or 'depsamplesF'). | + | * With **cfg.statistic** = 'ft_statfun_indepsamplesT', we choose the independent samples T-statistic to evaluate the effect (the difference between the fully congruent and the fully incongruent condition) at the sample level. In cfg.statistic, many other test statistics can be specified. Which test statistic is appropriate depends on your research question and your experimental design. For instance, in a within-UO design, one must use the dependent samples T-statistic ('ft_statfun_depsamplesT'). And if you want to compare more than two experimental conditions, you should choose an F-statistic ('ft_statfun_indepsamplesF' or 'ft_statfun_depsamplesFmultivariate'). |

* We use **cfg.clusteralpha** to choose the critical value that will be used for thresholding the sample-specific T-statistics. With cfg.clusteralpha = 0.05, every sample-specific T-statistic is compared with the critical value of the univariate T-test with a critical alpha-level of 0.05. (This statistical test would have been the most appropriate test if we had observed a single channel at a single time-point.) The value of cfg.clusteralpha does not affect the false alarm rate of the statistical test at the cluster-level. It is a rational threshold for deciding whether a sample should be considered a member of some large cluster of samples (which may or may not be significant at the cluster-level). | * We use **cfg.clusteralpha** to choose the critical value that will be used for thresholding the sample-specific T-statistics. With cfg.clusteralpha = 0.05, every sample-specific T-statistic is compared with the critical value of the univariate T-test with a critical alpha-level of 0.05. (This statistical test would have been the most appropriate test if we had observed a single channel at a single time-point.) The value of cfg.clusteralpha does not affect the false alarm rate of the statistical test at the cluster-level. It is a rational threshold for deciding whether a sample should be considered a member of some large cluster of samples (which may or may not be significant at the cluster-level). | ||

* We use **cfg.clusterstatistic** to choose the test statistic that will be evaluated under the permutation distribution. This is the actual test statistic and it must be distinguished from the sample-specific T-statistics that are used for thresholding. With cfg.clusterstatistic = 'maxsum', the actual test statistic is the maximum of the cluster-level statistics. A cluster-level statistic is equal to the sum of the sample-specific T-statistics that belong to this cluster. Taking the largest of these cluster-level statistics of the different clusters produces the actual test statistic. | * We use **cfg.clusterstatistic** to choose the test statistic that will be evaluated under the permutation distribution. This is the actual test statistic and it must be distinguished from the sample-specific T-statistics that are used for thresholding. With cfg.clusterstatistic = 'maxsum', the actual test statistic is the maximum of the cluster-level statistics. A cluster-level statistic is equal to the sum of the sample-specific T-statistics that belong to this cluster. Taking the largest of these cluster-level statistics of the different clusters produces the actual test statistic. | ||

Line 111: | Line 112: | ||

We now briefly discuss the configuration fields that are not specific for **[[reference:ft_timelockstatistics|ft_timelockstatistics]]**: | We now briefly discuss the configuration fields that are not specific for **[[reference:ft_timelockstatistics|ft_timelockstatistics]]**: | ||

- | cfg.channel = {'MEG'}; % cell-array with selected channel labels | + | cfg_neighb = []; |

- | cfg.latency = [0 1]; % time interval over which the experimental | + | |

- | % conditions must be compared (in seconds) | + | |

cfg_neighb.method = 'distance'; | cfg_neighb.method = 'distance'; | ||

- | neighbours = ... % specifies with which sensors other sensors | + | neighbours = ft_prepare_neighbours(cfg_neighb, dataFC_LP); |

- | ft_prepare_neighbours(... % can form clusters | + | |

- | cfg.neighb, dataFC_LP); | + | cfg.neighbours = neighbours; % the neighbours specify for each sensor with |

- | cfg.neighbours = neighbours; | + | % which other sensors it can form clusters |

+ | cfg.channel = {'MEG'}; % cell-array with selected channel labels | ||

+ | cfg.latency = [0 1]; % time interval over which the experimental | ||

+ | % conditions must be compared (in seconds) | ||

+ | | ||

With these two options, we select the spatio-temporal dataset involving all MEG channels and the time interval between 0 and 1 second. The two experimental conditions will only be compared on this selection of the complete spatio-temporal dataset. Also, feel free to consult | With these two options, we select the spatio-temporal dataset involving all MEG channels and the time interval between 0 and 1 second. The two experimental conditions will only be compared on this selection of the complete spatio-temporal dataset. Also, feel free to consult | ||

- | [[faq:how_can_i_define_neighbouring_sensors|our frequenly asked questions about prepare_neighbours]] | + | [[faq:how_can_i_define_neighbouring_sensors|our frequently asked questions about ft_prepare_neighbours]] |

One should be aware of the fact that the sensitivity of **[[reference:ft_timelockstatistics|ft_timelockstatistics]]** (i.e., the probability of detecting an effect) depends on the length of the time interval that is analyzed, as specified in cfg.latency. For instance, assume that the difference between the two experimental conditions extends over a short time interval only (e.g., between 0.3 and 0.4 sec.). If it is known in advance that this short time interval is the only interval where an effect is likely to occur, then one should limit the analysis to this time interval (i.e., choose cfg.latency = [0.3 0.4]). Choosing a time interval on the basis of prior information about the time course of the effect will increase the sensitivity of the statistical test. If there is no prior information, then one must compare the experimental conditions over the complete time interval. This is accomplished by choosing cfg.latency = 'all'. In this tutorial, we choose cfg.latency = [0 1] because EEG-studies have shown that the strongest effect of semantic incongruity is observed in the first second after stimulus presentation. | One should be aware of the fact that the sensitivity of **[[reference:ft_timelockstatistics|ft_timelockstatistics]]** (i.e., the probability of detecting an effect) depends on the length of the time interval that is analyzed, as specified in cfg.latency. For instance, assume that the difference between the two experimental conditions extends over a short time interval only (e.g., between 0.3 and 0.4 sec.). If it is known in advance that this short time interval is the only interval where an effect is likely to occur, then one should limit the analysis to this time interval (i.e., choose cfg.latency = [0.3 0.4]). Choosing a time interval on the basis of prior information about the time course of the effect will increase the sensitivity of the statistical test. If there is no prior information, then one must compare the experimental conditions over the complete time interval. This is accomplished by choosing cfg.latency = 'all'. In this tutorial, we choose cfg.latency = [0 1] because EEG-studies have shown that the strongest effect of semantic incongruity is observed in the first second after stimulus presentation. | ||

Line 136: | Line 138: | ||

=== The format of the output === | === The format of the output === | ||

- | The output can also be obtained from [[ftp://ftp.fcdonders.nl/pub/fieldtrip/tutorial/cluster_permutation_timelock/stat_ERF_axial_FICvsFC.mat|stat_ERF_axial_FICvsFC.mat]]. If you need to reload the statistics output, use: | + | The output can also be obtained from [[ftp://ftp.fieldtriptoolbox.org/pub/fieldtrip/tutorial/cluster_permutation_timelock/stat_ERF_axial_FICvsFC.mat|stat_ERF_axial_FICvsFC.mat]]. If you need to reload the statistics output, use: |

load stat_ERF_axial_FICvsFC | load stat_ERF_axial_FICvsFC | ||

Line 143: | Line 145: | ||

* The field **clusterstat** contains the cluster-level statistic (the sum of the T-values in this cluster). | * The field **clusterstat** contains the cluster-level statistic (the sum of the T-values in this cluster). | ||

* The field **prob** contains the proportion of draws from the permutation distribution with a maximum cluster-level statistic that is larger than clusterstat. | * The field **prob** contains the proportion of draws from the permutation distribution with a maximum cluster-level statistic that is larger than clusterstat. | ||

- | The elements in the array stat.posclusters are sorted according to their p-value: the cluster with the smallest p-value comes first, followed by the cluster with the second-smallest, etc. Thus, if the k-th cluster has a p-value that is larger than the critical alpha-level (e.g., 0.025), then so does the (k+1)-th. Type stat.posclusters(k) on the Matlab command line to see the information for the k-th cluster. | + | The elements in the array stat.posclusters are sorted according to their p-value: the cluster with the smallest p-value comes first, followed by the cluster with the second-smallest, etc. Thus, if the k-th cluster has a p-value that is larger than the critical alpha-level (e.g., 0.025), then so does the (k+1)-th. Type stat.posclusters(k) on the MATLAB command line to see the information for the k-th cluster. |

The field stat.posclusterslabelmat is a spatiotemporal matrix. This matrix contains numbers that identify the clusters to which the (channel,time)-pairs (the samples) belong. For example, all (channel,time)-pairs that belong to the third cluster, are identified by the number 3. As will be shown in the following, this information can be used to visualize the topography of the clusters. | The field stat.posclusterslabelmat is a spatiotemporal matrix. This matrix contains numbers that identify the clusters to which the (channel,time)-pairs (the samples) belong. For example, all (channel,time)-pairs that belong to the third cluster, are identified by the number 3. As will be shown in the following, this information can be used to visualize the topography of the clusters. | ||

Line 149: | Line 151: | ||

For the negative clusters, the output is given in the following pair of fields: stat.negclusters and stat.negclusterslabelmat. These fields contain the same type of information as stat.posclusters and stat.posclusterslabelmat, but now for the negative clusters. | For the negative clusters, the output is given in the following pair of fields: stat.negclusters and stat.negclusterslabelmat. These fields contain the same type of information as stat.posclusters and stat.posclusterslabelmat, but now for the negative clusters. | ||

- | By inspecting stat.posclusters and stat.negclusters, it can be seen that only the first positive and the first negative cluster have a p-value less than the critical alpha-level of 0.025. This critical alpha-level corresponds to a false alarm rate of 0.05 in a two-sided test. By typing stat.posclusters(1) on the Matlab command line, you should obtain the following: | + | By inspecting stat.posclusters and stat.negclusters, it can be seen that only the first positive and the first negative cluster have a p-value less than the critical alpha-level of 0.025. This critical alpha-level corresponds to a false alarm rate of 0.05 in a two-sided test. By typing stat.posclusters(1) on the MATLAB command line, you should obtain the following: |

stat.posclusters(1) | stat.posclusters(1) | ||

Line 163: | Line 165: | ||

clusterstat: -1.0251e+04 | clusterstat: -1.0251e+04 | ||

- | It is possible that the p-values in your output are a little bit different from 0. This is because **[[reference:ft_timelockstatistics|ft_timelockstatistics]]** calculated as a Monte Carlo approximation of the permutation p-values: the p-value for the k-th positive cluster is calculated as the proportion of random draws from the permutation distribution in which the maximum of the cluster-level statistics is more larger than stat.posclusters(k).clusterstat. | + | It is possible that the p-values in your output are a little bit different from 0. This is because **[[reference:ft_timelockstatistics|ft_timelockstatistics]]** calculated as a Monte Carlo approximation of the permutation p-values: the p-value for the k-th positive cluster is calculated as the proportion of random draws from the permutation distribution in which the maximum of the cluster-level statistics is larger than stat.posclusters(k).clusterstat. |

==== Plotting the results ==== | ==== Plotting the results ==== | ||

- | To plot the results of the permutation test, we use the plotting function **[[reference:ft_topoplotER|ft_topoplotER]]**. In doing so, we will plot a topography of the difference between the two experimental conditions (FC and FIC). Atop that, and for each timestep of interest, we'll highlight the sensors which are members of significant clusters. First, however, we must calculate the difference between conditions. | + | To plot the results of the permutation test, we use the plotting function **[[reference:ft_topoplotER|ft_topoplotER]]**. In doing so, we will plot a topography of the difference between the two experimental conditions (FC and FIC). Atop that, and for each timestep of interest, we'll highlight the sensors which are members of significant clusters. First, however, we must calculate the difference between conditions using **[[reference:ft_math|ft_math]]**. |

cfg = []; | cfg = []; | ||

- | cfg.keeptrials = 'no'; % now keep only the subject-wise average, not the single trials | ||

avgFIC = ft_timelockanalysis(cfg, dataFIC_LP); | avgFIC = ft_timelockanalysis(cfg, dataFIC_LP); | ||

avgFC = ft_timelockanalysis(cfg, dataFC_LP); | avgFC = ft_timelockanalysis(cfg, dataFC_LP); | ||

- | % Copy the entire timelockanalysis structure to preserve all | + | % Then take the difference of the averages using ft_math |

- | % the information it holds in addition to ERP averages. | + | cfg = []; |

- | raweffectFICvsFC = avgFIC; | + | cfg.operation = 'subtract'; |

- | % Then take the difference of the averages. | + | cfg.parameter = 'avg'; |

- | raweffectFICvsFC.avg = avg_FIC.avg - avg_FC.avg; | + | raweffectFICvsFC = ft_math(cfg,avgFIC,avgFC); |

We then construct a boolean matrix indicating membership in the significant clusters. This matrix has size [Number_of_MEG_channels × Number_of_temporal_samples], like stat.posclusterslabelmat. We'll make two such matrices: one for positive clusters (named pos), and one for negative (neg). All (channel,time)-pairs belonging to the significant clusters will be coded in the new boolean matrix as 1, and all those that don't will be coded as 0. | We then construct a boolean matrix indicating membership in the significant clusters. This matrix has size [Number_of_MEG_channels × Number_of_temporal_samples], like stat.posclusterslabelmat. We'll make two such matrices: one for positive clusters (named pos), and one for negative (neg). All (channel,time)-pairs belonging to the significant clusters will be coded in the new boolean matrix as 1, and all those that don't will be coded as 0. | ||

Line 284: | Line 285: | ||

- | The output can also be obtained from [[ftp://ftp.fcdonders.nl/pub/fieldtrip/tutorial/cluster_permutation_timelock/stat_ERF_planar_FICvsFC.mat]]. If you need to reload the statistics output, use: | + | The output can also be obtained from [[ftp://ftp.fieldtriptoolbox.org/pub/fieldtrip/tutorial/cluster_permutation_timelock/stat_ERF_planar_FICvsFC.mat]]. If you need to reload the statistics output, use: |

load stat_ERF_planar_FICvsFC | load stat_ERF_planar_FICvsFC | ||

Line 299: | Line 300: | ||

avgFC_planar_cmb = ft_combineplanar(cfg, avgFC_planar); | avgFC_planar_cmb = ft_combineplanar(cfg, avgFC_planar); | ||

- | % make a copy of the structure to contain the raw effect and all other information | + | % subtract avgFC from avgFIC |

- | % and subtract the averages from each other | + | cfg = []; |

- | raweffectFICvsFC = avgFIC_planar_cmb; | + | cfg.operation = 'subtract' |

- | raweffectFICvsFC.avg = avgFIC_planar_cmb.avg - avgFC_planar_cmb.avg; | + | cfg.parameter = 'avg'; |

+ | raweffectFICvsFC = ft_math(cfg,avgFIC_planar_cmb,avgFC_planar_cmb); | ||

Using the following configuration for **[[reference:ft_topoploter|ft_topoplotER]]** we can plot the raw effect and highlight the channels belonging to the significant clusters: | Using the following configuration for **[[reference:ft_topoploter|ft_topoplotER]]** we can plot the raw effect and highlight the channels belonging to the significant clusters: | ||

Line 341: | Line 344: | ||

==== Reading-in, preprocessing, timelockanalysis, planar gradient, and grandaveraging ==== | ==== Reading-in, preprocessing, timelockanalysis, planar gradient, and grandaveraging ==== | ||

- | We now describe how we can statistically test the difference between the event-related averages for fully incongruent (FIC) and the fully congruent (FC) sentence endings. For this analysis we use planar gradient data. For convenience we will not do the reading-in and preprocessing steps on all subjects. Instead we begin by loading the timelock structures containing the event-related averages (of the planar gradient data) of all ten subjects. The data is available from the FieldTrip FTP server ([[ftp://ftp.fcdonders.nl/pub/fieldtrip/tutorial/cluster_permutation_timelock/GA_ERF_orig.mat|GA_ERF_orig.mat]]). | + | We now describe how we can statistically test the difference between the event-related averages for fully incongruent (FIC) and the fully congruent (FC) sentence endings. For this analysis we use planar gradient data. For convenience we will not do the reading-in and preprocessing steps on all subjects. Instead we begin by loading the timelock structures containing the event-related averages (of the planar gradient data) of all ten subjects. The data is available from the FieldTrip FTP server ([[ftp://ftp.fieldtriptoolbox.org/pub/fieldtrip/tutorial/cluster_permutation_timelock/ERF_orig.mat|ERF_orig.mat]]). |

+ | | ||

+ | load ERF_orig; | ||

+ | | ||

+ | ERF_orig contains allsubjFIC and allsubjFC, each storing the event-related averages for the fully incongruent, and the fully congruent sentence endings, respectively. | ||

+ | | ||

+ | The format for these variables, are a prime example of how you should organise your data to be suitable for ft_XXXstatistics. Specifically, each variable is a cell array of structures, with each subject's averaged stored in one cell. To create this data structure two steps are required. First, the single-subject averages were calculated individually for each subject using the function [[reference:ft_timelockanalysis|ft_timelockanalysis]]. Second, using a for-loop we have combined the data from each subject, within each condition, into one variable (allsubj_FIC/allsubj_FC). We suggest that you adopt this procedure as well. | ||

+ | | ||

+ | On a technical note, it is preferred to represent the multi-subject data as a cell-array of structures, rather than a so-called struct-array. The reason for this is that the cell-array representation allows for easy expansion into a MATLAB function that allows for a variable number of input arguments (which is how the ft_XXXstatistics functions have been designed). | ||

- | load GA_ERF_orig; | ||

- | The event-related averages for the fully incongruent and the fully congruent sentence endings are stored in GA_FIC and GA_FC. These averages were calculated using the function **[[reference:ft_timelockgrandaverage|ft_timelockgrandaverage]]**. In the configuration for **[[reference:ft_timelockgrandaverage|ft_timelockgrandaverage]]**, the option cfg.keepindividual = ‘yes’ has to be chosen. (This has been done in the example data.) If this option is not used, then only the average ERF of all subjects will be calculated. | ||

==== Permutation test ==== | ==== Permutation test ==== | ||

Line 364: | Line 373: | ||

cfg.clusterstatistic = 'maxsum'; | cfg.clusterstatistic = 'maxsum'; | ||

cfg.minnbchan = 2; | cfg.minnbchan = 2; | ||

- | cfg.neighbours = neighbours; | + | cfg.neighbours = neighbours; % same as defined for the between-trials experiment |

cfg.tail = 0; | cfg.tail = 0; | ||

cfg.clustertail = 0; | cfg.clustertail = 0; | ||

Line 392: | Line 401: | ||

Now, use the configuration above to perform the following statistical analysis: | Now, use the configuration above to perform the following statistical analysis: | ||

- | [stat] = ft_timelockstatistics(cfg, GA_FIC, GA_FC) | + | [stat] = ft_timelockstatistics(cfg, allsubjFIC{:}, allsubjFC{:}) |

save stat_ERF_planar_FICvsFC_GA stat | save stat_ERF_planar_FICvsFC_GA stat | ||

- | The output can also be obtained from [[ftp://ftp.fcdonders.nl/pub/fieldtrip/tutorial/cluster_permutation_timelock/stat_ERF_planar_FICvsFC_GA.mat]]. If you need to reload the statistics output, use: | + | The output can also be obtained from [[ftp://ftp.fieldtriptoolbox.org/pub/fieldtrip/tutorial/cluster_permutation_timelock/stat_ERF_planar_FICvsFC_GA.mat]]. If you need to reload the statistics output, use: |

load stat_ERF_planar_FICvsFC_GA | load stat_ERF_planar_FICvsFC_GA | ||

Line 405: | Line 414: | ||

==== Plotting the results ==== | ==== Plotting the results ==== | ||

- | To plot the results: | + | For plotting we first use [[reference:ft_timelockgrandaverage|ft_timelockgrandaverage]] to calculate the grand average (average across all subject's average). |

- | GA_FICvsFC = GA_FIC; | + | |

- | GA_FICvsFC.avg = GA_FIC.avg - GA_FC.avg; | + | % load individual subject data |

+ | load('ERF_orig'); | ||

+ | % calculate the grand average for each condition | ||

+ | cfg = []; | ||

+ | cfg.channel = 'all'; | ||

+ | cfg.latency = 'all'; | ||

+ | cfg.parameter = 'avg'; | ||

+ | GA_FC = ft_timelockgrandaverage(cfg,allsubjFC{:}); | ||

+ | GA_FIC = ft_timelockgrandaverage(cfg,allsubjFIC{:}); | ||

+ | % "{:}" means to use data from all elements of the variable | ||

+ | | ||

+ | With the output, we can now create the plots | ||

+ | cfg = []; | ||

+ | cfg.operation = 'subtract'; | ||

+ | cfg.parameter = 'avg'; | ||

+ | GA_FICvsFC = ft_math(cfg,GA_FIC,GA_FC); | ||

figure; | figure; | ||

+ | % define parameters for plotting | ||

timestep = 0.05; %(in seconds) | timestep = 0.05; %(in seconds) | ||

- | sampling_rate = GA_FIC.fsample; | + | sampling_rate = dataFIC_LP.fsample; |

sample_count = length(stat.time); | sample_count = length(stat.time); | ||

j = [0:timestep:1]; % Temporal endpoints (in seconds) of the ERP average computed in each subplot | j = [0:timestep:1]; % Temporal endpoints (in seconds) of the ERP average computed in each subplot | ||

m = [1:timestep*sampling_rate:sample_count]; % temporal endpoints in MEEG samples | m = [1:timestep*sampling_rate:sample_count]; % temporal endpoints in MEEG samples | ||

- | + | % get relevant (significant) values | |

pos_cluster_pvals = [stat.posclusters(:).prob]; | pos_cluster_pvals = [stat.posclusters(:).prob]; | ||

pos_signif_clust = find(pos_cluster_pvals < stat.cfg.alpha); | pos_signif_clust = find(pos_cluster_pvals < stat.cfg.alpha); | ||

pos = ismember(stat.posclusterslabelmat, pos_signif_clust); | pos = ismember(stat.posclusterslabelmat, pos_signif_clust); | ||

+ | % plot | ||

for k = 1:20; | for k = 1:20; | ||

subplot(4,5,k); | subplot(4,5,k); | ||

Line 430: | Line 456: | ||

cfg.comment = 'xlim'; | cfg.comment = 'xlim'; | ||

cfg.commentpos = 'title'; | cfg.commentpos = 'title'; | ||

+ | cfg.layout = 'CTF151.lay'; | ||

ft_topoplotER(cfg, GA_FICvsFC); | ft_topoplotER(cfg, GA_FICvsFC); | ||

end | end | ||

- | |||

{{:tutorial:cluster_permutation_erf:clusperm_erf_topos_raweffect_ficvsfc_pl_ga.png?700}} | {{:tutorial:cluster_permutation_erf:clusperm_erf_topos_raweffect_ficvsfc_pl_ga.png?700}} | ||

Line 442: | Line 468: | ||

If you are interested in parametric tests in FieldTrip, you can read the [[tutorial:eventrelatedstatistics|Parametric and non-parametric statistics on event-related fields]] tutorial. If you are interested in how to do the same statistics on time-frequency representations, you can read the [[tutorial:cluster_permutation_freq|Cluster-based permutation tests on time-frequency data]] tutorial. | If you are interested in parametric tests in FieldTrip, you can read the [[tutorial:eventrelatedstatistics|Parametric and non-parametric statistics on event-related fields]] tutorial. If you are interested in how to do the same statistics on time-frequency representations, you can read the [[tutorial:cluster_permutation_freq|Cluster-based permutation tests on time-frequency data]] tutorial. | ||

- | If you would like to read more about issues related to statistical analysis, you can read the following FAQ's as well: | + | If you would like to read more about issues related to statistical analysis, you can read the following as well: |

- | \\ | + | FAQs: |

- | [[faq:why_should_i_use_the_cfg.correcttail_option_when_using_statistics_montecarlo|Why should I use the cfg.correcttail option when using statistics_montecarlo?]] | + | {{topic>statistics cluster neighbour +faq &list}} |

- | \\ | + | |

- | [[faq:what_is_the_idea_behind_statistical_inference_at_the_second-level|What is the idea behind statistical inference at the second-level?]] | + | |

- | If you would like to read about neighborhood selection, you can read the following FAQ's: | + | Example scripts: |

- | \\ | + | {{topic>statistics cluster neighbour +example &list}} |

- | [[faq:how_can_i_define_my_own_neighbourhood_template|How can I define my own neighbourhood templates or updating an already existing template?]] | + | |

- | \\ | + | |

- | [[faq:how_can_i_define_neighbouring_sensors|How can I define neighbouring sensors?]] | + | |

- | \\ | + | |

- | [[faq:how_does_ft_prepare_neighbours_work|How does ft_prepare_neighbours work?]] | + | |

- | \\ | + | |

- | Or you can look also at the following example scripts: | ||

- | \\ | ||

- | [[example:apply_clusterrandanalysis_on_tfrs_of_power_that_were_computed_with_besa|Apply clusterrandanalysis on TFRs of power that were computed with BESA]] | ||

- | \\ | ||

- | [[example:source_statistics|Source statistics]] | ||

- | \\ | ||

- | [[example:stratify|Stratify the distribution of one variable that differs in two conditions]] | ||

- | \\ | ||

- | [[example:statistics_toolbox|Using the MATLAB statistics toolbox]] | ||

+ | ----- | ||

+ | This tutorial was last revised by Nietzsche (June 18 2014) of FieldTrip using MATLAB 2011b on a 64-bit Linux platform. | ||

- | ----- | ||

- | This tutorial was last tested by Jörn, with version 20110507 of FieldTrip, using Matlab 2009b on a Windows 7 platform. |

This DokuWiki features an Anymorphic Webdesign theme, customised by Eelke Spaak and Stephen Whitmarsh.

Share this page: