How I get traceplot (or something else) to show priors?

How can do I get traceplot to show the prior’s value for all variables? Traceplot takes has a priors argument, but I can’t get the syntax right. I’m trying to use pymc3 for bayesian a/b testing and want to the choice prior values and hyperprior distributions effects the posterior, if at all. Also any suggestions for other ways to see how priors influence the posterior.

EXPERIMENT_NAME = "Global Search"

# a 
variant_name_a = "Control"
n_a            = 110198
hto_orders_a   = 5555
sales_orders_a = 3361

# b
variant_name_b = "Variant"
n_b            = 110062
hto_orders_b   = 5533
sales_orders_b = 3407
samples = 10000

with pm.Model() as unadjusted_web_only_model:
        ######### prior #########

        ### HTO COVR ###
        hto_alpha = pm.HalfCauchy("hto_alpha",1)
        hto_beta = pm.HalfCauchy("hto_beta",19)

        hto_conversion_a = pm.Beta('hto_conversion_a', alpha=hto_alpha, beta=hto_beta)
        hto_conversion_b = pm.Beta('hto_conversion_b', alpha=hto_alpha, beta=hto_beta)
        hto_lift = pm.Deterministic("hto_lift", hto_conversion_b-hto_conversion_a)

        ###Sales COVR ###

        sales_alpha = pm.HalfCauchy("sales_alpha",1)
        sales_beta = pm.HalfCauchy("sales_beta",32)

        sales_conversion_a = pm.Beta('sales_conversion_a', alpha=sales_alpha, beta=sales_beta)
        sales_conversion_b = pm.Beta('sales_conversion_b', alpha=sales_alpha, beta=sales_beta)
        unadjusted_sales_lift = pm.Deterministic("unadjusted_sales_lift", sales_conversion_b-sales_conversion_a)

        ## Liklihoods
        hto_y_a = pm.Binomial('hto_y_a', n=model_n_a, p=hto_conversion_a, observed=model_hto_orders_a)
        sales_y_a = pm.Binomial('sales_y_a', n=model_n_a,p=sales_conversion_a, observed=model_sales_orders_a)
        hto_y_b = pm.Binomial('hto_y_b', n=model_n_b, p=hto_conversion_b, observed=model_hto_orders_b)
        sales_y_b = pm.Binomial('sales_y_b',n=model_n_b, p=sales_conversion_b, observed=model_sales_orders_b)

        start = pm.find_MAP() 
        step = pm.Metropolis()
        trace = pm.sample(samples,start=start,step=step)
        chain = trace[burnin:]

pm.traceplot(chain, priors=chain.varnames)
I get an error when priors is a list of variables and when it is a string of the name of variables. What am I doing wrong?

You can find more information here:, specifically: “priors (iterable of PyMC distributions) – PyMC prior distribution(s) to be plotted alongside posterior. Defaults to None (no prior plots).” Thus, you need to pass e.g. pm.Normal.dist(mu=0, sd=1).

Thank you so much! I figured it was something simple like that.

I couldn’t figure out what “iterable of PyMC distributions” in API docs meant without the example. Very clear with the example. Might be worth adding to the docs or an example below? If it would be accepted, I can try submitting a PR for it since I hate making suggestions that add things to other people’s to do list.

Great point, such a PR would be much appreciated!

is priors argument removed from traceplot function?

I think this feature is removed from Arviz - I created an issue on the pymc3 side:

1 Like