Skip to content

Commit b86f3b4

Browse files
committed
simulation code upload
1 parent 7b04992 commit b86f3b4

File tree

4 files changed

+606
-1
lines changed

4 files changed

+606
-1
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
11
# cwas_simulation
2-
Simulate a connectome wide association study with real data
2+
Simulate a connectome wide association study (CWAS) with real data.
3+
4+
This repo contains code used to run a CWAS simulation for the paper "Investigating the convergence of resting-state functional connectivity profiles in Alzheimer’s disease with neuropsychiatric symptoms and schizophrenia".
5+
6+
The CWAS contrasts cases and controls, using whole-brain connectomes with functional connectivity (FC) standardised (z-scored) based on the variance of the control group. CWAS is conducted using linear regression, with z-scored FC as the dependent variable, and case/control label as the explanatory variable. The models are adjusted for site of data collection. The linear regression is applied to each connection (here, 2080), with the resulting β values determining the case FC profile. Number of tests is corrected using Benjamini-Hochberg correction for FDR at a threshold of q < 0.1. The top-10% effect size of the group label on FC is measured as the mean of the top decile of the absolute β values.
7+
8+
The simulation uses real connectomes from neurotypical control participants. The participants are first randomly split into two equal-sized groups. An effect of disease on FC is modelled by altering pi% of connections for one group ("cases"), given by the equation connection<sub>i</sub> = connection<sub>i</sub> + *d* x std, where *d* is equal to a previously published effect size (Cohen’s *d*) for the disease, and std is equal to the standard deviation of the connectivity values combined across groups. This process is repeated (default=100), FDR corrected at a threshold of *q*, and the average sensitivity and specificity calculated.
9+
10+
The notebook `run_simulation.ipynb` runs the simulation to estimate the sensitivity and specificity for a range of sample sizes with a *d* of 0.3, pi of 20% and q of 0.1. Connectomes used in this simulation were derived from the Autism Brain Imaging Data Exchange (ABIDE-1 and -2) initiative.
11+
12+
13+

requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
numpy>=1.23.1
2+
pandas>=1.4.3
3+
scikit-learn>=1.2.2
4+
statsmodels>=0.14.0

run_simulation.ipynb

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "71e121d4",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"import simulation_tools as sim\n",
11+
"import pandas as pd"
12+
]
13+
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": 2,
17+
"id": "fb17ca19",
18+
"metadata": {},
19+
"outputs": [],
20+
"source": [
21+
"# Path to a .csv file with connectomes in upper triangular form\n",
22+
"path_conn = \"/home/neuromod/ad_sz/data/abide/abide1_2_controls_concat.csv\""
23+
]
24+
},
25+
{
26+
"cell_type": "code",
27+
"execution_count": 3,
28+
"id": "8b6c3bf5",
29+
"metadata": {},
30+
"outputs": [],
31+
"source": [
32+
"# Load control connectomes from ABIDE\n",
33+
"conn_df = pd.read_csv(path_conn)"
34+
]
35+
},
36+
{
37+
"cell_type": "code",
38+
"execution_count": 4,
39+
"id": "5df7cb69",
40+
"metadata": {},
41+
"outputs": [],
42+
"source": [
43+
"# Create a range of N values\n",
44+
"N_values = range(300, 951, 50)"
45+
]
46+
},
47+
{
48+
"cell_type": "code",
49+
"execution_count": 5,
50+
"id": "3b4565ab",
51+
"metadata": {},
52+
"outputs": [
53+
{
54+
"name": "stdout",
55+
"output_type": "stream",
56+
"text": [
57+
"Simulation ran for N=300.\n",
58+
"Simulation ran for N=350.\n",
59+
"Simulation ran for N=400.\n",
60+
"Simulation ran for N=450.\n",
61+
"Simulation ran for N=500.\n",
62+
"Simulation ran for N=550.\n",
63+
"Simulation ran for N=600.\n",
64+
"Simulation ran for N=650.\n",
65+
"Simulation ran for N=700.\n",
66+
"Simulation ran for N=750.\n",
67+
"Simulation ran for N=800.\n",
68+
"Simulation ran for N=850.\n",
69+
"Simulation ran for N=900.\n",
70+
"Simulation ran for N=950.\n"
71+
]
72+
}
73+
],
74+
"source": [
75+
"result_list = []\n",
76+
"# Loop through the values of N and run simulation with specififed parameters\n",
77+
"for N in N_values:\n",
78+
" result = sim.run_multiple_simulation(conn_df, N=N, pi=0.20, d=0.3, q=0.1, num_sample=100)\n",
79+
" print(f\"Simulation ran for N={N}.\")\n",
80+
" result_list.append(result)"
81+
]
82+
},
83+
{
84+
"cell_type": "code",
85+
"execution_count": 6,
86+
"id": "ebf2916e",
87+
"metadata": {},
88+
"outputs": [
89+
{
90+
"name": "stdout",
91+
"output_type": "stream",
92+
"text": [
93+
"Estimated mean sensitivity to detect d=0.3, with pi=0.2%, q=0.1 and N=300: 0.52, with mean specificity of 0.99.\n",
94+
"Estimated mean sensitivity to detect d=0.3, with pi=0.2%, q=0.1 and N=350: 0.62, with mean specificity of 0.99.\n",
95+
"Estimated mean sensitivity to detect d=0.3, with pi=0.2%, q=0.1 and N=400: 0.72, with mean specificity of 0.99.\n",
96+
"Estimated mean sensitivity to detect d=0.3, with pi=0.2%, q=0.1 and N=450: 0.78, with mean specificity of 0.98.\n",
97+
"Estimated mean sensitivity to detect d=0.3, with pi=0.2%, q=0.1 and N=500: 0.84, with mean specificity of 0.98.\n",
98+
"Estimated mean sensitivity to detect d=0.3, with pi=0.2%, q=0.1 and N=550: 0.88, with mean specificity of 0.98.\n",
99+
"Estimated mean sensitivity to detect d=0.3, with pi=0.2%, q=0.1 and N=600: 0.91, with mean specificity of 0.98.\n",
100+
"Estimated mean sensitivity to detect d=0.3, with pi=0.2%, q=0.1 and N=650: 0.94, with mean specificity of 0.98.\n",
101+
"Estimated mean sensitivity to detect d=0.3, with pi=0.2%, q=0.1 and N=700: 0.95, with mean specificity of 0.98.\n",
102+
"Estimated mean sensitivity to detect d=0.3, with pi=0.2%, q=0.1 and N=750: 0.96, with mean specificity of 0.98.\n",
103+
"Estimated mean sensitivity to detect d=0.3, with pi=0.2%, q=0.1 and N=800: 0.97, with mean specificity of 0.98.\n",
104+
"Estimated mean sensitivity to detect d=0.3, with pi=0.2%, q=0.1 and N=850: 0.98, with mean specificity of 0.98.\n",
105+
"Estimated mean sensitivity to detect d=0.3, with pi=0.2%, q=0.1 and N=900: 0.99, with mean specificity of 0.98.\n",
106+
"Estimated mean sensitivity to detect d=0.3, with pi=0.2%, q=0.1 and N=950: 0.99, with mean specificity of 0.98.\n"
107+
]
108+
}
109+
],
110+
"source": [
111+
"for result in result_list:\n",
112+
" print(result)"
113+
]
114+
},
115+
{
116+
"cell_type": "code",
117+
"execution_count": null,
118+
"id": "cd6f422f",
119+
"metadata": {},
120+
"outputs": [],
121+
"source": []
122+
}
123+
],
124+
"metadata": {
125+
"kernelspec": {
126+
"display_name": "Python 3 (ipykernel)",
127+
"language": "python",
128+
"name": "python3"
129+
},
130+
"language_info": {
131+
"codemirror_mode": {
132+
"name": "ipython",
133+
"version": 3
134+
},
135+
"file_extension": ".py",
136+
"mimetype": "text/x-python",
137+
"name": "python",
138+
"nbconvert_exporter": "python",
139+
"pygments_lexer": "ipython3",
140+
"version": "3.10.10"
141+
}
142+
},
143+
"nbformat": 4,
144+
"nbformat_minor": 5
145+
}

0 commit comments

Comments
 (0)