Skip to content

Commit

Permalink
BUG FIX motion metrics plotting full sample
Browse files Browse the repository at this point in the history
THIS IS A MAJOR BUG FIX

the motion metrics were not correctly plotted before this commit
the old behaviour: the summary stats were split by group and has a
separate calculation for the full sample, and when plotting, the
summary stats were the combination of ALL summary stats, rather than
just the full sample.

This has now been fixed with most of the observation remain the same.
  • Loading branch information
htwangtw committed Apr 13, 2023
1 parent cadb13d commit 4f2548f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ def plot_stats(stats):
# rotation=45, ha="right", rotation_mode="anchor"
)
ax.set_title(
f"{dataset}\nMean\u00B1SD={mean_fd:.2f}\u00B1{sd_fd:.2f}; $N={df.shape[0]}$"
f"{dataset}\n"
f"Motion in dataset subgroups\n"
f"Mean\u00B1SD={mean_fd:.2f}\u00B1{sd_fd:.2f}; $N={df.shape[0]}$"
)

# statistical annotation
Expand Down
14 changes: 9 additions & 5 deletions fmriprep_denoise/visualization/motion_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
"label": "Percentage %",
"title": "Significant QC-FC in connectomes\n"
+ r"(uncorrrected, $\alpha=0.05$)",
"ylim": (0, 60),
"ylim": (0, 70),
},
"fdr_p_values": {
"var_name": "qcfc_fdr_significant",
"label": "Percentage %",
"title": "Significant QC-FC in connectomes\n"
+ r"(FDR corrected, $\alpha=0.05$)",
"ylim": (0, 25),
"ylim": (0, 35),
},
"median": {
"var_name": "qcfc_mad",
Expand All @@ -32,7 +32,7 @@
"var_name": "corr_motion_distance",
"label": "Pearson's correlation, absolute value",
"title": "DM-FC",
"ylim": (0, 0.33),
"ylim": (0, 0.65),
},
"modularity": {
"var_name": "modularity",
Expand Down Expand Up @@ -83,15 +83,20 @@ def plot_stats(data, measure):
fontsize="x-large",
)
for i, dataset in enumerate(data):
df = data[dataset].query("groups=='full_sample'")
baseline_values = df.query("strategy=='baseline'")
baseline_mean = baseline_values[measure["label"]].mean()
sns.barplot(
y=measure["label"],
x="strategy",
data=data[dataset],
data=df,
ax=axs[i],
order=strategy_order,
ci=95,
palette=paired_palette,
)
# horizontal line baseline
axs[i].axhline(baseline_mean, ls="-.", c=paired_palette[0])
axs[i].set_title(dataset)
axs[i].set_ylim(measure["ylim"])
axs[i].set_xticklabels(
Expand Down Expand Up @@ -128,7 +133,6 @@ def plot_joint_scatter(path_root, dataset, fmriprep_version):
)
motion = pd.read_csv(path_data, sep="\t", index_col=0)
data = pd.concat([modularity, motion.loc[modularity.index, :]], axis=1)

data = data.drop("groups", axis=1)
data.index.name = "participants"
data = data.reset_index()
Expand Down
1 change: 1 addition & 0 deletions fmriprep_denoise/visualization/strategy_ranking.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def load_data(path_root, datasets, criteria_name="stringent"):
ascending = m != "modularity"
r = (
data[d]
.query("groups=='full_sample'")
.groupby("strategy")[measure["label"]]
.describe()["mean"]
.sort_values(ascending=ascending)
Expand Down
4 changes: 2 additions & 2 deletions fmriprep_denoise/visualization/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ def get_descriptive_data(
# filter data by proportion vol scrubbed
if fd_thresh is not None and proportion_thresh is not None:
scrub_label = (fd2label[fd_thresh], "excised_vol_proportion")
keep_scrub = confounds_phenotype[scrub_label] <= proportion_thresh
keep_scrub = confounds_phenotype.index[keep_scrub]
exclude_scrub = confounds_phenotype[scrub_label] > proportion_thresh
keep_scrub = confounds_phenotype.index[~exclude_scrub]
else:
keep_scrub = confounds_phenotype.index
mask_motion = keep_gross_fd.intersection(keep_scrub)
Expand Down
15 changes: 14 additions & 1 deletion scripts/make_manuscript_figures.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
degrees_of_freedom_loss,
mean_framewise_displacement,
motion_metrics,
strategy_ranking,
)

group_order = {
Expand Down Expand Up @@ -100,15 +101,19 @@
)
axs_modularity = subfigs_modularity[j].subplots(1, 2, sharey=True)
for i, dataset in enumerate(data):
df = data[dataset].query("groups=='full_sample'")
baseline_values = df.query("strategy=='baseline'")
baseline_mean = baseline_values[measure["label"]].mean()
sns.barplot(
y=measure["label"],
x="strategy",
data=data[dataset],
data=df,
ax=axs_modularity[i],
order=strategy_order,
ci=95,
palette=paired_palette,
)
axs_modularity[i].axhline(baseline_mean, ls="-.", c=paired_palette[0])
axs_modularity[i].set_title(dataset)
axs_modularity[i].set_ylim(measure["ylim"])
axs_modularity[i].set_xticklabels(
Expand Down Expand Up @@ -137,3 +142,11 @@
Path(__file__).parents[1] / "outputs" / "meanfd_modularity.png",
transparent=True,
)

data = strategy_ranking.load_data(path_root, datasets)
fig_ranking = strategy_ranking.plot_ranking(data)

fig_ranking.savefig(
Path(__file__).parents[1] / "outputs" / "strategy_ranking.png",
transparent=True
)

0 comments on commit 4f2548f

Please sign in to comment.