Skip to content
This repository was archived by the owner on Oct 21, 2025. It is now read-only.

Commit 0756d01

Browse files
critical bug fix: wald test and z-score were note two-sided
i noticed in the example notebook that all negative LFC genes had very high p-values. this was because the wald test was not two-sided, i changed this and checked that the test still produces uniform pvalues under the null model. i also changed the z-test to be two-sided.
1 parent d7de2a5 commit 0756d01

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

diffxpy/stats.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ def wald_test(
194194
if theta_mle.shape[0] != theta0.shape[0]:
195195
raise ValueError('stats.wald_test(): theta_mle and theta0 have to contain the same number of entries')
196196

197-
wald_statistic = np.divide(theta_mle - theta0, theta_sd)
198-
pvals = 1 - scipy.stats.norm(loc=0, scale=1).cdf(wald_statistic) # check whether this is two-sided
197+
wald_statistic = np.abs(np.divide(theta_mle - theta0, theta_sd))
198+
pvals = 2*(1 - scipy.stats.norm(loc=0, scale=1).cdf(wald_statistic)) # two-tailed test
199199
return pvals
200200

201201

@@ -235,6 +235,6 @@ def two_coef_z_test(
235235
if theta_mle0.shape[0] != theta_sd0.shape[0]:
236236
raise ValueError('stats.two_coef_z_test(): theta_mle0 and theta_sd0 have to contain the same number of entries')
237237

238-
z_statistic = (theta_mle0 - theta_mle1) / np.sqrt(np.square(theta_sd0) + np.square(theta_sd1))
239-
pvals = 1 - scipy.stats.norm(loc=0, scale=1).cdf(z_statistic) # check whether this is two-sided
238+
z_statistic = np.abs((theta_mle0 - theta_mle1) / np.sqrt(np.square(theta_sd0) + np.square(theta_sd1)))
239+
pvals = 2*(1 - scipy.stats.norm(loc=0, scale=1).cdf(z_statistic)) # two-tailed test
240240
return pvals

0 commit comments

Comments
 (0)