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

Permutation_test (1/4): add comments and docstring of the functions #111

Merged
merged 31 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ac17884
Fix gitignore
lionelkusch Jan 2, 2025
65b5564
Remove not necesaru function
lionelkusch Jan 2, 2025
ac8b76f
refactor files
lionelkusch Jan 2, 2025
ca0b257
Add option to pytest for detection of test
lionelkusch Jan 2, 2025
1d81370
Fix test
lionelkusch Jan 2, 2025
316a245
Remove not necessary normalisation
lionelkusch Jan 2, 2025
1e1badf
Comment step_down_maxt algo
lionelkusch Jan 2, 2025
4f98a49
Modify function of the integrate the difference.
lionelkusch Jan 2, 2025
5a29cdc
format stat tools
lionelkusch Jan 2, 2025
7aaa78f
add formating
lionelkusch Jan 2, 2025
0ccb7ff
Fixe bug
lionelkusch Jan 2, 2025
7322a3b
Format files
lionelkusch Jan 2, 2025
87bb15c
Fix a bug from the reformating
lionelkusch Jan 2, 2025
75048fc
Better function for empty matrix
lionelkusch Jan 2, 2025
3a271b8
Add a citation
lionelkusch Jan 2, 2025
df483d1
Fix format
lionelkusch Jan 2, 2025
62d1142
Improve actual tests
lionelkusch Jan 2, 2025
f8b2a7f
Add two tests
lionelkusch Jan 2, 2025
bea81fe
format type
lionelkusch Jan 7, 2025
e3fc566
Merge branch 'main' into PR_permutation_test
lionelkusch Jan 17, 2025
d39bed9
change default values
lionelkusch Jan 17, 2025
8d19b65
Format file
lionelkusch Jan 17, 2025
47b7d84
Change default argument for parallelization
lionelkusch Jan 20, 2025
fd8e475
Update example
lionelkusch Feb 3, 2025
0299315
Merge branch 'main' into PR_permutation_test
lionelkusch Feb 4, 2025
d785bd1
include all
lionelkusch Feb 4, 2025
72ca7d5
Modification folowwing suggestion
lionelkusch Feb 4, 2025
0fb452e
Format file
lionelkusch Feb 4, 2025
6e92b7a
Small modification
lionelkusch Feb 5, 2025
f0420aa
Add comment on the non usage of CV
lionelkusch Feb 17, 2025
57b1bca
Format file
lionelkusch Feb 17, 2025
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
3 changes: 2 additions & 1 deletion doc_conf/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ Functions
knockoff_aggregation
model_x_knockoff
multivariate_1D_simulation
permutation_test_cv
permutation_test
permutation_test_pval
reid
standardized_svr
zscore_from_pval
Expand Down
20 changes: 19 additions & 1 deletion doc_conf/references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,24 @@ @article{liuFastPowerfulConditional2021
file = {/home/ahmad/Zotero/storage/8HRQZX3H/Liu et al. - 2021 - Fast and Powerful Conditional Randomization Testin.pdf;/home/ahmad/Zotero/storage/YFNDKN2B/2006.html}
}

@book{westfall1993resampling,
title={Resampling-based multiple testing: Examples and methods for p-value adjustment},
author={Westfall, Peter H and Young, S Stanley},
volume={279},
year={1993},
publisher={John Wiley \& Sons}
}

@article{hirschhorn2005genome,
title={Genome-wide association studies for common diseases and complex traits},
author={Hirschhorn, Joel N and Daly, Mark J},
journal={Nature reviews genetics},
volume={6},
number={2},
pages={95--108},
year={2005},
publisher={Nature Publishing Group UK London}
}
@article{gaonkar_deriving_2012,
title = {Deriving statistical significance maps for {SVM} based image classification and group comparisons},
volume = {15},
Expand All @@ -192,4 +210,4 @@ @article{gaonkar_deriving_2012
year = {2012},
pmid = {23285616},
pmcid = {PMC3703958},
}
}
26 changes: 19 additions & 7 deletions examples/plot_fmri_data_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,18 @@
from sklearn.cluster import FeatureAgglomeration
from sklearn.feature_extraction import image
from sklearn.linear_model import Ridge
from sklearn.svm import LinearSVR
from sklearn.utils import Bunch

from hidimstat.ada_svr import ada_svr
from hidimstat.clustered_inference import clustered_inference
from hidimstat.ensemble_clustered_inference import ensemble_clustered_inference
from hidimstat.permutation_test import permutation_test, permutation_test_cv
from hidimstat.permutation_test import permutation_test, permutation_test_pval
from hidimstat.standardized_svr import standardized_svr
from hidimstat.stat_tools import pval_from_scale, zscore_from_pval

n_job = None


#############################################################################
# Function to fetch and preprocess Haxby dataset
Expand Down Expand Up @@ -151,19 +154,28 @@ def preprocess_haxby(subject=2, memory=None):

SVR_permutation_test_inference = False
if SVR_permutation_test_inference:
# We computed the regularization parameter by CV (C = 0.1)
pval_corr_svr_perm_test, one_minus_pval_corr_svr_perm_test = permutation_test_cv(
X, y, n_permutations=50, C=0.1
# It will be better to associate cross validation with the estimator
# but for a sake of time, this is not done.
estimator = LinearSVR()
weight_svr, weight_svr_distribution = permutation_test(
X, y, estimator, n_permutations=50
)
pval_corr_svr_perm_test, one_minus_pval_corr_svr_perm_test = permutation_test_pval(
weight_svr, weight_svr_distribution
)

# Another method is to compute the p-values by permutation test from the
# Ridge decoder. The solution provided by this method should be very close to
# the previous one and the computation time is much shorter: around 20 seconds.

# We computed the parameter from a cross valisation (alpha = 0.0215)
# It will be better to use RidgeCV but for a sake of time, this is not done.
estimator = Ridge()
pval_corr_ridge_perm_test, one_minus_pval_corr_ridge_perm_test = permutation_test(
weight_ridge, weight_ridge_distribution = permutation_test(
X, y, estimator=estimator, n_permutations=200
)
pval_corr_ridge_perm_test, one_minus_pval_corr_ridge_perm_test = permutation_test_pval(
weight_ridge, weight_ridge_distribution
)

#############################################################################
# Now, let us run the algorithm introduced by Gaonkar et al. (c.f. References).
Expand Down Expand Up @@ -305,4 +317,4 @@ def plot_map(
# (EnCluDL) seems realistic as we recover the visual cortex and do not make
# spurious discoveries.

show()
# show()
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,8 @@ where = ["src"]


[tool.hatch.version]
source = "vcs"
source = "vcs"

#pyproject.toml
[tool.pytest.ini_options]
addopts = "--ignore=src" # ignore src directory
5 changes: 3 additions & 2 deletions src/hidimstat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .knockoffs import model_x_knockoff
from .multi_sample_split import aggregate_quantiles
from .noise_std import group_reid, reid
from .permutation_test import permutation_test_cv
from .permutation_test import permutation_test, permutation_test_pval
from .scenario import multivariate_1D_simulation
from .standardized_svr import standardized_svr
from .stat_tools import zscore_from_pval
Expand All @@ -34,7 +34,8 @@
"knockoff_aggregation",
"model_x_knockoff",
"multivariate_1D_simulation",
"permutation_test_cv",
"permutation_test",
"permutation_test_pval",
"reid",
"standardized_svr",
"zscore_from_pval",
Expand Down
Loading