Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

progress bar #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
21 changes: 17 additions & 4 deletions time_series_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import random
from collections import namedtuple


__version__ = '0.11.2'
DEFAULT_HUE_COLORMAP = 'Dark2'
DEFAULT_ANNOTATION_COLORMAP = 'brg'
Expand Down Expand Up @@ -116,7 +117,7 @@ def lmer_crossvalidation_test(dm, formula, groups, re_formula=None, winlen=1,
samples_re=samples_re, **kwargs)


def lmer_series(dm, formula, winlen=1, fit_kwargs={}, **kwargs):
def lmer_series(dm, formula, winlen=1, progbar=False, fit_kwargs={}, **kwargs):
"""Performs a sample-by-sample linear-mixed-effects analysis. See
`lmer_crossvalidation()` for an explanation of the arguments.

Expand Down Expand Up @@ -161,7 +162,14 @@ def lmer_series(dm, formula, winlen=1, fit_kwargs={}, **kwargs):
model = smf.ols
else:
model = smf.mixedlm
for i in range(0, depth, winlen):

if progbar:
from tqdm import tqdm
iterator = tqdm(range(0, depth, winlen), 'lmer_series')
else:
iterator = range(0, depth, winlen)

for i in iterator:
logger.debug('sample {}'.format(i))
with warnings.catch_warnings():
warnings.simplefilter('ignore')
Expand Down Expand Up @@ -192,7 +200,7 @@ def lmer_series(dm, formula, winlen=1, fit_kwargs={}, **kwargs):
def lmer_permutation_test(dm, formula, groups, re_formula=None, winlen=1,
suppress_convergence_warnings=False, fit_kwargs={},
iterations=1000, cluster_p_threshold=.05,
test_intercept=False, **kwargs):
test_intercept=False, progbar=False, **kwargs):
"""Performs a cluster-based permutation test based on sample-by-sample
linear-mixed-effects analyses. The permutation test identifies clusters
based on p-value threshold and uses the absolute of the summed z-values of
Expand Down Expand Up @@ -254,7 +262,12 @@ def lmer_permutation_test(dm, formula, groups, re_formula=None, winlen=1,
for effect, clusters in cluster_obs.items()}
logger.info(f'observed clusters: {cluster_obs}')
# Now run through all iterations
for i in range(iterations):
if progbar:
from tqdm import tqdm
iterator = tqdm(iterations, 'lmer_permutation_test')
else:
iterator = iterations
for i in iterator:
# If there are no significant clusters, we'll skip the test altogether
# to save time. The Intercept doesn't count here, because the intercept
# generally does have significant clusters but we're not interested in
Expand Down