@@ -3,7 +3,6 @@ using Random
33using LinearAlgebra
44using PDMats
55using Statistics
6- using HypothesisTests
76using Test
87import JSON
98import Distributions: _univariate, _multivariate, _rand_params
@@ -185,11 +184,26 @@ function test_against_univariate(D::MatrixDistribution, d::UnivariateDistributio
185184 nothing
186185end
187186
187+ # Equivalent to `ExactOneSampleKSTest` in HypothesisTests.jl
188+ # We implement it here to avoid a circular dependency on HypothesisTests
189+ # that causes test failures when preparing a breaking release of Distributions
190+ function pvalue_kolmogorovsmirnoff (x:: AbstractVector , d:: UnivariateDistribution )
191+ # compute maximum absolute deviation from the empirical cdf
192+ n = length (x)
193+ cdfs = sort! (map (Base. Fix1 (cdf, d), x))
194+ dmax = maximum (zip (cdfs, (0 : (n- 1 ))/ n, (1 : n)/ n)) do (cdf, lower, upper)
195+ return max (cdf - lower, upper - cdf)
196+ end
197+
198+ # compute asymptotic p-value (see `KSDist`)
199+ return ccdf (KSDist (n), dmax)
200+ end
201+
188202function test_draws_against_univariate_cdf (D:: MatrixDistribution , d:: UnivariateDistribution )
189203 α = 0.05
190204 M = 100000
191205 matvardraws = [rand (D)[1 ] for m in 1 : M]
192- @test pvalue ( ExactOneSampleKSTest ( matvardraws, d) ) >= α
206+ @test pvalue_kolmogorovsmirnoff ( matvardraws, d) >= α
193207 nothing
194208end
195209
@@ -335,8 +349,7 @@ function test_special(dist::Type{Wishart})
335349 ρ = Chisq (ν)
336350 A = rand (q, M)
337351 z = [A[:, m]' * H[m]* A[:, m] / (A[:, m]' * Σ* A[:, m]) for m in 1 : M]
338- kstest = ExactOneSampleKSTest (z, ρ)
339- @test pvalue (kstest) >= α
352+ @test pvalue_kolmogorovsmirnoff (z, ρ) >= α
340353 end
341354 @testset " H ~ W(ν, I) ⟹ H[i, i] ~ χ²(ν)" begin
342355 κ = n + 1
@@ -347,8 +360,7 @@ function test_special(dist::Type{Wishart})
347360 mymats[:, :, m] = rand (g)
348361 end
349362 for i in 1 : n
350- kstest = ExactOneSampleKSTest (mymats[i, i, :], ρ)
351- @test pvalue (kstest) >= α / n
363+ @test pvalue_kolmogorovsmirnoff (mymats[i, i, :], ρ) >= α / n
352364 end
353365 end
354366 @testset " Check Singular Branch" begin
@@ -423,8 +435,7 @@ function test_special(dist::Type{LKJ})
423435 end
424436 for i in 1 : d
425437 for j in 1 : i- 1
426- kstest = ExactOneSampleKSTest (mymats[i, j, :], ρ)
427- @test pvalue (kstest) >= α / L
438+ @test pvalue_kolmogorovsmirnoff (mymats[i, j, :], ρ) >= α / L
428439 end
429440 end
430441 end
0 commit comments