Skip to content

Commit

Permalink
minor adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
bdpedigo committed Mar 13, 2023
1 parent a9305e9 commit 478b21c
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 122 deletions.
160 changes: 81 additions & 79 deletions docs/show_data.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion overleaf
Submodule overleaf updated from 68493b to 0dcae8
110 changes: 69 additions & 41 deletions scripts/adjusted_sbm_unmatched_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ def gluefig(name, fig, **kwargs):
"misc": misc,
"resample": i,
"method": method,
"kc-kc": misc["uncorrected_pvalues"].loc["KC", "KC"],
"kc-mbon": misc["uncorrected_pvalues"].loc["KC", "MBON"],
"kc-cn": misc["uncorrected_pvalues"].loc["KC", "CN"],
}
)
resample_results = pd.DataFrame(rows)
Expand Down Expand Up @@ -284,52 +287,77 @@ def gluefig(name, fig, **kwargs):

#%%

set_theme(font_scale=1.25)
set_theme(font_scale=1)

palette = dict(zip(["fisher", "score"], sns.color_palette(n_colors=2)))

fig, ax = plt.subplots(1, 1, figsize=(8, 6))
sns.histplot(
data=resample_results,
x="pvalue",
ax=ax,
# color=neutral_color,
hue="method",
kde=True,
log_scale=True,
stat="density",
bins=15,
palette=palette,

def plot_subgraph_pvalues(overall=False, source=None, target=None, ax=None):
if overall:
x = "pvalue"
title = "Overall"
analytic = pvalue
alpha = 0.05
else:
x = f"{source}-{target}"
title = (
"Subgraph: " + f"{source.upper()}" + r"$\rightarrow$" + f"{target.upper()}"
)
analytic = misc["uncorrected_pvalues"].loc[source.upper(), target.upper()]
alpha = 0.05 / misc["n_tests"]
sns.histplot(
resample_results,
x=x,
hue="method",
ax=ax,
log_scale=True,
bins=25,
stat="density",
palette=palette,
)
ax.axvline(alpha, color="black", linestyle=":", linewidth=2)
ax.axvline(analytic, color="darkred", linestyle="--", linewidth=3, label="Analytic")
ax.set(
xlabel="p-value",
ylabel="",
yticks=[],
title=title,
)
ax.spines["left"].set_visible(False)
sns.move_legend(ax, "upper left", title="Method", frameon=True, fontsize='small')
leg = ax.get_legend()
for text in leg.get_texts():
new_text = text.get_text().capitalize()
if new_text == "Score":
new_text = "Chi-squared"
text.set_text(new_text)

xlims = ax.get_xlim()
ylims = ax.get_ylim()
ax.fill_between(
[alpha, ax.get_xlim()[1]], 0, ax.get_ylim()[1], color="gray", alpha=0.2
)
ax.set_xlim(xlims)
ax.set_ylim(ylims)


fig, axs = plt.subplots(1, 3, figsize=(16, 4), sharex=False)
plot_subgraph_pvalues(overall=True, ax=axs[0])
axs[0].annotate(
"Analytic\ndensity\nadjustment",
(pvalue, 0.2),
color="darkred",
xytext=(-140, -10),
textcoords="offset points",
arrowprops=dict(arrowstyle="-|>", color="darkred"),
)
sns.move_legend(ax, "upper left", title="Method")
leg = ax.get_legend()
for text in leg.get_texts():
text.set_text(text.get_text().capitalize())

for method in ["fisher", "score"]:
median = np.median(resample_results.query(f"method == '{method}'")["pvalue"])
ax.axvline(median, linestyle="-", color=palette[method], linewidth=3)

ax.set(xlabel="p-value", ylabel="", yticks=[])

# draw line for alpha
ax.spines["left"].set_visible(False)
ax.axvline(0.05, linestyle=":", color="black", linewidth=3)
ylim = ax.get_ylim()
ax.text(0.06, ylim[1] * 0.9, r"$\alpha = 0.05$")


color = "darkred"
ax.axvline(pvalue, color=color, linewidth=3, linestyle="--")
# ax.text(
# pvalue - 0.0005,
# ylim[1] * 0.85,
# f"Analytic = {pvalue:0.2g}",
# ha="right",
# color=color,
# )
axs[0].text(0.065, 0.4, "Not\nsig.")
plot_subgraph_pvalues(source="kc", target="kc", ax=axs[1])
plot_subgraph_pvalues(source="kc", target="mbon", ax=axs[2])
axs[1].get_legend().remove()
axs[2].get_legend().remove()

gluefig("resampled_pvalues_distribution", fig)
gluefig("resampled_pvalues_distributions", fig)


#%%
Expand Down
4 changes: 3 additions & 1 deletion scripts/show_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def glue(name, var, **kwargs):
#%%
left_adj = left_adj[indices_left, :][:, indices_left]
right_adj = right_adj[indices_right, :][:, indices_right]
left_nodes = left_nodes.iloc[indices_left]
right_nodes = right_nodes.iloc[indices_right]

#%%

Expand Down Expand Up @@ -309,7 +311,7 @@ def nice_text(x, y, s, color="black"):

left_nodes["degree"] = left_adj.sum(axis=0) + left_adj.sum(axis=1)
left_nodes["x"] = left_umap_embedding[:, 0]
left_nodes["y"] = -left_umap_embedding[:, 1]
left_nodes["y"] = left_umap_embedding[:, 1]


networkplot_kws = dict(
Expand Down

0 comments on commit 478b21c

Please sign in to comment.