Wikipedia defines a p-value as follows:
the p-value is the probability of obtaining test results at least as extreme as the result actually observed, under the assumption that the null hypothesis is correct.
And to compute a p-value, we need a sampling distribution.
My question is: when we talk about the null hypothesis here, are we referring to the sampling distribution constructed:
- Before any data is collected (a priori), or
- After data has been collected (a posteriori)?
Bonus points for providing any reference which speaks to this explicitly.
I think the correct answer is the a priori version, otherwise our type 1 and 2 error rates may deviate from the rates specified during the power analysis. However, I believe most A/B test software calculates the p-value from the sampling distribution generated directly from the sample data collected - so I'm confused.
Quick example
Suppose that I am planning to test a new website landing page, with the aim of improving conversion rates. Applying the Null Hypothesis Significance Testing framework (NHST), I lay out my hypotheses a priori:
- Null hypothesis (H0): treatment and control samples are drawn from populations with identical proportions: 6% conversion rates
- Alternate hypothesis (HA): treatment and control samples are drawn from populations with different proportions: 7% and 5% conversion rates, respectively
To achieve a significance level of 0.05 and a power of 0.8, I calculate a minimum required sample size of 2213:
# R code
prop_baseline <- 0.05
prop_treatment <- 0.07
alpha <- 0.05
beta <- 0.2
n <- ceiling(
power.prop.test(
p1 = prop_baseline,
p2 = prop_treatment,
sig.level = alpha,
power = 1-beta,
alternative = c("two.sided")
)$n
)
n
# [1] 2213
I also determine the a priori critical value (= 1.4%):
prop_pooled <- (prop_baseline+prop_treatment)/2
se_h0 <- sqrt(prop_pooled * (1-prop_pooled) * (1/n + 1/n))
se_ha <- sqrt((prop_baseline*(1-prop_baseline))/n +
(prop_treatment*(1-prop_treatment))/n)
critical_value <- qnorm(alpha / 2, mean = 0, sd = se_h0,
lower.tail = FALSE)
critical_value
# [1] 0.0139930354339993
We can visualize the sampling distributions for both hypotheses like so:
At the conclusion of the test, the results are:
The a priori decision framework:
The effect size (= 0.0154) is greater than the critical value (= 0.0140).
And so, the p-value < 0.05:
2*(1 - pnorm(0.01536376, mean = 0, sd = se_h0))
# [1] 0.0314007090609361
So, we reject the null hypothesis in favor of the alternate hypothesis.
The a posteriori decision framework:
The p-value > 0.05:
prop.test(x=c(141, 175), n=c(n,n))$p.value
# [1] 0.0540496200600176
So, we DO NOT reject the null hypothesis.
What's the correct approach?