diff --git a/src/metaDMG/fit/bayesian.py b/src/metaDMG/fit/bayesian.py index c288a0f..b9c2d96 100644 --- a/src/metaDMG/fit/bayesian.py +++ b/src/metaDMG/fit/bayesian.py @@ -97,32 +97,33 @@ def add_D_information( beta = (1 - Dx) * phi # 1000x faster approximation for sp_betabinom(N, alpha, beta) - pdf_approx = sp_betabinom(N, alpha.mean(), beta.mean()) + # pdf_approx = sp_betabinom(N, alpha.mean(), beta.mean()) fit_result[f"{prefix}damage"] = mu.item() fit_result[f"{prefix}damage_std"] = std.item() fit_result[f"{prefix}significance"] = mu.item() / std.item() - fit_result[f"{prefix}damage_median"] = np.median(A) + + # fit_result[f"{prefix}damage_median"] = np.median(A) # fit_result[f"{prefix}prob_lt_1p_damage"] = pdf_beta.cdf(0.01).mean() # # fit_result[f"{prefix}prob_lt_1p_damage_betabinom"] = pdf.cdf(0.01 * N).mean() # fit_result[f"{prefix}prob_zero_damage"] = pdf.cdf(0).mean() - for n_sigma in [1, 2, 3]: - conf = get_n_sigma_probability(n_sigma) - fit_result[f"{prefix}damage_CI_{n_sigma}_sigma_low"] = ( - pdf_approx.ppf((1 - conf) / 2.0).mean() / N - ) - fit_result[f"{prefix}damage_CI_{n_sigma}_sigma_high"] = ( - pdf_approx.ppf((1 + conf) / 2.0).mean() / N - ) - - fit_result[f"{prefix}damage_CI_95_low"] = ( - pdf_approx.ppf((1 - 0.95) / 2.0).mean() / N - ) - fit_result[f"{prefix}damage_CI_95_high"] = ( - pdf_approx.ppf((1 + 0.95) / 2.0).mean() / N - ) + # for n_sigma in [1, 2, 3]: + # conf = get_n_sigma_probability(n_sigma) + # fit_result[f"{prefix}damage_CI_{n_sigma}_sigma_low"] = ( + # pdf_approx.ppf((1 - conf) / 2.0).mean() / N + # ) + # fit_result[f"{prefix}damage_CI_{n_sigma}_sigma_high"] = ( + # pdf_approx.ppf((1 + conf) / 2.0).mean() / N + # ) + + # fit_result[f"{prefix}damage_CI_95_low"] = ( + # pdf_approx.ppf((1 - 0.95) / 2.0).mean() / N + # ) + # fit_result[f"{prefix}damage_CI_95_high"] = ( + # pdf_approx.ppf((1 + 0.95) / 2.0).mean() / N + # ) return fit_result @@ -158,9 +159,9 @@ def add_summary_of_variable( fit_result[f"{s}"] = np.mean(values, axis=axis) fit_result[f"{s}_std"] = np.std(values, axis=axis) - fit_result[f"{s}_median"] = np.median(values, axis=axis) - fit_result[f"{s}_CI_1_sigma_low"] = np.quantile(values, q_low, axis=axis) - fit_result[f"{s}_CI_1_sigma_high"] = np.quantile(values, q_high, axis=axis) + # fit_result[f"{s}_median"] = np.median(values, axis=axis) + # fit_result[f"{s}_CI_1_sigma_low"] = np.quantile(values, q_low, axis=axis) + # fit_result[f"{s}_CI_1_sigma_high"] = np.quantile(values, q_high, axis=axis) def compute_rho_Ac(mcmc): diff --git a/src/metaDMG/viz/app.py b/src/metaDMG/viz/app.py index 0c73dcc..bd4e0d6 100644 --- a/src/metaDMG/viz/app.py +++ b/src/metaDMG/viz/app.py @@ -263,39 +263,39 @@ def update_sidebar_right_datatable_results(click_data): bayesian_list = [] if viz_results.Bayesian: - s_D = f", [{ds['damage_CI_1_sigma_low']:.2%}, {ds['damage_CI_1_sigma_high']:.2%}]" + # s_D = f", [{ds['damage_CI_1_sigma_low']:.2%}, {ds['damage_CI_1_sigma_high']:.2%}]" - conf_q_low = ds["q_CI_1_sigma_low"] - conf_q_high = ds["q_CI_1_sigma_high"] - s_q = f", [{conf_q_low:.3f}, {conf_q_high:.3f}]" + # conf_q_low = ds["q_CI_1_sigma_low"] + # conf_q_high = ds["q_CI_1_sigma_high"] + # s_q = f", [{conf_q_low:.3f}, {conf_q_high:.3f}]" - conf_phi_low = viz_utils.human_format(ds["phi_CI_1_sigma_low"]) - conf_phi_high = viz_utils.human_format(ds["phi_CI_1_sigma_high"]) - s_phi = f", [{conf_phi_low}, {conf_phi_high}]" + # conf_phi_low = viz_utils.human_format(ds["phi_CI_1_sigma_low"]) + # conf_phi_high = viz_utils.human_format(ds["phi_CI_1_sigma_high"]) + # s_phi = f", [{conf_phi_low}, {conf_phi_high}]" - conf_A_low = ds["A_CI_1_sigma_low"] - conf_A_high = ds["A_CI_1_sigma_high"] - s_A = f", [{conf_A_low:.3f}, {conf_A_high:.3f}]" + # conf_A_low = ds["A_CI_1_sigma_low"] + # conf_A_high = ds["A_CI_1_sigma_high"] + # s_A = f", [{conf_A_low:.3f}, {conf_A_high:.3f}]" - conf_c_low = ds["c_CI_1_sigma_low"] - conf_c_high = ds["c_CI_1_sigma_high"] - s_c = f", [{conf_c_low:.3f}, {conf_c_high:.3f}]" + # conf_c_low = ds["c_CI_1_sigma_low"] + # conf_c_high = ds["c_CI_1_sigma_high"] + # s_c = f", [{conf_c_low:.3f}, {conf_c_high:.3f}]" bayesian_list = [ "Fit results:", html.Br(), - f"D: {ds['damage']:.2%} " f"± {ds['damage_std']:.2%}" + s_D, + f"D: {ds['damage']:.2%} " f"± {ds['damage_std']:.2%}", # + s_D, html.Br(), f"significance: {ds['significance']:.2f}", html.Br(), - f"q: {ds['q']:.3f} " f"± {ds['q_std']:.3f}" + s_q, + f"q: {ds['q']:.3f} " f"± {ds['q_std']:.3f}", # + s_q, html.Br(), f"phi: {viz_utils.human_format(ds['phi'])} " - f"± {viz_utils.human_format(ds['phi_std'])}" + s_phi, + f"± {viz_utils.human_format(ds['phi_std'])}", # + s_phi, html.Br(), - f"A: {ds['A']:.3f} " f"± {ds['A_std']:.3f}" + s_A, + f"A: {ds['A']:.3f} " f"± {ds['A_std']:.3f}", # + s_A, html.Br(), - f"c: {ds['c']:.3f} " f"± {ds['c_std']:.3f}" + s_c, + f"c: {ds['c']:.3f} " f"± {ds['c_std']:.3f}", # + s_c, html.Br(), f"rho Ac: {ds['rho_Ac']:.3f}", html.Br(), diff --git a/src/metaDMG/viz/figures.py b/src/metaDMG/viz/figures.py index c6aafc3..f6c781b 100644 --- a/src/metaDMG/viz/figures.py +++ b/src/metaDMG/viz/figures.py @@ -12,11 +12,14 @@ from matplotlib import ticker from matplotlib.backends.backend_pdf import PdfPages from matplotlib.ticker import EngFormatter -from tqdm import tqdm +from tqdm.rich import tqdm from metaDMG.viz import viz_utils +# from tqdm import tqdm + + #%% plt.rcParams["text.usetex"] = True @@ -255,7 +258,8 @@ def plot_group( # add damage as single errorbar if D_info is not None: - D, D_low, D_high = D_info + # D, D_low, D_high = D_info + D, D_std = D_info # fit with errorbars fig.add_trace( @@ -264,9 +268,10 @@ def plot_group( y=[D], error_y=dict( type="data", - symmetric=False, - array=[D_high - D], - arrayminus=[D - D_low], + array=[D_std], + # symmetric=False, + # array=[D_high - D], + # arrayminus=[D - D_low], visible=True, color="black", ), diff --git a/src/metaDMG/viz/results.py b/src/metaDMG/viz/results.py index 2561191..61e3a74 100644 --- a/src/metaDMG/viz/results.py +++ b/src/metaDMG/viz/results.py @@ -105,14 +105,14 @@ def correct_for_non_LCA(df): def add_MAP_measures(df): df["MAP_rho_Ac_abs"] = np.abs(df["MAP_rho_Ac"]) - df["MAP_damage_CI_low"] = df["MAP_damage"] - df["MAP_damage_std"] - df["MAP_damage_CI_high"] = df["MAP_damage"] + df["MAP_damage_std"] + # df["MAP_damage_CI_low"] = df["MAP_damage"] - df["MAP_damage_std"] + # df["MAP_damage_CI_high"] = df["MAP_damage"] + df["MAP_damage_std"] def add_bayesian_measures(df): df["rho_Ac_abs"] = np.abs(df["rho_Ac"]) - df["damage_CI_low"] = df["damage_CI_1_sigma_low"] - df["damage_CI_high"] = df["damage_CI_1_sigma_high"] + # df["damage_CI_low"] = df["damage_CI_1_sigma_low"] + # df["damage_CI_high"] = df["damage_CI_1_sigma_high"] #%% @@ -502,13 +502,14 @@ def get_D(self, sample, tax_id): prefix = "MAP_" D = ds[f"{prefix}damage"].iloc[0] + D_sigma = ds[f"{prefix}damage_std"].iloc[0] - s1 = f"{prefix}damage_CI_low" - s2 = f"{prefix}damage_CI_high" - D_low = ds[s1].iloc[0] - D_high = ds[s2].iloc[0] + # s1 = f"{prefix}damage_CI_low" + # s2 = f"{prefix}damage_CI_high" + # D_low = ds[s1].iloc[0] + # D_high = ds[s2].iloc[0] - return D, D_low, D_high + return D, D_sigma def _ds_to_fit_text(self, ds): diff --git a/src/metaDMG/viz/viz_utils.py b/src/metaDMG/viz/viz_utils.py index cd1db17..4de8f49 100644 --- a/src/metaDMG/viz/viz_utils.py +++ b/src/metaDMG/viz/viz_utils.py @@ -267,8 +267,8 @@ def get_range_slider_keywords(viz_results, column="N_reads", N_steps=100): "q", "A", "c", - "damage_CI_low", - "damage_CI_high", + # "damage_CI_low", + # "damage_CI_high", ]: range_min = 0.0 range_max = 1.0 @@ -633,10 +633,10 @@ def get_d_columns_latex(viz_results): "significance": r"$\text{significance}$", "MAP_significance": r"$\text{significance} \,\, \text{(MAP)}$", # - "damage_CI_low": r"$D \,\, \text{CI. low}$", - "damage_CI_high": r"$D \,\, \text{CI. high}$", - "MAP_damage_CI_low": r"$D \,\, \text{CI. low} \,\, \text{(MAP)}$", - "MAP_damage_CI_high": r"$D \,\, \text{CI. high} \,\, \text{(MAP)}$", + # "damage_CI_low": r"$D \,\, \text{CI. low}$", + # "damage_CI_high": r"$D \,\, \text{CI. high}$", + # "MAP_damage_CI_low": r"$D \,\, \text{CI. low} \,\, \text{(MAP)}$", + # "MAP_damage_CI_high": r"$D \,\, \text{CI. high} \,\, \text{(MAP)}$", # "q": r"$q$", "MAP_q": r"$q \text{(MAP)}$",