-
Notifications
You must be signed in to change notification settings - Fork 0
/
hhgDemo.m
68 lines (48 loc) · 1.32 KB
/
hhgDemo.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
%% HHGDEMO.M
% A script demonstrating the usage of HHGPermutationTest.m
% Set the sample size
n = 1000;
% Set the number of permutations
nperm = 100;
%% Linear correlation
x = randn(1000,1);
y = 10*x+1;
% Run the test
[p, t, pstat] = HHGPermutationTest(x,y, nperm);
% Visualize the results
hhgDemoPlot(p,t,pstat,nperm,'Perfect linear correlation');
%% Quadratic
x = randn(1000,1);
y = x.^2;
% Run the test
[p, t, pstat] = HHGPermutationTest(x,y, nperm);
% Visualize the results
hhgDemoPlot(p,t,pstat,nperm,'Quadratic');
%% Exponential
x = randn(1000,1);
y = exp(x);
% Run the test
[p, t, pstat] = HHGPermutationTest(x,y, nperm);
% Visualize the results
hhgDemoPlot(p,t,pstat,nperm,'Exponential');
%% Uncorrelated Gaussian variables
x = randn(1000,1);
y = randn(1000,1);
% Run the test
[p, t, pstat] = HHGPermutationTest(x,y, nperm);
% Visualize the results
hhgDemoPlot(p,t,pstat,nperm,'Uncorrelated Gaussian variables');
%% Utility function to plot results
function hhgDemoPlot(p,t,pstat,nperm,titleStr)
figure; hold on;
plot(pstat, '-k','linewidth',2);
plot(xlim, [t t], '-r','linewidth',2);
legend({'test statistic under permutation','empirical value'});
xlabel('permutation');
ylabel('HHG test statistic');
if p == 0
title(sprintf('%s: p < 1/%d', titleStr, nperm));
else
title(sprintf('%s: p = %f', titleStr, p));
end
end