Two MATLAB functions are provided for estimating the sample size through simulations for the cluster-based permutation test used in EEG/MEG data. They can be used for **t-test** between two conditions, **one-way ANOVA** with three or more conditions, or **2×N interactions**. **Cite as**: [Wang, & Zhang. (2021). Word frequency effect in written production: Evidence from ERPs and neural oscillations. Psychophysiology, 58: e13775](https://doi.org/10.1111/psyp.13775). **Please cite the above paper** if you use these functions, which were written for, and first used in this paper. MATLAB functions are stored in the *functions* file. - **sampleSize_erp** is for ERP analysis - **sampleSize_timefreq** is for time frequency analysis The following two demo files demonstrate how to use the above two functions: - **demo_erp.m** - **demo_timefreq.m** Take a simple design with two conditions for example, what the functions do is simulating a dataset with two conditions of ERP (2 dimensions: channel×time) or time-frequency (3 dimensions: channel×frequency×time) data, for each sample size (starting from 10, increasing in steps of 1 until reaching a power of 0.80). In each sample of the ERP/time-frequency data, we simulate a cluster of interest within a predefined time window (eg, 50-250 ms) and frequency band (eg, 4-8 Hz) in neighboring channels (eg, C1, CZ, CP1, CPZ). The size of the cluster can be chosen to be similar to that of the cluster displaying effect of interest in prior existing or pilot studies. The cluster's peak values in the two conditions were sampled from two normal distributions (for a between-subject design) or a bivariate normal distribution (for a within-subject design). The means and standard deviations of the distributions can be chosen to be similar to those in prior existing or pilot studies. Then a cluster-based permutation test is performed on the simulated dataset to test whether any cluster exhibited significant difference between the two conditions with an alpha level of 0.05. For each sample size, the simulation was run for 1000 times, and the power was calculated as the proportion of the number of times finding significant clusters in these 1000 simulations. I also provided a detailed introduction to this method in the [ Fieldtrip website](https://www.fieldtriptoolbox.org/example/samplesize/).
OSF does not support the use of Internet Explorer. For optimal performance, please switch to another browser.