Skip to content
This repository was archived by the owner on Oct 21, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions diffxpy/stats/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numpy.linalg
import scipy.sparse
import scipy.stats
import sys
from typing import Union


Expand Down Expand Up @@ -263,16 +264,20 @@ def wald_test_chisq(
raise ValueError('stats.wald_test(): theta_mle and theta0 have to contain the same number of entries')

theta_diff = theta_mle - theta0
wald_statistic = np.array([
invertible = np.where(np.linalg.cond(theta_covar, p=None) < 1 / sys.float_info.epsilon)[0]
wald_statistic = np.zeros([theta_covar.shape[0]]) + np.nan
wald_statistic[invertible] = np.array([
np.matmul(
np.matmul(
theta_diff[:, [i]].T,
numpy.linalg.inv(theta_covar[i, :, :])
),
theta_diff[:, [i]]
)
for i in range(theta_diff.shape[1])
for i in invertible
]).flatten()
if invertible.shape[0] < theta_covar.shape[0]:
print("caught %i linalg singular matrix errors" % (theta_covar.shape[0] - invertible.shape[0]))
pvals = 1 - scipy.stats.chi2(theta_mle.shape[0]).cdf(wald_statistic)
return pvals

Expand Down