Skip to content

Commit 5a5108e

Browse files
fixed indexing of covar matrix in testing
1 parent cc73de4 commit 5a5108e

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

diffxpy/stats/stats.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def likelihood_ratio_test(
3333
delta_df = df_full - df_reduced
3434
# Compute the deviance test statistic.
3535
delta_dev = 2 * (ll_full - ll_reduced)
36-
# Compute the p-values based on the deviance and its expection based on the chi-square distribution.
36+
# Compute the p-values based on the deviance and its expectation based on the chi-square distribution.
3737
pvals = 1 - scipy.stats.chi2(delta_df).cdf(delta_dev)
3838
return pvals
3939

@@ -251,6 +251,8 @@ def wald_test_chisq(
251251
if theta_mle.shape[0] != theta_covar.shape[1]:
252252
raise ValueError(
253253
'stats.wald_test(): theta_mle and theta_covar have to contain the same number of parameters')
254+
if len(theta_covar.shape) != 3:
255+
raise ValueError('stats.wald_test(): theta_covar should have 3 dimensions but has %i' % len(theta_covar.shape))
254256
if theta_mle.shape[1] != theta_covar.shape[0]:
255257
raise ValueError('stats.wald_test(): theta_mle and theta_covar have to contain the same number of genes')
256258
if theta_covar.shape[1] != theta_covar.shape[2]:

diffxpy/testing/det.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -791,8 +791,7 @@ def _test(self):
791791
if len(self.coef_loc_totest) == 1:
792792
self.theta_mle = self.theta_mle[0] # Make xarray one dimensional for stats.wald_test.
793793
self.theta_sd = self.model_estim.fisher_inv[:, self.coef_loc_totest[0], self.coef_loc_totest[0]]
794-
self.theta_sd = np.nextafter(0, np.inf, out=self.theta_sd,
795-
where=self.theta_sd < np.nextafter(0, np.inf))
794+
self.theta_sd = np.nextafter(0, np.inf, out=self.theta_sd, where=self.theta_sd < np.nextafter(0, np.inf))
796795
self.theta_sd = np.sqrt(self.theta_sd)
797796
return stats.wald_test(
798797
theta_mle=self.theta_mle,
@@ -801,12 +800,11 @@ def _test(self):
801800
)
802801
else:
803802
self.theta_sd = np.diagonal(self.model_estim.fisher_inv, axis1=-2, axis2=-1).copy()
804-
self.theta_sd = np.nextafter(0, np.inf, out=self.theta_sd,
805-
where=self.theta_sd < np.nextafter(0, np.inf))
803+
self.theta_sd = np.nextafter(0, np.inf, out=self.theta_sd, where=self.theta_sd < np.nextafter(0, np.inf))
806804
self.theta_sd = np.sqrt(self.theta_sd)
807805
return stats.wald_test_chisq(
808806
theta_mle=self.theta_mle,
809-
theta_covar=self.model_estim.fisher_inv[:, self.coef_loc_totest, self.coef_loc_totest],
807+
theta_covar=self.model_estim.fisher_inv[:, self.coef_loc_totest, :][:, :, self.coef_loc_totest],
810808
theta0=0
811809
)
812810

0 commit comments

Comments
 (0)