Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kahaaga committed Jul 21, 2024
1 parent 1251ca1 commit c14c81c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/methods/correlation/partial_correlation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ function association(::PartialCorrelation, x::VectorOrStateSpaceSet, y::VectorOr
conds::ArrayOrStateSpaceSet...)
X, Y, Z = construct_partialcor_datasets(x, y, conds...)
D = StateSpaceSet(X, Y, Z)
cov = fastcov(D)
precision_matrix = invert_cov(cov)
cov_matrix = cov(D)
precision_matrix = invert_cov(cov_matrix)
return partial_correlation_from_precision(precision_matrix, 1, 2)
end

Expand All @@ -66,14 +66,14 @@ function association(measure::PartialCorrelation, est::Nothing, x, y, z)
end


function invert_cov(cov::AbstractMatrix)
if det(cov) 0.0
function invert_cov(cov_matrix::AbstractMatrix)
if det(cov_matrix) 0.0
# If the determinant of the covariance matrix is zero, then the
# Moore-Penrose pseudo-inverse is used.
rtol = sqrt(eps(real(float(one(eltype(cov))))))
return pinv(cov; rtol)
rtol = sqrt(eps(real(float(one(eltype(cov_matrix))))))
return pinv(cov_matrix; rtol)
else
return inv(cov)
return inv(cov_matrix)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ n = 100
likeit = rand(rng, ["yes", "no"], n)
food = rand(rng, ["veggies", "meat", "fish"], n)
service = rand(rng, ["netflix", "hbo"], n)
est =
nshuffles = 3
d = CodifyVariables(UniqueElements())
nshuffles = 3
test_mi_s = SurrogateAssociationTest(JointProbabilities(MIShannon(), d); nshuffles, rng)
test_mi_rj = SurrogateAssociationTest(JointProbabilities(MIRenyiJizba(), d); nshuffles, rng)
test_mi_rs = SurrogateAssociationTest(JointProbabilities(MIRenyiSarbu(), d); nshuffles, rng)
Expand Down Expand Up @@ -52,5 +51,7 @@ experience = map(preferred_equipment) do equipment
end;

# We should be able to reject the null hypothesis of `places ⫫ experience`.
test_mi = independence(SurrogateAssociationTest(MIShannon(), est; nshuffles, rng), places, experience)
d = CodifyVariables(UniqueElements())
est = JointProbabilities(MIShannon(), d)
test_mi = independence(SurrogateAssociationTest(est), places, experience)
@test pvalue(test_mi) < α

0 comments on commit c14c81c

Please sign in to comment.