Skip to content

Commit d0f50f2

Browse files
committed
Adds sphericity tests
1 parent b51feab commit d0f50f2

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/StatisticalTests.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+

0 commit comments

Comments
 (0)