Assume I have a hypothesis
$$H_0: \mu \leq 0$$ $$H_1: \mu > 0$$
which corresponds to R's alternativ "greater" and which I would like to check with a confidence level of $95\%$ ($\alpha = 0.05$). I thought the confidence interval (CI) must be of the form $\left(- \infty, a\right]$, which is wrong. Is there an intuitive argument for the opposite? Long form:
Lets assume we have $n=10$ measuremts with $\bar{x} = -9.603$ and $s_x = 2.342$ as in the R example below. For a two-sided test (without any bias) it is clear that the CI can be calculate to be $$\left[\bar{x}-c\cdot\frac{s_x}{\sqrt{10}}, \bar{x}-c\cdot\frac{s_x}{\sqrt{10}}\right] = \left[-11.28, -7.93\right]$$
using the t-distributiuon $F_9(c) = 1 - \frac{\alpha}{2}$.
But in my case I want to consider a one-sided test and I thought about the two options (here $F_9(c) = 1 - \alpha$)
- $\left(- \infty, \bar{x}-c\cdot\frac{s_x}{\sqrt{10}}\right]$
- $\left[\bar{x}-c\cdot\frac{s_x}{\sqrt{10}}, +\infty\right)$
At first, my intuition for $H_0: \bar{x} \leq 0$ told me that the first option
should be correct: "$-\infty$ is less 0". But when looking at the hypothesis test, I realized, I was wrong.
Our test statistics is $t = \frac{\bar{x} - 0}{s_x/\sqrt{n}} = -12.968$ and our cut off value is $c = F^{-1}(1 - \alpha) = 1.833$ resulting in a p-value of $1 - F_9(t) \approx 1$. Thus, we accept the null-hypothesis, because $t < c$ or $p > \alpha$ (as expected from the values!).
If we look at the two intervals, it is clear (the result must be the same!) that the second option is correct. whereas the first is wrong:
- $0 \notin \left(-\infty, -8.25\right]$
- $0 \in \left[-10.96, +\infty\right)$
Some references:
(1),
(2) ,
(3) and
(4) (Null hypothesis for directional tests),
Working example in R:
set.seed(1)
conf_level <- 0.95
x <- rnorm(10, -10, 3)
xm <- mean(x)
sx <- sd(x)
print(paste0("Mean = ", xm))
print(paste0("Standard deviation = ", sx))
mu0 <- 0
# H_0: mean(x) < 0 (which is true)
print(t.test(x, mu = 0,alternative = "greater", conf.level = conf_level))
n <- length(x)
t <- (xm - mu0)/(sx/sqrt(n)) # tests statistics
print(paste0("t = ", t))
df <- n - 1
print(paste0("df = ", df))
alpha <- 1 - conf_level # probability type I error
c_val <- qt(1 - alpha, df = df)
p_value <- 1 - pt(t, df)
print(paste0("p_value = ", p_value))
# confidence interval
cint <- qt(1 - alpha, df = df) * sqrt(sx^2/n)
cint <- xm + c(-Inf, cint)
print(paste0("CI1 = (", paste(cint, collapse = ", "), "]"))
cint <- qt(1 - alpha, df = df) * sqrt(sx^2/n)
cint <- xm + c(-cint, Inf)
print(paste0("CI2 = [", paste0(cint, collapse = ", "), ")"))