How to plot matrix plot of correlations in pymc3?


#1

Hi everyone,
I am new user pymc3. I don’t know how to plot matrix of correlations in pymc3?
please help me!!
thanks you


#2

What exactly are you trying to correlate? It would help if you could be more specific, framed your problem and listed out what you’d tried and where you’re stuck.

If you’re trying to look at correlations in the traces, you can extract them with trace.get_values, you specify the chains and it will give you a numpy array to do with what you want.


#3

My personal favorite is pairplot. You can try with arviz or seaborn. If you just want to see the Pearson correlation as a matrix you can use numpy.corr and pyplot.pcolor. If you need a but more help getting those to run, just ask


#4

my problem:
I have three coefficients with prior uniform distribution:
C_1 (0.054,0.066); C_2 (0.9,1.1); C_3 (45,55)

I have surrogate model of three coefficients:
mu = -1.2*c_1^2+0.01*c_1*c_2+0.05*c2^2-0.0004*c_1*c_3+0.16*c_1-0.0001*c_2*c_3+2.01*c3^2-0.002*c_2-4.03*c_3+0.01

I want to find the correlations of three coefficients with mu and the posterior of mu.

please help me.


#5

You can do prior sample and posterior sample of C_1, C_2, C_3, and mu, and compute correlation between each pair between C_1, C_2, C_3, and mu


#6

this is my code :

a= -1.24
b=0.011
c=0.005
d=-0.0004
e=0.16
f=-0.00013
g=-2.01e-6
k=-0.002
m=-4.03e-5
l=0.0165

basic_model = pm.Model()

with basic_model:
nodes1 = pm.Normal(‘nodes1’, 0.05, 0.06)
nodes2 = pm.Normal(‘nodes2’, 1.0, 0.1)
nodes3 = pm.Normal(‘nodes3’, 50, 5)
mu=a.nodes1^2+b.nodes1.nodes2+c.nodes2^2+d.nodes1.nodes3+e.nodes1+f.nodes2.nodes3+g.nodes3^2+k.nodes2+m.nodes3+l
pm.Normal(‘observed’, mu, 0.05, observed=evals)
trace = pm.sample(1000, cores =1)
pm.traceplot(trace,varnames= [‘nodes1’,‘nodes2’,‘nodes3’])
k = pm.summary(trace).round(2)
pm.plot_posterior (trace, varnames= [‘nodes1’,‘nodes2’,‘nodes3’])
tracedf1 = pm.trace_to_dataframe (trace, varnames = [‘nodes1’,‘nodes2’,‘nodes3’])
sns.pairplot(tracedf1 )
print (k)
plt.show()

in this my code just plot correlations of nodes1, nodes2 and nodes3 can’t plot with mu. And I also want to calculate correlation values between each pair between nodes1,nodes2 nodes3 and mu.

Having a problem I don’t understand in my code that is using the this code

pm.Normal(‘observed’, mu, 0.05, observed=evals)

but I want to use the multivariate normal distribution so What things I need to find to I can apply the multivariate normal distribution to my problem. Because our prior distribution is Uniform distribution when I use it for pm.Normal (‘observed’,mu,0.05, observed=evals) the posterior distribution shape isn’t Bell shape.

please help me.

thank you