#This scriptfile answers exercise 15 (a) og (b) in
#Eriksen og Lauritzen (2004).
# (a) is obtained by adding 1412 to aa and ab
# (b) is obtained by ba and bb

import scipy
import numpy
from scipy.stats import (chi2, t)

x = numpy.array([0.80, 1.09, 0.86, 0.80, 0.78, 0.85, 0.50, 0.84, 0.84, 1.02, 0.87, 0.80, 0.66, 0.84, 0.72])
m = float(sum(x)) / len(x)
s = (sum((x - m) ** 2) / (len(x) - 1)) ** 0.5
aa = [m - t.ppf(0.975, 14) * s / (15), m + t.ppf(0.975, 14) * s / (15)]
ab = [m - t.ppf(0.995, 14) * s / (15), m + t.ppf(0.995, 14) * s / (15)]
ba = [s * (14 / chi2.ppf(0.75, 14)) ** 0.5, s * (14 / chi2.ppf(0.25, 14)) **
0.5]
bb = [s * (14 / chi2.ppf(0.975, 14)) ** 0.5, s * (14 / chi2.ppf(0.025, 14)) **
0.5]

print('a =', aa, 'og', ab)
print('b =', ba, 'og', bb)
print('a + 1412 =', [aa[0] + 1412, aa[1] + 1412], 'og', [ab[0] + 1412, ab[1] + 1412])



