In [1]:
import numpy as np
from scipy import stats
%matplotlib inline
import matplotlib.pyplot as plt
In [2]:
import os, sys
# add utilities directory to path
util_path = os.path.abspath(os.path.join(os.path.pardir, 'utilities_and_data'))
if util_path not in sys.path and os.path.exists(util_path):
sys.path.insert(0, util_path)
# import from utilities
import plot_tools
In [3]:
# edit default plot settings
plt.rc('font', size=12)
In [4]:
# data
data_path = os.path.abspath(
os.path.join(
os.path.pardir,
'utilities_and_data',
'light.txt'
)
)
y = np.loadtxt(data_path)
# sufficient statistics
n = len(y)
s2 = np.var(y, ddof=1)
my = np.mean(y)
In [5]:
# tail area probabilities of marginal predictive distributions
Ty = stats.t.cdf(y, n-1, loc=my, scale=np.sqrt(s2*(1+1/n)))
In [6]:
# plot
plt.hist(Ty, np.arange(0, 1.01, 0.05))
plt.xlim((0, 1))
plt.title('Light speed example\ndistribution of marginal posterior p-values')
plot_tools.modify_axes.only_x(plt.gca())