Skip to content

Commit 7a23ead

Browse files
authored
Plot convergence (#68)
* add plot_converge * add multiple comparison adjustment * add comment
1 parent e859ae3 commit 7a23ead

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

pymc_bart/utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pytensor.tensor.var import Variable
88
from scipy.interpolate import griddata
99
from scipy.signal import savgol_filter
10-
from scipy.stats import pearsonr
10+
from scipy.stats import pearsonr, norm
1111

1212

1313
def _sample_posterior(all_trees, X, rng, size=None, excluded=None):
@@ -92,10 +92,11 @@ def plot_convergence(idata, var_name=None, kind="ecdf", figsize=None, ax=None):
9292

9393
for idx, (essi, rhati) in enumerate(zip(ess, rhat)):
9494
kind_func(essi, ax=ax[0], plot_kwargs={"color": f"C{idx}"})
95-
ax[0].axvline(ess_threshold, color="k", ls="--")
95+
ax[0].axvline(ess_threshold, color="0.7", ls="--")
9696
kind_func(rhati, ax=ax[1], plot_kwargs={"color": f"C{idx}"})
97-
ax[1].axvline(1.01, color="0.6", ls="--")
98-
ax[1].axvline(1.05, color="k", ls="--")
97+
# Assume Rhats are N(1, 0.005) iid. Then compute the 0.99 quantile
98+
# scaled by the sample size and use it as a threshold.
99+
ax[1].axvline(norm(1, 0.005).ppf(0.99 ** (1 / ess.size)), color="0.7", ls="--")
99100

100101
ax[0].set_xlabel("ESS")
101102
ax[1].set_xlabel("R-hat")

0 commit comments

Comments
 (0)