|
| 1 | +%Run simulated normal data to check Type I error rate and power |
| 2 | +% |
| 3 | +%AUTHOR: Eric Fields |
| 4 | +%VERSION DATE: 13 July 2017 |
| 5 | + |
| 6 | +clearvars; |
| 7 | + |
| 8 | +%% Set-up |
| 9 | + |
| 10 | +global VERBLEVEL |
| 11 | +VERBLEVEL = 0; |
| 12 | + |
| 13 | +%Design |
| 14 | +n_electrodes = 1; |
| 15 | +n_time_pts = 1; |
| 16 | +n_subs = 16; |
| 17 | +wg_design = [3, 2]; |
| 18 | + |
| 19 | +%Effect |
| 20 | +dims = 3; |
| 21 | + |
| 22 | +%Parameters |
| 23 | +n_exp = 1e3; |
| 24 | +n_perm = 1e3; |
| 25 | +alpha = 0.05; |
| 26 | + |
| 27 | +%Add effects |
| 28 | +main_effect = 5; |
| 29 | +int_effect = 0; |
| 30 | + |
| 31 | +%Pre-allocate results struct |
| 32 | +test_results = repmat(struct('h', NaN(n_electrodes, n_time_pts), ... |
| 33 | + 'p', NaN(n_electrodes, n_time_pts), ... |
| 34 | + 'F_obs', NaN(n_electrodes, n_time_pts), ... |
| 35 | + 'Fmax_crit', NaN, ... |
| 36 | + 'df', [NaN, NaN], ... |
| 37 | + 'estimated_alpha', NaN, ... |
| 38 | + 'exact_test', NaN), ... |
| 39 | + n_exp, 1); |
| 40 | + |
| 41 | + |
| 42 | +%% Simulate experiments |
| 43 | + |
| 44 | +tic |
| 45 | +parfor i = 1:n_exp |
| 46 | + |
| 47 | + %Simulate null data |
| 48 | + data = normrnd(0, 1, [n_electrodes, n_time_pts, wg_design, n_subs]); |
| 49 | + |
| 50 | + %Add effects |
| 51 | + if main_effect |
| 52 | + data(:, :, 1, :) = data(:, :, 1, :) + main_effect; |
| 53 | + end |
| 54 | + if int_effect |
| 55 | + if isequal(dims, [3, 4]) |
| 56 | + data(:, :, 1, 1, :) = data(:, :, 1, 1, :) + int_effect; |
| 57 | + data(:, :, 1, 2, :) = data(:, :, 1, 2, :) - int_effect; |
| 58 | + data(:, :, 2, 1, :) = data(:, :, 1, 2, :) - int_effect; |
| 59 | + data(:, :, 2, 2, :) = data(:, :, 1, 1, :) + int_effect; |
| 60 | + end |
| 61 | + end |
| 62 | + |
| 63 | + %Calculate ANOVA |
| 64 | + test_results(i) = calc_Fmax(data, dims, n_perm, alpha); |
| 65 | + |
| 66 | +end |
| 67 | +toc |
| 68 | + |
| 69 | + |
| 70 | +%% Report results |
| 71 | + |
| 72 | +fprintf('\nRejection rate = %f\n', mean(mean([test_results(:).h]))) |
| 73 | +fprintf('Mean p = %f\n', mean(mean([test_results(:).p]))) |
| 74 | +fprintf('Mean F_obs = %f\n', mean(mean([test_results(:).F_obs]))) |
| 75 | +fprintf('Mean F_crit = %f\n', mean(mean([test_results(:).Fmax_crit]))) |
| 76 | +fprintf('Parametric F_crit = %f\n\n', finv(.95, test_results(1).df(1), test_results(1).df(2))) |
0 commit comments