Assignment 5
I found a significant p-value!
A paper reports “the treatment group differed from the control group, p < 0.05”. The reader assumes this means the result is real. It does not have to be. By construction, a hypothesis test at significance level of \(\alpha = 0.05\) produces a “significant” p-value in 5% of experiments in which the null hypothesis is true — i.e. in which there is no real effect at all.
In this assignment you will make that statement concrete. You will simulate experiments in which you know there is no effect (both sets of data are drawn from the same normal distribution), run a t-test on each, and watch the false positives pile up. You will then explore a way researchers make the problem worse: “optional stopping” — collecting data until something becomes significant.
Create a script. Your script will receive two command-line arguments, the sample size, \(n\), and the number of times the experiment will be repeated, \(m\). Using these values, the driver script should
- run one batch of \(m\) null experiments of size \(n\) (meaning two groups of size \(n\)), and print out the number that are significant (\(\alpha = 0.05\)), and the number that are expected to be significant.
- print the mean, median and 90th percentile of the distribution of the number of experiments needed before the first significant result appears under optional stopping (running the null experiment, of size \(n\), until a significant result is found), repeated 300 times (which may be hard-coded) alongside the theoretical mean 1/0.05 = 20 (the
quantilefunction may be helpful here).
Your code should be modular, as much as you think is necessary, and use coding best-practices. You should also implement defensive programming; as much as is needed.
Running the script should produce output in the spirit of:
$ Rscript PHacking.Analysis.R 20 1000
Experiments that came out 'significant' (p < 0.05): 58
Expected number by pure chance (0.05 * 1000) : 50.0
Experiments needed before the first 'significant' one:
mean : 19.9 (theory: 1/0.05 = 20)
median : 13.0 (theory: ln(2)/0.05 ~ 14)
90th pct: 46.0
Because of the random nature of the simulation, your numbers will differ, but the story must be the same: roughly 5% of no-effect experiments are “significant”; a batch of many tests is almost guaranteed to contain at least one false positive; and a researcher who keeps trying until something works will, on average, “discover” something within about 20 attempts — purely by chance.
Assignments will be graded on a 10 point basis.
Due date: October 23rd, 11:59pm, with 0.5 point penalty per day for late submission until the cut-off date, October 29th, 9:00am.