# Designing a hypothesis test for a gamma distributed RV and a given significance level

I am stuck at the follwoing problem:

Consider the exponentially distributed RVs $$X_1, X_2, \ldots, X_9$$ with parameter $$\lambda$$. We reject $$H_0: \lambda \ge 1$$ in favor of $$H_A: \lambda < 1$$ if $$\overline{X} \ge k$$.

We want to reach the significance level $$\alpha = 0.05$$. Find $$k$$ and calculate the powerfunction at $$\lambda = 0.5$$.

Since the sum of $$n$$ exponentially distributed RVs (with parameter $$\lambda$$) is $$\Gamma_{n, \ 1/\lambda}$$ distributed the problem reduces itself to find a $$k$$ such that

$$\alpha = P_\lambda(\overline{X} \ge k) = \int_{k}^\infty \frac{1}{9}\cdot\Gamma_{9, \ 1/\lambda } \ \ d\lambda$$

if I am not mistaken. But I am haveing a hard time finding a suitable $$k$$. Could you help me ?

• It depends on your tools. R's qgamma and pgamma functions will give you $k$ and then the power. Or you could use a normal approximation – Henry Dec 5 '18 at 10:42
• I am supposed to do this by hand unfortunately – 3nondatur Dec 5 '18 at 10:58
• By parameter $\lambda$, do you mean the pdf is $\lambda e^{-\lambda x}\mathbf1_{x>0}$? – StubbornAtom Dec 5 '18 at 13:18
• @StubbornAtom $\lambda$ is likely to be the rate or mean of the exponential distribution. Given that the critical region is associated with low $\lambda$ and higher values, I think we can assume $\lambda$ is the rate – Henry Dec 5 '18 at 14:32
• In that case you can get $k$ as a fractile of $\chi^2_{18}$ distribution using a chi-square table, because with the above pdf, $X_i\stackrel{\text{ i.i.d }}\sim\text{Exp}\text{ with mean }1/\lambda\implies 2\lambda X_i\stackrel{\text{ i.i.d }}\sim\text{Exp}\text{ with mean }2\equiv\chi^2_2\implies 2\lambda\sum_{i=1}^9 X_i\sim\chi^2_{18}$. In other words, $18\lambda\overline X\sim\chi^2_{18}$. – StubbornAtom Dec 5 '18 at 17:25

Hypothesis test for exponential rate. Suppose $$n = 60,$$ so that you have a random sample $$X_1, X_2, \dots, X_{50}$$ from $$\mathsf{Exp}(\text{rate} = \lambda).$$ Then $$\bar X \sim \mathsf{Gamma}(\text{shape} = n, \text{rate} = n\lambda).$$

If you are testing $$H_0: \lambda \ge 1$$ against $$H_a:\lambda < 1,$$ then you want to reject when $$\bar X \ge c$$ where $$c$$ cuts probability $$0.05$$ from the upper tail of the null distribution $$\mathsf{Gamma}(50,50).$$ [Notice that large values of $$\bar X$$ correspond to small values of $$\lambda$$ because the exponential mean $$\mu = 1/\lambda.]$$

In R one finds $$c = 1.243421.$$

qgamma(.95, 50, 50)
[1] 0.7792947


[If you are allergic to software, then you could use the relationship between gamma and chi-squared distributions to get $$c$$ from printed tables of the chi-squared distribution.]

Example not leading to rejection. For example, suppose I have a sample x with $$\bar X = 1.008.$$

set.seed(2005)    # generate fake data with rate 1
x = rexp(50, 1)
summary(x)
Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
0.01236 0.27856 0.69518 1.00772 1.42997 6.01451


Then you do not reject $$H_0: \lambda \le 1$$ because $$1.008 < c.$$ The p-value of this test is the probability $$0.46$$ under the null distribution that a mean greater than $$1.008$$ is observed.

 1 - pgamma(1.008, 50, 50)
[1] 0.4587632


Power of the test. Suppose that in fact $$\lambda = 1/2.$$ Then the power of this test is the probability $$0.9989$$ of rejecting (getting $$X \ge 1.2434)$$ under the alternative distribution $$\mathsf{Gamma}(n, n/2).$$

Intuitively, with $$n = 50$$ observations, it is not difficult to tell the difference between an exponential rate of $$\lambda = 1$$ and an exponential rate of $$\lambda = 1/2.$$ (In the figure below, the two density curves have little area in common.)

1 - pgamma(1.2434, 50, 50/2)
[1] 0.9989138


Example leading to rejection As an example, suppose we have a sample y with $$\bar Y = 1.573.$$ Then we reject $$H_0: \lambda \ge 1$$ in favor of the alternative $$H_0: \lambda < 1.$$ because $$\bar Y = 1.573 > 1.2434.$$

set.seed)2018)    # generate fake data with rate 1/2
y = rexp(50, 1/2)
summary(y)
Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
0.01971 0.47256 1.01072 1.57307 2.22232 8.82067


The p-value for the Y-sample is very small (much below 5%).

1 - pgamma(1.573, 50, 50)
[1] 0.0002244243


[It is difficult to use printed distribution tables to find p-values.]

In the figure below, the p-value is the very small area under the grey null curve to the right of the vertical dotted line (at the observed value $$\bar Y).$$ The power of the test is the large area under the heavy black alternative curve to the right of the vertical red line (at the critical value).