ex3 practical exercises for Example Sheet 3.¶
To test your answers on Moodle,
please upload either a Jupyter notebook called ex3.ipynb or a plain Python file called ex3.py.
We have a data $x_1,\dots,x_m$ drawn from $\operatorname{Exp}(\mu)$, and $y_1,\dots,y_n$ drawn from $\operatorname{Exp}(\nu)$.
- Compute a confidence interval for $\hat{\nu}-\hat{\mu}$, using parametric resampling
- Compute a confidence interval for $\hat{\nu}-\hat{\mu}$, using non-parametric resampling
- Test if $\mu=\nu$, using a parametric test with test statistic $\hat{\nu}-\hat{\mu}$
- Test if $\mu=\nu$, using a non-parametric test with the same test statistic
- Test if $\mu\leq\nu$, using a parametric test with the same test statistic
Implement the following functions:
def exp_confint_parametric(x, y, q=0.95): return (lo,hi)
def exp_confint_nonparamatric(x, y, q=0.95): return (lo,hi)
def exp_pvalue_equality_parametric(x, y): return p
def exp_pvalue_equality_nonparametric(x, y): return p
def exp_pvalue_onesided_parametric(x, y): return p
NOTE. These functions are meant to compute 95% confidence intervals and $p$-values, using computational approximation based on sampling. This means that your answers might not be exact. You should be able to use around 30,000 samples with no more than a few seconds of runtime, and this should be enough to pass the tester. If you can't, you should refactor your code to make it faster (using numpy vectorized commands).
The tester will always use the same $(x,y)$ dataset when it calls your functions. The function arguments are only passed in for your convenience. If you wish, you can precompute all the answers and simply provide dummy functions that return your precomputed answers. The specific dataset the tester uses is tiny, only 11 datapoints, so the nonparametric and the parametric approaches give very different answers.
TEST¶
The Moodle checker will look for a markdown cell with the contents # TEST, and ignore everything beneath it. Put your working code above this cell, and put any experiments and tests below.
import numpy as np
x = np.array([0.89, 0.97, 1.30, 1.85, 1.05, 0.53])
y = np.array([1.51, 2.24, 1.21, 3.16, 2.1])
lo,hi = exp_confint_parametric(x, y, q=.95)
lo,hi
(-1.927486721023633, 0.6278607372034353)