# Program to find measure of expected significance as a function # of a cut value x_cut applied to measured variable x. # G. Cowan / RHUL Physics / December 2022 # Full version containing exercise solutions import numpy as np import scipy.stats as stats import matplotlib.pyplot as plt plt.rcParams["font.size"] = 14 # Plot the pdfs def f_s(x): return 3.*(1-x)**2 def f_b(x): return 3.*x**2 x = np.linspace(0., 1., 201) fs = f_s(x) fb = f_b(x) fig = plt.figure(figsize=(5,5)) plt.plot(x, fs, color='orange', label=r'$f(x|s)$') plt.plot(x, fb, color='dodgerblue', label=r'$f(x|b)$') plt.xlabel(r'$x$') plt.ylabel(r'$f(x)$') plt.xlim(0., 1.) plt.ylim(0., 3.) plt.legend(loc='upper center', frameon=False) plt.subplots_adjust(left=0.15, right=0.9, top=0.9, bottom=0.15) plt.show() # Find x_cut for size alpha = 0.05 alpha = 0.05 xc05 = alpha**(1./3.) print("For alpha=0.05, x_cut = {:.3f}".format(xc05)) # Find power with respect to s for this x_cut power = 1. - (1. - xc05)**3 print("Power = {:.3f}".format(power), "\n") # Plot critical region fig = plt.figure(figsize=(5,5)) plt.plot(x, fs, color='orange', label=r'$f(x|s)$') plt.plot(x, fb, color='dodgerblue', label=r'$f(x|b)$') plt.xlabel(r'$x$') plt.ylabel(r'$f(x)$') plt.xlim(0., 1.) plt.ylim(0., 3.) plt.legend(loc=(0.65,0.2), frameon=False) plt.subplots_adjust(left=0.15, right=0.9, top=0.9, bottom=0.15) plt.axvline(xc05, color="black") plt.fill_between(x=x, y1= fs, where=x