-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e587bcb
commit da5457e
Showing
9 changed files
with
190 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from sklearn.model_selection import KFold, ShuffleSplit, RepeatedKFold | ||
|
||
from cpm import CPMRegression | ||
from cpm.simulate_data import simulate_regression_data_2 | ||
from cpm.edge_selection import PThreshold, UnivariateEdgeSelection | ||
|
||
|
||
link_types = [#'no_link', | ||
#'no_no_link', | ||
'direct_link', | ||
'weak_link' | ||
] | ||
|
||
for link in link_types: | ||
X, y, covariates = simulate_regression_data_2(n_features=1225, n_informative_features=50, link_type=link) | ||
|
||
univariate_edge_selection = UnivariateEdgeSelection(edge_statistic=['pearson'], | ||
edge_selection=[PThreshold(threshold=[0.05], | ||
correction=[None])]) | ||
cpm = CPMRegression(results_directory=f'./tmp/simulated_data_{link}', | ||
cv=RepeatedKFold(n_splits=10, n_repeats=5, random_state=42), | ||
edge_selection=univariate_edge_selection, | ||
#cv_edge_selection=ShuffleSplit(n_splits=1, test_size=0.2, random_state=42), | ||
add_edge_filter=True, | ||
n_permutations=2) | ||
cpm.estimate(X=X, y=y, covariates=covariates) | ||
|
||
#cpm._calculate_permutation_results('./tmp/example_simulated_data2') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import os | ||
|
||
import seaborn as sns | ||
import matplotlib.pyplot as plt | ||
import pandas as pd | ||
|
||
|
||
results_folder = "/home/nwinter/PycharmProjects/cpm_python/examples/tmp/" | ||
|
||
results = {"brain not associated with y\n brain not associated with confound\n confound associated with y": os.path.join(results_folder, "simulated_data_no_no_link"), | ||
"brain not associated with y\n brain associated with confound\n confound associated with y": os.path.join(results_folder, "simulated_data_no_link"), | ||
"brain weakly associated with y\n brain associated with confound\n confound associated with y": os.path.join(results_folder, "simulated_data_weak_link"), | ||
"brain strongly associated with y\n brain associated with confound\n confound associated with y": os.path.join(results_folder, "simulated_data_direct_link"), | ||
|
||
} | ||
|
||
dfs = [] | ||
for link_type, folder in results.items(): | ||
df = pd.read_csv(os.path.join(folder, 'cv_results.csv')) | ||
df['link_type'] = link_type | ||
dfs.append(df) | ||
|
||
concatenated_df = pd.concat(dfs, ignore_index=True) | ||
|
||
concatenated_df = concatenated_df[concatenated_df['network'] == 'both'] | ||
|
||
concatenated_df['model'] = concatenated_df['model'].replace({"covariates": "confound only", "full": "connectome + confound", | ||
"connectome": "connectome only"}) | ||
|
||
g = sns.FacetGrid(concatenated_df, col="link_type", margin_titles=True, despine=True, | ||
height=2.5) | ||
g.map(plt.axvline, x=0, color='grey', linewidth=0.5, zorder=-1) | ||
g.map(sns.violinplot, "pearson_score", "model", inner=None, split=True, hue=1, hue_order=[1, 2], | ||
density_norm='count', dodge=True, palette="Blues_r") | ||
g.map(sns.boxplot, "pearson_score", "model", dodge=True, hue=1, hue_order=[2, 1]) | ||
g.set_titles(col_template="{col_name}", size=7) | ||
g.set_xlabels("Pearson correlation", size=8) | ||
plt.show() | ||
print() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import numpy as np | ||
import pandas as pd | ||
|
||
from sklearn.model_selection import KFold | ||
|
||
from cpm import CPMRegression | ||
from cpm.edge_selection import PThreshold, UnivariateEdgeSelection | ||
|
||
|
||
X = np.load('/spm-data/vault-data3/mmll/projects/cpm_macs_example/datahub/AnalysisReady/hc/DTI_fractional_anisotropy/X.npy') | ||
df = pd.read_csv('/spm-data/vault-data3/mmll/projects/cpm_macs_example/datahub/AnalysisReady/hc/DTI_fractional_anisotropy/subjects.csv', | ||
na_values=-99) | ||
|
||
X = X[~df['Haushaltsnetto'].isna()] | ||
df = df[~df['Haushaltsnetto'].isna()] | ||
covs = df[['Alter', 'Geschlecht', 'Site']].to_numpy() | ||
y = df['Haushaltsnetto'].to_numpy() | ||
|
||
# define edge selection | ||
p_threshold = PThreshold(threshold=[0.001], correction=[None]) | ||
p_fdr = PThreshold(threshold=[0.05], correction=['fdr_by']) | ||
univariate_edge_selection = UnivariateEdgeSelection(edge_statistic=['pearson_partial'], edge_selection=[p_threshold]) | ||
|
||
# run cpm regression | ||
cpm = CPMRegression(results_directory='/spm-data/vault-data3/mmll/projects/cpm_macs_example/haushaltsnetto', | ||
cv=KFold(n_splits=10, shuffle=True, random_state=42), | ||
edge_selection=univariate_edge_selection, | ||
cv_edge_selection=KFold(n_splits=10, shuffle=True, random_state=42), | ||
add_edge_filter=True, | ||
n_permutations=1000) | ||
results = cpm.estimate(X=X, y=y, covariates=covs) |