File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
1
+ using Distributions
2
+
3
+ # Compute Mauchly's statistic (valid under assumption of multinormality)
4
+ # Mauchly, 1940; Kendall and Stuart, 1968
5
+ # n is the number of data points (samples)
6
+ # This returns both the value of the test statistic and the expected distribution to test against
7
+ function MauchlySphericityTestStatistic {T<:Real} (PopulationCovariance:: AbstractMatrix{T} , SampleCovariance:: AbstractMatrix{T} , n:: Integer )
8
+ p = size (SampleCovariance)[1 ]
9
+ C = inv (PopulationCovariance) * SampleCovariance
10
+ l = (det (C)/ (trace (C)/ p)^ p)
11
+ x = - n* log (l)
12
+ f = p* (p+ 1 )/ 2 - 1
13
+ return x, Chisq (f)
14
+ end
15
+
16
+ # Johnstone's variant of the sphericity test
17
+ # n, p>= 10 recommended
18
+ # Johnstone (2001)
19
+ function JohnstoneSphericityTestStatistic {T<:Real} (PopulationCovariance:: AbstractMatrix{T} , SampleCovariance:: AbstractMatrix{T} , n:: Integer )
20
+ C = inv (PopulationCovariance) * SampleCovariance
21
+ v = max (eigvals (C))
22
+ mu= (sqrt (n- 1 )+ sqrt (p))^ 2
23
+ sigma= sqrt (mu)* (1 / sqrt (n- 1 )+ 1 / sqrt (p))^ (1 / 3 )
24
+ (n* l- mu)/ sigma # To be tested against Tracy-Widom with beta=1
25
+ end
26
+
You can’t perform that action at this time.
0 commit comments