fig = plt.figure(figsize = (32, 32))
gs = GridSpec(nrows = 5, ncols = 3, figure=fig, height_ratios=[0.4, 1, 1, 1, 1])
axcol = [None for i in range(4)]
def boxplot_col(fig, grid, colidx, variable, variable_values, variable_label,
methods = methods, score_names = score_names,
dscout = dscout, method_colors = method_colors):
nmethods = len(methods)
nvariables = len(variable_values)
nscores = len(score_names)
axs = [fig.add_subplot(grid[i + 1, colidx]) for i in range(nscores)]
boxs = {x: None for x in methods.keys()}
for i, (score_name, score_label) in enumerate(score_names.items()):
scores = get_scores_from_dataframe(dscout, score_name, variable, variable_values)
for j, mkey in enumerate(methods.keys()):
boxcolor = method_colors[mkey]
boxface = f'#{boxcolor[1:]}80'
medianprops = dict(linewidth=0, color = boxcolor)
whiskerprops = dict(linewidth=2, color = boxcolor)
boxprops = dict(linewidth=2, color = boxcolor, facecolor = boxface)
flierprops = dict(marker='o', markerfacecolor=boxface, markersize=3, markeredgecolor = boxcolor)
xpos = [x * (nmethods + 1) + j for x in range(nvariables)]
boxs[mkey] = axs[i].boxplot(scores[mkey], positions = xpos,
showcaps = False, showfliers = False,
widths = 0.7, patch_artist = True, notch = False,
flierprops = flierprops, boxprops = boxprops,
medianprops = medianprops, whiskerprops = whiskerprops)
axs[i].scatter(random_jitter(xpos, scores[mkey]), scores[mkey],
edgecolor = boxcolor, facecolor = boxface, linewidths = 1,
s = 10)
xcenter = [x * (nmethods + 1) + (nmethods - 1) / 2 for x in range(nvariables)]
axs[i].set_xticks(xcenter)
axs[i].set_xticklabels(variable_values)
if i == 0:
axs[i].set_xlabel(variable_label, labelpad = 30)
axs[i].xaxis.set_label_position('top')
# axs[i].set_ylabel(score_label)
xlim_low = 0 - (nvariables - 1) / 2
#xlim_high = (nvariables - 1) * (nmethods + 1) + (nmethods - 1) + (nvariables - 1) / 2
xlim_high = (nmethods + 1.5) * nvariables - 2.5
axs[i].set_xlim( xlim_low, xlim_high )
plt.tight_layout()
return axs, boxs
colidx = 0
variable = 'p'
variable_values = [500, 1000, 2000, 5000, 10000]
# variable_values = [500, 1000]
variable_label = r'No. of variants ($p$)'
axcol[colidx], boxs[colidx] = boxplot_col(fig, gs, colidx, variable, variable_values, variable_label)
colidx = 1
variable = 'k'
variable_values = [2, 5, 10, 15, 20]
# variable_values = [2, 5]
variable_label = r'No. of factors ($k$)'
axcol[colidx], boxs[colidx] = boxplot_col(fig, gs, colidx, variable, variable_values, variable_label)
colidx = 2
variable = 'h2'
variable_values = [0.05, 0.1, 0.2, 0.3, 0.4]
# variable_values = [0.05, 0.1]
variable_label = r'Heritability ($h^2$)'
axcol[colidx], boxs[colidx] = boxplot_col(fig, gs, colidx, variable, variable_values, variable_label)
colidx = 3
variable = 'aq'
variable_values = [0.4, 0.6, 0.8]
# variable_values = [0.4, 0.6]
variable_label = r'Strength of correlation ($\alpha_q$)'
axcol[colidx], boxs[colidx] = boxplot_col(fig, gs, colidx, variable, variable_values, variable_label)
# Legend
axleg = fig.add_subplot(gs[0, :])
handles = [boxs[0][mkey]["boxes"][0] for mkey in methods.keys()]
labels = [method_labels[mkey] for mkey in methods.keys()]
axleg.legend(handles = handles, labels = labels, loc = 'upper left', frameon = False, handlelength = 4, ncol = 2)
for side, border in axleg.spines.items():
border.set_visible(False)
axleg.tick_params(bottom = False, top = False, left = False, right = False,
labelbottom = False, labeltop = False, labelleft = False, labelright = False)
# Score labels for each row
for i, (score_name, score_label) in enumerate(score_names.items()):
ax = fig.add_subplot(gs[i + 1, :])
ax.patch.set_facecolor("None")
ax.set_ylabel(score_label, labelpad = 120)
ax.tick_params(bottom = False, top = False, left = False, right = False,
labelbottom = False, labeltop = False, labelleft = False, labelright = False)
for side, border in ax.spines.items():
border.set_visible(False)
plt.savefig('../plots/rppr-2024/numerical_experiments.png', bbox_inches='tight')
plt.savefig('../plots/rppr-2024/numerical_experiments.pdf', bbox_inches='tight')
plt.show()