Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
SabrinaRichter committed Mar 4, 2019
2 parents 7e47156 + e4b862c commit 8eff054
Show file tree
Hide file tree
Showing 9 changed files with 559 additions and 136 deletions.
1 change: 1 addition & 0 deletions diffxpy/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
from . import enrich
from . import stats
from . import utils
from .. import pkg_constants
2 changes: 1 addition & 1 deletion diffxpy/api/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from diffxpy.stats.stats import wald_test
from diffxpy.stats.stats import wald_test_chisq
from diffxpy.stats.stats import two_coef_z_test
from diffxpy.stats.stats import wilcoxon_test
from diffxpy.stats.stats import mann_whitney_u_test
from diffxpy.stats.stats import t_test_moments
from diffxpy.stats.stats import t_test_raw

Expand Down
2 changes: 1 addition & 1 deletion diffxpy/api/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from diffxpy.testing.base import lrt
from diffxpy.testing.base import wald
from diffxpy.testing.base import t_test
from diffxpy.testing.base import wilcoxon
from diffxpy.testing.base import rank_test
from diffxpy.testing.base import partition
from diffxpy.testing.base import pairwise
from diffxpy.testing.base import versus_rest
Expand Down
11 changes: 7 additions & 4 deletions diffxpy/pkg_constants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
BATCHGLM_OPTIM_GD = True
BATCHGLM_OPTIM_ADAM = True
BATCHGLM_OPTIM_GD = False
BATCHGLM_OPTIM_ADAM = False
BATCHGLM_OPTIM_ADAGRAD = False
BATCHGLM_OPTIM_RMSPROP = False
BATCHGLM_OPTIM_NEWTON = True
BATCHGLM_OPTIM_IRLS = True
BATCHGLM_OPTIM_NEWTON = False
BATCHGLM_OPTIM_NEWTON_TR = True
BATCHGLM_OPTIM_IRLS = False
BATCHGLM_OPTIM_IRLS_TR = False
BATCHGLM_PROVIDE_BATCHED = False
BATCHGLM_TERMINATION_TYPE = "by_feature"
16 changes: 11 additions & 5 deletions diffxpy/stats/stats.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from typing import Union

import numpy as np
import numpy.linalg
import scipy.stats
from typing import Union
import xarray as xr


def likelihood_ratio_test(
Expand Down Expand Up @@ -37,7 +39,7 @@ def likelihood_ratio_test(
return pvals


def wilcoxon_test(
def mann_whitney_u_test(
x0: np.ndarray,
x1: np.ndarray,
):
Expand Down Expand Up @@ -68,7 +70,8 @@ def wilcoxon_test(
scipy.stats.mannwhitneyu(
x=x0[:, i].flatten(),
y=x1[:, i].flatten(),
alternative='two-sided'
use_continuity=True,
alternative="two-sided"
).pvalue for i in range(x0.shape[1])
])
return pvals
Expand Down Expand Up @@ -152,7 +155,7 @@ def t_test_moments(
out=s_delta
)

t_statistic = np.abs((mu0 - mu1) / s_delta)
t_statistic = (mu0 - mu1) / s_delta

divisor = (
(np.square(var0 / n0) / (n0 - 1)) +
Expand All @@ -174,7 +177,7 @@ def t_test_moments(
out=df
)

pval = 2 * (1 - scipy.stats.t(df).cdf(t_statistic))
pval = 2 * scipy.stats.t.sf(np.abs(t_statistic), df)
return pval


Expand Down Expand Up @@ -261,6 +264,9 @@ 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
# Convert to nd.array to avoid gufunc error.
if isinstance(theta_diff, xr.DataArray):
theta_diff = theta_diff.values
wald_statistic = np.array([
np.matmul(
np.matmul(
Expand Down
Loading

0 comments on commit 8eff054

Please sign in to comment.