State which hypothesis best matches the scenario and justify your answer
Choose and peform hypothesis tests for the following examples. Report your p-values!!
Ting says your cellphone bill will be about \$50 or lower if you switch. You switch and find your bills a are \\$48, \$ 53, \\$67, \$44. Was their claim correct?
You are testing the efficacy of a drug that causes weight loss. You have 15 patients try the drug. Their weights in pounds before are [178,189,136,134,172,171,178,179,154,159,167,149,125,180,135] and after are [174,178,139,133,166,165,172,180,141,145,176,151,108,174,131]. Is the drug effective?
In [21]:
import scipy.stats as ss
#Poisson
1 - ss.poisson.cdf(10, 8)
Out[21]:
In [25]:
Z = (12 - 8) / 2
2 * ss.norm.cdf(-Z)
Out[25]:
In [32]:
bills = [45, 53, 67, 44]
bm = np.mean(bills)
bs = np.std(bills, ddof=1)
T = (bm - 50) / (bs / np.sqrt(len(bills)))
2 * ss.t.cdf(-T, df=len(bills) - 1)
Out[32]:
In [38]:
before = [178,189,136,134,172,171,178,179,154,159,167,149,125,180,135]
after = [174,178,139,133,166,165,172,180,141,145,176,151,108,174,131]
ss.wilcoxon(before, after)
Out[38]:
In [44]:
beforec = [211,175,151,160,163,137,169,145,171,177,148,145,173,174,167]
afterc = [200,171,146,162,178,134,183,148,164,166,141,142,166,167,142]
changec = [b - a for b,a in zip(beforec,afterc)]
change = [b - a for b,a in zip(before, after)]
ss.ranksums(change, changec)
Out[44]:
In [48]:
import scipy.optimize as opt
opt.root(lambda x: np.tan(x) - x**2 - 1, x0=1)
Out[48]:
In [49]:
opt.minimize(lambda x: (x - 4)**2, x0=0)
Out[49]:
In [53]:
import matplotlib.pyplot as plt
%matplotlib inline
x = np.linspace(-4, 4, 500)
plt.plot(x, x**2 * np.sin(x)**2)
Out[53]:
In [56]:
def sys(v):
x = v[0]
y = v[1]
return [x**2 - y - 18, np.sqrt(x) + y**2 - 6]
opt.root(sys, x0 = [1,-1])
Out[56]: