Notebook on nbviewer (original) (raw)
mu2 = trace2['mu'] sigma2 = trace2['sigma']
Concatenate the fixed thresholds into the estimated thresholds
n = trace2['theta_missing'].shape[0] thresholds2 = np.c_[np.tile([1.5], (n,1)), trace2['theta_missing'], np.tile([4.5], (n,1))]
fig, axes = plt.subplots(5,2, figsize=(10,14)) ax1,ax2,ax3,ax4,ax5,ax6,ax7,ax8,ax9,ax10 = axes.flatten()
Mu
pm.plot_posterior(mu2[:,0], point_estimate='mode', color=color, ax=ax1) ax1.set_xlabel('$\mu_{1}$', fontdict=f_dict) pm.plot_posterior(mu2[:,1], point_estimate='mode', color=color, ax=ax3) ax3.set_xlabel('$\mu_{2}$', fontdict=f_dict) for title, ax in zip(['A Mean', 'B Mean'], [ax1, ax3]): ax.set_title(title, fontdict=f_dict)
Sigma
pm.plot_posterior(sigma2[:,0], point_estimate='mode', color=color, ax=ax5) ax5.set_xlabel('$\sigma_{1}$', fontdict=f_dict) pm.plot_posterior(sigma2[:,1], point_estimate='mode', color=color, ax=ax7) ax7.set_xlabel('$\sigma_{2}$', fontdict=f_dict) for title, ax in zip(['A Std. Dev.', 'B Std. Dev.'], [ax5, ax7]): ax.set_title(title, fontdict=f_dict)
Posterior distribution on the thresholds
ax9.scatter(thresholds2, np.tile(thresholds2.mean(axis=1).reshape(-1,1), (1,4)), color=color, alpha=.6, facecolor='none') ax9.set_ylabel('Mean Threshold', fontdict=f_dict) ax9.set_xlabel('Threshold', fontdict=f_dict) ax9.vlines(x = thresholds2.mean(axis=0), ymin=thresholds2.mean(axis=1).min(), ymax=thresholds2.mean(axis=1).max(), linestyles='dotted', colors=color)
Posterior predictive probabilities of the outcomes
threshCumProb2A = np.empty(thresholds2.shape)
for i in np.arange(threshCumProb2A.shape[0]):
threshCumProb2A[i] = norm().cdf((thresholds2[i] - mu2[i,0])/sigma2[i,0])
outProb2A = (np.c_[threshCumProb2A, np.tile(1, (thresholds2.shape[0],1))]
- np.c_[np.tile(0, (thresholds2.shape[0],1)), threshCumProb2A])
yerr2A = np.abs(np.subtract(pm.hpd(outProb2A), outProb2A.mean(axis=0).reshape(-1,1)))
ax2.errorbar(x = np.arange(outProb2A.shape[1]), y=outProb2A.mean(axis=0), yerr=yerr2A.T, color=color, fmt='o')
threshCumProb2B = np.empty(thresholds2.shape)
for i in np.arange(threshCumProb2B.shape[0]):
threshCumProb2B[i] = norm().cdf((thresholds2[i] - mu2[i,1])/sigma2[i,1])
outProb2B = (np.c_[threshCumProb2B, np.tile(1, (thresholds2.shape[0],1))]
- np.c_[np.tile(0, (thresholds2.shape[0],1)), threshCumProb2B])
yerr2B = np.abs(np.subtract(pm.hpd(outProb2B), outProb2B.mean(axis=0).reshape(-1,1)))
ax4.errorbar(x = np.arange(outProb2B.shape[1]), y=outProb2B.mean(axis=0), yerr=yerr2B.T, color=color, fmt='o')
for grp, ax in zip(['A', 'B'], [ax2, ax4]): ((df2[df2.X == grp].Y.value_counts()/df2[df2.X == grp].Y.size) .plot.bar(ax=ax, rot=0, color='royalblue')) ax.set_title('Data for {0} with Post. Pred.\nN = {1}'.format(grp, df2[df2.X == grp].Y.size), fontdict=f_dict) ax.set_xlabel('y') sns.despine(ax=ax, left=True) ax.yaxis.set_visible(False)
Mu diff
pm.plot_posterior(mu2[:,1]-mu2[:,0], point_estimate='mode', color=color, ax=ax6) ax6.set_xlabel('$\mu_{2}-\mu_{1}$', fontdict=f_dict)
Sigma diff
pm.plot_posterior(sigma2[:,1]-sigma2[:,0], point_estimate='mode', color=color, ax=ax8) ax8.set_xlabel('$\sigma_{2}-\sigma_{1}$', fontdict=f_dict)
Effect size
pm.plot_posterior((mu2[:,1]-mu2[:,0]) / np.sqrt((sigma2[:,0]**2+sigma2[:,1]**2)/2), point_estimate='mode', color=color, ax=ax10) ax10.set_xlabel(r'$\frac{(\mu_2-\mu_1)}{\sqrt{(\sigma_1^2+\sigma_2^2)/2}}$', fontdict=f_dict) for title, ax in zip(['Differences of Means', 'Difference of Std. Dev's', 'Effect Size'], [ax6, ax8, ax10]): ax.set_title(title, fontdict=f_dict)
fig.tight_layout()