Inference 6 of 8
On this page

Inference

6.5 Hypothesis Tests

Chapter 5 of 7 80 min read

In this module, we present a detailed description of hypothesis testing and its applications. Hypothesis tests are scientific methods for making data-based decisions.

6.5.1 Introduction

In this chapter, we will discuss the fundamental ideas about hypothesis testing. When a certain statement is made about a population, more specifically about a parameter of that population, it is natural to want to know whether or not the experimental results from a sample contradict that statement. To do this, we do a hypothesis test. In this section we will study the basic procedure for testing hypotheses about a given parameter in a population.

Let’s assume a situation in which a manufacturer wants to know whether a certain type of bar produced by his factory meets the requirement of having an average length of 70 cm. In fact, what the manufacturer is doing is raising hypotheses about a characteristic (parameter), in this case the average $\mu$ (average length), its production (population) of bars. Eventually he could make conjectures about the distribution of the random variable that represents the length of the bar, or he could even be questioning the proportion of defective ones, etc. These conjectures or assumptions are called statistical hypotheses. In a generic way, we can state: statistical hypothesis is a statement or conjecture about a parameter, or parameters; it can also refer to the type or nature of the population.

A statistical hypothesis, such as the one formulated above regarding the average length of the bars, is called the Null Hypothesis and will be denoted by $H_0$. The term “Null Hypothesis” is used to see whether any initially established hypothesis can be rejected or not. The idea is to establish a common null hypothesis even in non-statistical reasoning. This is exactly what is done in criminal cases, where an accused (defendant) is said to be innocent until proven guilty. The presupposition of innocence is a null hypothesis.

Let’s suppose, for example, that we want to show that one manufacturing method is as efficient as another. To do this, we could formulate the hypothesis that the two methods are equally efficient and look for evidence (in the data) against or in favor of this hypothesis.

The hypothesis that we use as an alternative to the null hypothesis, that is, the hypothesis that we accept when the null hypothesis is rejected, is called the Alternative Hypothesis and will be denoted by $H_{1}$. Thus, considering the defendant’s example, we formulate the hypotheses:

$$\begin{cases}H_0: \ \hbox{O réu é inocente} \cr H_1: \ \hbox{O réu é culpado}\end{cases}$$

Note: Some authors denote $H_{1}$ by $H_{A}$.

Now let’s go back to the introductory example of the bar maker. The manufacturer is interested in deciding whether the bars have an average of 70 cm or different from 70 cm. In this case, the hypotheses would be:

$$\begin{cases}H_0: \mu=70 \cr H_1: \mu\neq 70\end{cases}$$

Still regarding this example, we could have hypotheses like:

$$(1)\begin{cases} {l}H_0: \mu=70 \cr H_1: \mu \ > \ 70\end{cases} \quad (2)\begin{cases}H_0: \mu=70 \cr H_1: \mu \ < \ 70\end{cases} \quad (3)\begin{cases}H_0: \mu=70 \cr H_1: \mu\neq 70\end{cases} \quad (4)\begin{cases}H_0: \mu=70 \cr H_1: \mu=75\end{cases}$$

In all situations the null hypothesis $H_0$ is of the “simple” type, while $H_1$ is of the “composite” type in (1), (2), (3), and of the “simple” type in (4). Cases like situations (1) and (2) are called one-sided tests. Let us now consider an example to illustrate situation (1).

Example 5.1.1

A production manager is studying the possibility of purchasing a new machine for stamping metal parts. Be $\mu_0$ the average number of parts stamped per hour by the old machine and $\mu$ the average of the new machine. The manager does not want to buy the new machine unless it is more productive than the old machine. Let’s find the hypotheses.

The manager should use the null hypothesis $\mu = \mu_0$ and the alternative hypothesis $\mu \ > \ \mu_0$. That is,

$$\begin{cases}H_0: \mu=\mu_0 \cr H_1: \mu \ > \ \mu_0\end{cases}$$

Thus, the manager should choose to buy the new machine only if the null hypothesis is rejected.

Decision rule

The decision rule allows us to distinguish between the two hypotheses. This is defined based on the maximum likelihood estimator of the parameter and is always based on the hypothesis $H_1$.

Rejection Region

In Example 5.1.1, we take the estimator $\overline{X}$ for the parameter of interest $\mu$ to determine the decision rule, which is defined by: we reject $H_0$ if $\overline{X} \ > \ X_C$, in which $X_C$ is the critical value for the sample mean. If the sample mean is greater than the critical value $X_C$, we have evidence to assume that the population mean is greater than $\mu_0$. Thus, in the case of Example 5.1.1 we have evidence to assume that the new machine has a higher average production than the old machine. The region $R_C= \lbrace\overline{X} \ >\ X_C\rbrace$ which leads us to reject the hypothesis $H_0$ is the rejection region (or critical region).

Figura6.5.1.svg

Figure 6.5.1: Representation of the unilateral critical region

For each type of hypothesis, we determine an appropriate rejection region, always in accordance with the hypothesis $H_1$. For example, to test the hypotheses

$$\begin{cases}H_0: \mu=\mu_0 \cr H_1: \mu\neq\mu_0,\end{cases}$$

we take it as the critical region $R_C=\lbrace\overline{X} \ > \ X_{C_2}\quad {ou}\quad \overline{X} \ < \ X_{C_1}\rbrace$. The values $X_{C_1}$ and $X_{C_2}$ are the critical values for the test.

Figura6.5.2.svg

Figure 6.5.2: Representation of the bilateral critical region

Regardless of the critical values used to determine the critical region, the decisions we make are subject to errors. Through discussion of these errors, we will define a method for finding appropriate critical values.

6.5.1.1 Errors made in hypothesis testing

There are two types of errors that we can make when carrying out a hypothesis test:

  1. Reject the hypothesis $H_0$, when it is true.

  2. Do not reject the hypothesis $H_0$, when it is false.

Table 6.5.1 below summarizes the above situations.

Accept H0 Reject H0
true H0 Correct decision Type I error
false H0 Type II error Correct decision

Table 6.5.1: Error types

If the hypothesis $H_0$ is true and not rejected or false and rejected, the decision will be correct. However, if the hypothesis $H_0$ is rejected being true, or if it is not rejected being false, the decision will be wrong. The first of these errors is called Type I Error and the probability of making it is denoted by the Greek letter $\alpha$ (alpha); the second is called Type II Error and the probability of committing it is denoted by the Greek letter $\beta$ (beta). So we have,

$$\alpha=\mathbb{P}(\hbox{Erro do tipo I})=P(\hbox{rejeitar} \ H_0 \ | \ H_0 \ \hbox{verdadeira});$$

$$\beta=\mathbb{P}(\hbox{Erro do tipo II})=P(\hbox{aceitar} \ H_0 \ | \ H_0 \ \hbox{falsa}).$$

Consider a one-sided test given by the hypotheses:

$$\begin{cases}H_0: \mu=\mu_0 \cr H_1: \mu \ < \ \mu_0\end{cases}$$

In this case, the rejection region is determined by $\lbrace\overline{X} \ < \ X_C\rbrace$, and the interpretation of errors can be seen as:

$$\alpha=\mathbb{P}(\overline{X} \ < \ X_C \ | \ \mu=\mu_0);$$

$$\beta=\mathbb{P}(\overline{X} \ > \ X_C \ | \ \mu \ < \ \mu_0).$$

The ideal situation is one in which both probabilities, $\alpha$ and $\beta$, are close to zero. However, it is easy to see that as we decrease $\alpha$, $\beta$ increases. The following figure shows this relationship.

Figura6.5.3.svg

Figure 6.5.3: Representation of errors

For a hypothesis test of the type above, where we are interested in testing the mean of a population, we use the expression

$$Z=\frac{\overline{X}-\mu_0}{\cfrac{\sigma}{\sqrt{n}}},$$

which is the hypothesis testing statistic. From the Central Limit Theorem, we know that as long as we have a large enough sample size, this statistic has a standard normal distribution, i.e.

$$Z\sim N(0,1).$$

From the values of $Z$ and from the specification of the error committed, we can define the critical region of the test.

Let’s consider that the most important error to be avoided is the Type I Error. The probability of a Type I error occurring $(\alpha)$ is called the significance level of the test. The complement of the significance level $(1 - \alpha)$ is called the confidence level. Assuming that the significance level $\alpha$ is known, we are able to determine the critical value(s). If we consider the two-sided test

$$\begin{cases}H_0:\mu=\mu_0 \cr H_1: \mu\neq\mu_0\end{cases},$$

The following figure represents the rejection region for a fixed value of $\alpha$.

Figura6.5.4.svg

Figure 6.5.4: Representation of bilateral rejection region

If we consider the right-sided test

$$\begin{cases}H_0:\mu=\mu_0 \cr H_1: \mu \ > \ \mu_0\end{cases},$$

The critical region is represented as shown in the figure below.

Figura6.5.5.svg

Figure 6.5.5: Representation of unilateral rejection region on the right

And if we consider the left-sided test

$$\begin{cases}H_0:\mu=\mu_0 \cr H_1: \mu \ < \ \mu_0\end{cases},$$

the critical region is represented as shown in the figure below.

Figura6.5.6.svg

Figure 6.5.6: Representation of the unilateral rejection region on the left

The values $-Z_{\alpha}$ and $Z_{\alpha}$ in the last two figures are such that the areas to the left and right, respectively, under the standard Normal curve, are worth $\alpha$. Now the values $-Z_{\alpha/2}$ and $Z_{\alpha/2}$, in the first figure, are such that the areas to the left and right, respectively, under the standard Normal curve, are worth $\frac{\alpha}{2}$.

As stated initially, the objective of hypothesis testing is to determine, through statistics, whether the null hypothesis is acceptable or not. This decision is made considering the rejection region or critical region (RC). If the observed value of the statistic belongs to the rejection region, we reject $H_0$; otherwise, we do not reject $H_0$. Similarly, we define the acceptance region (complementary to the rejection region): if the observed value belongs to the acceptance region, we do not reject $H_0$; if it doesn’t belong, we reject it.

According to the Normal Distribution Table, if the significance level is $0,05$, the critical values are $-1,645$ or $1,645$ for unilateral and $-1,96$ and $1,96$ for the bilateral alternative; if the significance level is $0,01$, the critical values are $-2,33$ or $2,33$ for unilateral and $-2,575$ and $2,575$ for the bilateral alternative. Table 6.5.2 below presents some criteria for hypothesis testing.

Alternative Hypothesis Reject $H_0$ if Accept $H_0$ if
$\mu \ < \ \mu_0$ $Z \ < \ -Z_{\alpha}$ $ Z\geq -Z_{\alpha} $
$\mu \ > \ \mu_0$ $Z \ > \ Z_{\alpha}$ $ Z\leq Z_{\alpha} $
$ \mu\neq\mu_0 $ $Z \ < \ -Z_{\alpha/2}$ or $Z \ > \ Z_{\alpha/2}$ $ -Z_{\alpha/2}\leq Z\leq Z_{\alpha/2} $

Table 6.5.2: Regions of rejection in relation to hypotheses

Example 5.1.1.1

A quality supervisor wants to test, based on a random sample size $n = 35$ and to a significance level $\alpha = 0,05$, if the average depth of a hole in a given part is $72,4$ mm. What can we say if he got $\overline{x} = 73,2$ mm and it is known, from previous information, that $\sigma = 2,1$ mm?

1. First let’s establish the hypotheses:

$$\begin{cases}H_0: \mu=72,4 \cr H_1:\mu\neq 72,4\end{cases}$$

2. How $\alpha= 0,05$, we have to $Z_{\alpha/2}=Z_{0,025}=1,96$.

3. Criteria: reject $H_0$ if $Z_{\text{obs}}\ < \ -1,96$ or if $Z_{\text{obs}} \ > \ 1,96$ in which

$$Z_{\text{obs}}=\frac{\overline{x}-\mu_0}{\frac{\sigma}{\sqrt{n}}}$$

4. Replacing $\mu_0 = 72,4$, $\sigma = 2,1$, $n = 35$, $\overline{x} = 73,2$ In the above equation, we get

$$Z_{\text{obs}}=\frac{73,2-72,4}{\frac{2,1}{\sqrt{35}}}=2,25$$

5. Conclusion: How $Z_{\text{obs}}= 2,25 \ > \ 1,96$, the null hypothesis must be rejected. In other words, we cannot assume that the population mean $\mu$ be equal to $72,4$, that is, the difference between $73,2$ and $72,4$ is significant. See Figure 6.5.7 below

Figura6.5.7.svg

Figure 6.5.7: Rejection region representation

6.5.1.2 Calculation and interpretation of the p-value

P-value

The p-value, also called the descriptive level of the test, is the probability that the test statistic (as a random variable) has an extreme value in relation to the observed value (statistic) when the hypothesis $H_0$ is true.

To exemplify the definition of p-value, consider a hypothesis test for the mean in which the value of the statistic is given by $Z_{\text{obs}}$, see example 5.1.1.1. The following figures represent, respectively, the p-value in cases where we have a two-sided hypothesis test with rejection of the null hypothesis and without rejection of the null hypothesis.

Figura6.5.8.svg

Figure 6.5.8: Two-sided hypothesis test for mean, null hypothesis rejection case and non-rejection case

Next, we have the figure of a one-sided hypothesis test for mean.

Figura6.5.9.svg

Figure 6.5.9: Right-sided hypothesis test for mean, null hypothesis rejection case and non-rejection case

Note that if the p-value is lower than the proposed significance level ($\alpha$), then $Z_{\text{obs}}$ is in the critical region and therefore, we reject the null hypothesis $H_0$ . On the other hand, if the p-value is greater than the significance level, we do not reject the null hypothesis. Furthermore, the smaller the p-value, the further “distant” we are from the null hypothesis $H_0$. Therefore, the p-value has more information about the evidence against $H_0$ and thus the experimenter has more information to decide on $H_0$ with the appropriate level of significance.

We can also interpret the p-value as the lowest value of the significance level for which we reject $H_0$. In this way, if the significance level $(\alpha)$ proposed for the test is smaller than the p-value, we do not reject the hypothesis $H_0$.

In many situations, the region of rejection of a hypothesis test with a significance level $\alpha$ presents the following form:

We reject $H_0$ if and only if $W(X) \geq c_{\alpha}$,

in which $W(X)$ is the appropriate test statistic for the problem, and the constant $c_\alpha$ is chosen so that the test has a level of significance $\alpha$. In this case, the p-value for the sample point $x$ is defined mathematically as

$$p(x)=\sup_{\theta \in \Theta_{0}}P_{\theta}[W(X) \geq W(x)],$$

in which $\theta$ is a parameter belonging to the parameter space $\Theta$ under the null hypothesis $(H_0)$.

Returning to Example 5.1.1.1, let’s calculate the p-value of the means test. During this module we calculate the p-value for all classic statistical tests.

In this case, as we have a two-sided test, it follows that the p-value is given by

$$\text{P-valor}=\mathbb{P}[Z \ > \ |Z_{\text{obs}}|]+\mathbb{P}[Z \ < \ -|Z_{\text{obs}}|]=$$ $$= \mathbb{P}[Z \ > \ 2,25]+\mathbb{P}[ Z \ < -2.25]=0,0122+0,0122=0,0244.$$

Figura6.5.10.svg

Figure 6.5.10: Representation of the two-sided hypothesis test in Example 5.1.1.1

Therefore, we can conclude that for any significance level greater than 0.0244, we have evidence to reject the null hypothesis.

p-value analysis

Let us consider a hypothesis test in which $R_{\alpha}$ is the rejection region with significance level $\alpha$. Suppose that, for different values of $\alpha$, these regions can be fitted in the sense that

$$R_{\alpha}\subset R_{\alpha^{,}}, \quad \hbox{para qualquer} \quad \alpha < \alpha^{,}. \tag{5.1.2.1}$$

Under this situation, in addition to being able to know whether the hypothesis is rejected or not, we are also able to determine the p-value, which is defined here by

$$p=p(X)=\inf \lbrace\alpha : X \in R_{\alpha}\rbrace,$$

in which $X$ represents the sample.

The p-value gives us an idea of ​​how much the data contradicts the null hypothesis. Furthermore, it allows different experimenters to use their respective significance levels to evaluate the results of hypothesis testing.

Example 5.1.2.1

Consider a sample of size one from a population $X$ with distribution $N(\mu, \sigma^{2})$, with $\sigma^{2}$ known. Let us consider under $H_{0}$, $\mu=0$ and under $H_{1}$, $\mu=\mu_{1}$, for some $\mu_{1}>0$. Be $\Phi$ the cumulative distribution function of the standard normal and $z_{1-\alpha}$ the quantile $1-\alpha$ of the standard normal distribution. Then, the rejection region can be denoted as

$$R_{\alpha}=\lbrace X:X >\sigma z_{1-\alpha} \rbrace = \lbrace X: \Phi\left(\frac{X}{\sigma}\right)> 1-\alpha\rbrace= \lbrace X: 1- \Phi\left(\frac{X}{\sigma}\right)<\alpha\rbrace.$$

Thus, for an observed value of $X$ given, the least over all $\alpha$ where the last inequality holds is $$p = 1- \Phi(\frac{X}{\sigma}).$$

Alternatively, we can write that the p-value is $\mathbb{P}_0[X \geq x ]$, in which $x$ is the observed value of $X$. We also note that under the null hypothesis, $\mu=0$, the distribution of $p$ is given in the following way

$$\mathbb{P}_0 [p\leq u ]= \mathbb{P}_0 \left[1-\Phi\left(\frac{X}{\sigma}\right)\leq u\right]=\mathbb{P}_0 \left[\Phi\left(\frac{X}{\sigma}\right)\geq 1-u\right]=u,$$

because $\Phi(X/\sigma)$ is evenly distributed over $(0,1)$, therefore $p$ is evenly distributed in $(0,1)$. This result follows from the probability integral transformation, which guarantees that:

Se $X$ has a continuous distribution function $F$, then $F(X)$ is evenly distributed over $(0,1)$.

The following Lemma brings a general property of the p-value.

Motto

Let’s suppose that $X$ has probability distribution $\mathbb{P}_\theta$, for some $\theta \in \Theta$. Let us consider $\theta \in \Theta_0$, in which $\Theta_0$ represents the parameter space under the null hypothesis $H_0$. We further assume that the rejection regions satisfy $(5.1.2.1).$

i) Se

$$\sup_{\theta\in \Theta_{0}}\mathbb{P}_{\theta}[X \in R_{\alpha}]\leq \alpha\quad \hbox{para todo}\quad 0<\alpha<1,\tag{5.1.2.2}$$

then the distribution of $p$ about $\theta\in\Theta_0$ satisfies

$$\mathbb{P}_{\theta}[p\leq u]\leq u \quad \hbox{para todo}\quad 0\leq u\leq 1.$$

Proof

Se $\theta\in \Theta_0$, by the definition of the p-value, $p=p(X)=\inf\lbrace\alpha : X \in R_{\alpha}\rbrace$ and, we have to, for all $v> u$, $[p\leq u]\subset[X\in R_{v}]$, which implies $\mathbb{P}_{\theta}[p\leq u]\leq \mathbb{P}_{\theta}[X \in R_{v}].$ So, writing

$$\lim_{v\rightarrow u^{+}}\mathbb{P}_{\theta}[p\leq u]\leq \lim_{v\rightarrow u^{+}}\mathbb{P}_{\theta}[X \in R_{v}],$$

how $(5.1.2.2)$ is valid, it follows that $\mathbb{P}_{\theta}[p\leq u]\leq u.$

ii) If, for $\theta\in\Theta_0$,

$$\mathbb{P}_{\theta} [X \in R_α] = \alpha \quad \hbox{para todo} \quad 0 < \alpha < 1,\tag{5.1.2.3}$$

then

$$\mathbb{P}_\theta [p\leq u]=u \quad \hbox{para todo} \quad 0\leq u \leq 1,$$

i.e. $p$ is evenly distributed over $(0,1)$.

Proof

Again by the definition of the p-value, we have to $[X\in R_u]$ then $[p\leq u]$. Thus, it follows that

$$\mathbb{P}_θ [p\leq u] \quad \geq \quad \mathbb{P}_θ [X \in R_u].$$

So, for $(5.1.2.3)$ we have to $\mathbb{P}_θ [p\leq u]\geq u $. From the result obtained in (i), we conclude that $\mathbb{P}_θ [p\leq u]=u, $ i.e. $p$ has a uniform distribution in $(0,1)$.

Steps for carrying out hypothesis testing

  1. Establish hypotheses;

  2. Determine the significance level of the test (α);

  3. Determine the rejection region;

  4. Calculate the p-value

Next, we will apply the concepts discussed above to deal with several examples of hypothesis testing.

6.5.1.3 Power of the test

Be $T$ a statistical test with critical region $C$ to evaluate hypotheses regarding the parameter $\theta$. The power function of the test is the probability of rejecting $H_0$ given the value of $\theta$. In this case, we have to

$$\pi(\theta)=\mathbb{P}[\hbox{rejeitar} \ H_0|\theta]=\mathbb{P}[T\in C|\theta],$$

for every value of $\theta$.

Suppose we want to test the hypothesis $H_0:\mu=\mu_0$ against the alternative hypothesis $H_1:\mu\neq\mu_0$. Ideally, we would like to reject the hypothesis $H_0$ for every value of $\mu$ in $H_1$ with probability 1, and similarly, we would like not to reject (accept) the hypothesis $H_0$ for every value of $\mu$ in $H_0$ with probability 1 (Figure 6.5.11 below).

Figura6.5.11.svg

Figure 6.5.11: Representation of Test Power

The Power of the Test aims to know how much the hypothesis test controls a type II error, or what is the probability of rejecting the null hypothesis if it really is false. In practice, it is important to have tests with a significance level close to the nominal significance level and that the power is high, even in situations with small samples.

The power of a hypothesis test is affected by three factors:

  • Sample Size: Keeping all other parameters equal, the larger the sample size, the greater the power of the test.

  • Significance Level: The higher the significance level, the greater the power of the test. If you increase the significance level, you reduce the region of acceptance. As a result, you have a greater chance of rejecting the null hypothesis. This means that you have less chance of accepting the null hypothesis when it is false, that is, less chance of making a type II error. Then the power of the test increases.

  • The true value of the parameter to be tested: The greater the difference between the “true” value of the parameter and the value specified by the null hypothesis, the greater the power of the test.

Again, let’s consider the statistics

$$Z=\cfrac{\overline{X}-\mu_0}{\cfrac{\sigma}{\sqrt{n}}}$$

and hypothesis testing

$$\begin{cases}H_0: \mu=\mu_0 \cr H_1:\mu\neq \mu_0\end{cases}$$

Type II error is the error made when accepting the null hypothesis $H_{0}$ when this is false $H_{1}$ is true.

$$\mathbb{P}(\text{Erro do tipo II}) = \mathbb{P}(\text{aceitar} \ H_0| H_1 \text{é verdadeira}) = \beta$$

For this to be possible, assume that the null hypothesis is false and that the true value of the mean is $\mu = \mu_0+\delta$. So the test statistic is

$$Z_0=\frac{\overline{X}-\mu_0}{\sigma/\sqrt{n}}=\frac{\overline{X}-(\mu_0+\delta)}{\sigma/\sqrt{n}}+\frac{\delta}{\sigma/\sqrt{n}}.$$

Therefore, the distribution of $Z_0$ when $\mu=\mu_0+\delta$ is

$$Z_0\sim N\left(\frac{\delta}{\sigma/\sqrt{n}},1\right).$$

And, therefore, for a two-sided test, we have that the probability of type II error is the probability that $Z_0$ be between $-z_{\alpha/2}$ and $z_{\alpha/2}$ given that $H_1$ is true. This probability is calculated as follows

$$\beta=\Phi\left(z_{\alpha/2}-\frac{\delta\sqrt{n}}{\sigma}\right)-\Phi\left(-z_{\alpha/2}-\frac{\delta\sqrt{n}}{\sigma}\right)$$

where $\Phi$ is the cumulative distribution function of the standard normal distribution.

For the right- and left-sided tests, the type II error probabilities are given, respectively, by

$$\Phi\left(z_\alpha-\frac{\delta\sqrt{n}}{\sigma}\right) \quad \hbox{e} \quad 1-\Phi\left(-z_\alpha-\frac{\delta\sqrt{n}}{\sigma}\right).$$

The Power of the Test is calculated as 1 minus the probability of type II error, that is, $1-\beta$. In this case, the formulas used to calculate power are

$$\text{Poder} \ =1-\Phi\left(z_{\alpha/2}-\frac{\delta}{\sigma}\sqrt{n}\right)+\Phi\left(-z_{\alpha/2}-\frac{\delta}{\sigma}\sqrt{n}\right)$$

whether the test is two-sided. If the test is left-sided, the formula used is

$$\text{Poder} \ =\Phi\left(-z_{\alpha}-\frac{\delta}{\sigma}\sqrt{n}\right)$$

and if it is right-sided, then

$$\text{Poder} \ =1-\Phi\left(z_{\alpha}-\frac{\delta}{\sigma}\sqrt{n}\right)$$

where $\Phi$ is the cumulative distribution function of a random variable with standard normal distribution.

Consider Example 5.1.1.1 again. Suppose we want to calculate the power of the hypothesis test to detect a difference $\delta = 1$ between the null and alternative hypotheses. How $n = 35$, $\alpha = 0,05$ and $\sigma = 2,1$, we have that the probability of type II error is given by

$$\beta=\Phi\left(z_{\alpha/2}-\frac{\delta\sqrt{n}}{\sigma}\right)-\Phi\left(-z_{\alpha/2}-\frac{\delta\sqrt{n}}{\sigma}\right)=\Phi(-0,8572)-\Phi(-4,7772)=0,1957.$$

Thus, we have the power of hypothesis testing to detect a difference $\delta = 1$ between the null and alternative hypotheses is given by

$$\text{Poder} \ =1-\beta=1-0,1957=0,8043,$$

that is, the power is approximately 80.43%.

6.5.1.4 Likelihood ratio test

Be $X_1, \ldots, X_n$ an independent and equally distributed random sample from a population with probability function or probability density function $f(x|\theta)$ in which $\theta$ is the parameter or parametric vector of interest. In this case, the likelihood function is given by

$$L(\theta|\textbf{x}) = f(\textbf{x}|\theta) = \prod_{i=1}^nf(x_i|\theta).$$

Definition 5.1.4.1

The likelihood ratio test statistic for testing $H_0: \theta\in\Theta_0$ against $H_1:\theta\in\Theta_1$ is given by

$$\lambda(\textbf{x}) = \frac{\sup_{\theta\in\Theta_0}L(\theta|\textbf{x})}{\sup_{\theta\in\Theta}L(\theta|\textbf{x})}$$

in which $\Theta$ is the unrestricted parameter space and $\Theta_0$ is the parameter space restricted to the null hypothesis. The likelihood ratio test has a critical region of the form $\lbrace\textbf{x};\lambda(\textbf{x})\leq c\rbrace$ with $0\leq c\leq 1$. Denoting $\hat{\theta}$ as the maximum likelihood estimator of $\theta$ about space $\Theta$ and $\hat{\theta}_0$ the maximum likelihood estimator of $\theta$ about space $\Theta_0$, the likelihood ratio test statistic can be written as

$$\lambda(\textbf{x}) = \frac{L(\hat{\theta}_0|\textbf{x})}{L(\hat{\theta}|\textbf{x})}.$$

Example 3.1.4.1

Be $X_1,\ldots,X_n$ an independent, equally distributed random sample from the population with normal distribution $N(\theta,1)$. Consider the hypotheses $H_0:\theta = \theta_0$ versus $H_1:\theta\neq\theta_0$. Since there is only one value of $\theta$ specified by $H_0$, the hypothesis is simple and the numerator of $\lambda(\textbf{x})$ is $L(\theta_0|\textbf{x})$. Now, we know that $\hat{\theta} = \bar{X}$ is the maximum likelihood estimator of $\theta$ over unrestricted parameter space $\Theta$. Therefore, the denominator of $\lambda(\textbf{x})$ is $L(\bar{x}|\textbf{x})$ and the likelihood ratio test statistic is

$$\lambda(\textbf{x}) = \frac{L(\theta_0|\textbf{x})}{L(\bar{x}|\textbf{x})}=\frac{\exp\left[-\sum_{i=1}^n(x_i-\theta_0)^2/2\right]}{\exp\left[-\sum_{i=1}^n(x_i-\bar{x})^2/2\right]}=\exp\lbrace\left(-\sum_{i=1}^n(x_i-\theta_0)^2+\sum_{i=1}^n(x_i-\bar{x})^2\right)/2\rbrace$$

and how $\sum_{i=1}^n(x_i-\theta_0)^2 = \sum_{i=1}^n(x_i-\bar{x})^2+n(\bar{x}-\theta_0)^2$, the likelihood ratio test statistic is given by

$$\lambda(\textbf{x}) = \exp\lbrace\frac{-n(\bar{x}-\theta_0)^2}{2}\rbrace.$$

Since the critical region is given by $RC = \lbrace\textbf{x}: \lambda(\textbf{x})\leq c\rbrace$, it follows that

$$\lambda(\textbf{x})\leq c \Leftrightarrow\exp\lbrace\frac{-n(\bar{x}-\theta_0)^2}{2}\rbrace\leq c \Leftrightarrow |\bar{x}-\theta_0|\geq\sqrt{-2\log(c)/n}.$$

Therefore, the critical region is given by $RC = \lbrace\textbf{x};|\bar{x}-\theta_0|\geq\sqrt{-2\log(c)/n}\rbrace$ and, how $0\leq c\leq 1$, we have to $0\leq \sqrt{-2\log(c)/n} \ < \ \infty$. Setting the significance level $\alpha$, we can determine the value of $c$. I suppose $\alpha = 0,05$, we have to

$$\mathbb{P}\left(\textbf{x}\in RC|H_0 \ \hbox{é verdadeira}\right) = \alpha \Rightarrow\mathbb{P} \left(|\bar{X}-\theta_0|\geq\sqrt{-2\log(c)/n}\right) = 0,05$$

whence it follows that

$$\Rightarrow\mathbb{P}\left(\left| \frac{\bar{X}-\theta_0}{1/\sqrt{n}}\right|\geq \frac{\sqrt {-2\log(c)/n}}{1/\sqrt{n}}\right) = 0,05\Rightarrow\mathbb{P}\left(\sqrt{n}|\bar{X}-\theta_0|\geq 1,96\right) = 0,05$$

where we consider that $z_{\alpha/2}=1,96$ and therefore the critical region of the test is

$$RC = \lbrace\textbf{x}:\sqrt{n}|\bar{x}-\theta_0|\geq 1,96\rbrace.$$

6.5.1.5 Uniformly more powerful tests

The objective of this section is to set the significance level (type I error) $\alpha$, find a critical region $R_C$ which has the lowest probability of type II error and, therefore, greater power for hypothesis testing among all tests with a level less than or equal to $\alpha$. The following result, known as the Neyman-Pearson Lemma, considers the most powerful test of level $\alpha$ to test $H_0:\theta=\theta_0$ versus $H_1:\theta = \theta_1$.

Theorem 5.1.5.1 (Neyman-Pearson Lemma)

Suppose the hypotheses $H_0:\theta=\theta_0$ and $H_1:\theta=\theta_1$ (simple hypotheses), with a probability function or probability density function corresponding to $\theta_i$, $f(\textbf{x}|\theta_i)$, $i = 0,1$. Consider a critical region test $RC$ satisfying

$$\textbf{x}\in R_C \ \hbox{se} \ f(\textbf{x}|\theta_1) \ > \ kf(\textbf{x}|\theta_0) \ \hbox{e} \ \textbf{x}\notin R_C \ \hbox{se} \ f(\textbf{x}|\theta_1) \ < \ \ kf(\textbf{x}|\theta_0)$$

In a similar way,

$$\lambda(\textbf{x})=\frac{f(\textbf{x}|\theta_1)}{f(\textbf{x}|\theta_0)}> k$$

for some $k\geq 0$ and $\alpha = \mathbb{P}(\textbf{X}\in \ R_C|H_0 \ \hbox{é verdadeira})$. So the test is the most powerful.

Note 5.1.5.1

Se $f(\textbf{x}|\theta_1) = kf(\textbf{x}|\theta_0)$ any decision can be made. Note that the test with critical region

$$R_C = \lbrace\textbf{x}:f(\textbf{x}|\theta_1) \ > \ kf(\textbf{x}|\theta_0)\rbrace=\lbrace \textbf{x}: \lambda(\textbf{x})=\frac{f(\textbf{x}|\theta_1)}{f(\textbf{x}|\theta_0)} \ > \ k\rbrace$$

is the likelihood ratio test. Putting the likelihood function under $H_0$, $L(\theta_0|\textbf{x})$, and under $H_1$, $L(\theta_1|\textbf{x})$, the most powerful test rejects $H_0$ when $L(\theta_1|\textbf{x})|L(\theta_0|\textbf{x})\geq k$.

Example 5.1.5.1

Be $X_1,\ldots,X_n$ an independent and equally distributed random sample of size $n$ of the random variable $X\sim N(\mu,\sigma^2)$ with $\mu$ known. Let’s find the most powerful test to test $H_0:\sigma^2=\sigma_0^2$ versus $H_1:\sigma^2 = \sigma_1^2$ ($\sigma_1^2 \ > \ \sigma_0^2$)

By the Neyman-Pearson Lemma, we have that the most powerful test rejects $H_0$ when $\frac{L_1(\textbf{x})}{L_0(\textbf{x})} \ > \ 0$. So:

$$\frac{L_1(\textbf{x})}{L_0(\textbf{x})}=\frac{(1/\sqrt{2\pi\sigma_1^2})\exp[-\sum_{i=1}^n(x_i-\mu)^2/2\sigma_1^2]}{(1/\sqrt{2\pi\sigma_0^2})\exp[-\sum_{i=1}^n(x_i-\mu)^2/2\sigma_0^2]}$$

which is equivalent to

$$\sum_{i=1}^n(x_i-\mu)^2 \ > \ \frac{\log\left(k\left(\frac{\sigma_1}{\sigma_0}\right)^n\right)}{\frac{1}{2}\left(\frac{1}{\sigma_0^2}+\frac{1}{\sigma_1^2}\right)}=c.$$

Therefore, the critical region of the most powerful test is given by

$$R_C^\ast = \lbrace\textbf{x}:\sum_{i=1}^n(x_i-\mu)^2 \ > \ c\rbrace.$$

Now, fixing $\alpha$, we determine the value of $c$ by solving the equation

$$\alpha = \mathbb{P}\left(\textbf{X}\in \ R_C^\ast |H_0 \ \hbox{é verdadeira}\right) \Rightarrow \alpha = \mathbb{P}\left(\sum_{i=1}^n(X_i-\mu)^2 \ > \ c\right) = \mathbb{P}\left(\sum_{i=1}^n\frac{(X_i-\mu)^2}{\sigma_0^2} \ > \ \frac{c}{\sigma_0^2}\right).$$

But, under $H_0$, we have to

$$\frac{X_i-\mu}{\sigma_0}\sim N(0,1) \Rightarrow \frac{(X_i-\mu)^2}{\sigma_0^2}\sim\chi_1^2\Rightarrow \sum_{i=1}^n\frac{(X_i-\mu)^2}{\sigma_0^2}\sim\chi^2_n$$

and then, fixing $n$, $\alpha$ and $\sigma_0^2$ we can get the value $c$ from a chi-square distribution with $n$ degrees of freedom.

Definition 5.1.5.1

A test with critical region $RC^\ast$ is said to be uniformly more powerful (UMP) to test $H_0:\theta=\theta_0$ versus $H_1:\theta\in\Theta_1$, if he is more powerful level $\alpha$ to test $H_0:\theta=\theta_0$ versus $H_1:\theta=\theta_1$ for any $\theta_1\in\Theta_1$.

Therefore, we have already verified the following situations:

1) Most Powerful (MP) Tests $H_0$ simple versus $H_1$ simple.

2) Uniformly Most Powerful (UMP) Tests $H_0$ simple versus $H_1$ composite.

Now consider the hypotheses $H_0:\theta\in\Theta_0$ versus $H_1:\theta\in\Theta_1$. The following result establishes conditions for having the uniformly most powerful test to test these hypotheses.

Theorem 5.1.5.2

Se $X_1,\ldots,X_n$ follows an exponential family distribution, then the uniformly most powerful test to test $H_0:\theta=\theta_0$ versus $H_1:\theta \ > \ \theta_0$ It is also more powerful for testing $H_0:\theta\leq\theta_0$ versus $H_1:\theta \ > \ \theta_0$. We also have the most uniformly powerful test to test $H_0:\theta=\theta_0$ versus $H_1:\theta \ < \ \theta_0$ is uniformly more powerful to test $H_0:\theta\geq \theta_0$ versus $H_1:\theta \ < \ \theta_0$.

Another important property of uniformly most powerful tests is that if a family of distributions belongs to the exponential family, i.e. $$f(\textbf{x}|\theta) = h(\textbf{x})\exp \lbrace T(\textbf{x})c(\theta)+d(\theta)\rbrace$$

then $T(\textbf{X})$ is a sufficient statistic. If the function $c(\theta)$ is strictly increasing in $\theta$, then the level UMP test $\alpha$ has a critical region given by $RC = \lbrace\textbf{x}:T(\textbf{x}\geq c)\rbrace$ to test hypotheses $H_0:\theta\leq\theta_0$ versus $H_1:\theta \ > \ \theta_0$. If the hypotheses are reversed, $H_0:\theta\geq\theta_0$ versus $H_1:\theta \ < \ \theta_0$ then the uniformly more powerful test with level $\alpha$ has $R_C = \lbrace\textbf{x}: T(\textbf{x}) \ < \ c\rbrace$.

6.5.2 Test for mean (t test)

Consider a population from which we draw a sample $X_1,X_2,\ldots,X_n$. We are interested in making inferences about the population mean $\mu$.

Figura6.2.svg

Figure 6.5.12: Statistical Inference Flowchart

If we do not know the value of the population standard deviation $\sigma$ and the sample is small, $n < 30$, we must replace the expression

$$Z=\frac{\overline{X}-\mu_0}{\frac{\sigma}{\sqrt{n}}}$$

by the expression

$$T=\frac{\overline{X}-\mu_0}{\frac{s}{\sqrt{n}}}$$

where $T$ has a Student t distribution with $n-1$ degrees of freedom. To facilitate the execution of the test, we can follow the steps:

1. Establish the hypotheses:

We fix $H_0:\mu=\mu_0$. Depending on the information that provides the problem we are studying, the alternative hypothesis can take one of the three forms below:

  • $H_1: \mu\neq\mu_0 \quad \text{(teste bilateral)}$;
  • $H_1: \mu \ > \ \mu_0 \quad \text{(teste unilateral à direita)}$;
  • $H_1: \mu \ < \ \mu_0 \quad \text{(teste unilateral à esquerda)}$.

2. Set the significance level $\alpha$.

3. Determine the critical region.

  • If the test is two-sided, we determine the critical points $ -t_{\alpha/2} $ and $ t_{\alpha/2} $ such that $ \mathbb{P}[T \ > \ t_{\alpha/2}]=\mathbb{P}[T \ < -t_{\alpha/2}]=\alpha/2 $ from the Student t distribution with $ n-1 $ degrees of freedom.

Figura6.5.13.svg

Figure 6.5.13: Two-sided test based on Student’s t distribution

  • If the test is one-sided, we determine the critical point $ t_{\alpha} $ such that $ \mathbb{P}[T \ > \ t_{\alpha}]=\alpha $.

Figura6.5.14.svg

Figure 6.5.14: Right-sided test based on Student’s t distribution

  • If the test is left-sided, we determine the point $ -t_{\alpha} $ such that $ \mathbb{P}[T \ < \ -t_{\alpha}]=\alpha $.

Figura6.5.15.svg

Figure 6.5.15: Left-tailed test based on Student’s t distribution

4. Calculate, under the null hypothesis, the value:

$$T_{\text{obs}}=\frac{\overline{x}-\mu_0}{\frac{s}{\sqrt{n}}}$$

where

  • $ \overline{x} $: sample mean value.
  • $ \mu_0 $: population mean value under the null hypothesis.
  • $ s $: value of the sample standard deviation.
  • $ n $: sample size.

5. Criteria:

  • Two-sided test: if $ T_{\text{obs}} \ > \ t_{\alpha/2} $ or if $ T_{\text{obs}} \ < \ -t_{-\alpha/2} $, we reject $ H_0 $. Otherwise, we do not reject $ H_0 $.
  • Right-sided test: if $ T_{\text{obs}} \ > t_{\alpha} $, we reject $ H_0 $. Otherwise, we do not reject $ H_0 $.
  • Left-sided test: if $ T_{\text{obs}} \ < \ -t_{\alpha} $, we reject $ H_0 $. Otherwise, we do not reject $ H_0 $.

6. The p-value in the two-sided test is given by

$$\text{p-valor} = \mathbb{P}[|t| \ > \ |T_{\text{obs}}||H_0]=2\mathbb{P}[T \ > \ |T_{\text{obs}}| | H_0].$$

If the test is right-sided, the p-value is given by

$$\text{p-valor} = \mathbb{P}[T \ > \ T_{\text{obs}}|H_0]$$

and, if the test is left-sided, the p-value is given by

$$\text{p-valor} = \mathbb{P}[T\ < \ T_{\text{obs}}|H_0].$$

7. As we saw in Section 4.1.2, the confidence interval is given by

$$IC(\mu,1-\alpha)=\left(\overline{X}-t_{\alpha/2}\frac{s}{\sqrt{n}};\overline{X}+t_{\alpha/2}\frac{s}{\sqrt{n}}\right)$$

whether the test is two-sided. If the test is right-sided, then the confidence interval for the parameter $\mu$ is given by

$$IC(\mu,1-\alpha)=\left(\overline{X}-t_{\alpha}\frac{s}{\sqrt{n}};\infty\right)$$

and, if the test is left-tailed, then the confidence interval for the parameter $\mu$ is given by

$$IC(\mu,1-\alpha)=\left(-\infty;\overline{X}+t_{\alpha}\frac{s}{\sqrt{n}}\right).$$

8. Type II error is committed when accepting $H_0$ when it is false ($H_1$ is true).

$$\mathbb{P}[\hbox{erro do tipo II}]=\mathbb{P}[\hbox{Aceitar} \ H_0 | H_1 \ \hbox{é verdadeira}]=\beta.$$

To do this, assume that the null hypothesis is false and that the true value of the mean is $\mu = \mu_0+\delta$. So the test statistic is

$$T_0=\frac{\overline{X}-\mu_0}{S/\sqrt{n}}=\frac{\overline{X}-(\mu_0+\delta)+\delta}{s/\sqrt{n}}.$$

which can be written in the form

$$T_0=\frac{\overline{X}-\mu_0}{s/\sqrt{n}}=\frac{\frac{\overline{X}-(\mu_0+\delta)+\delta}{\sigma/\sqrt{n}}}{\sqrt{\frac{(n-1)s^2}{\sigma^2(n-1)}}}.$$

How

$$\frac{\overline{X}-(\mu_0+\delta)+\delta)}{\sigma/\sqrt{n}}\sim N\left(\frac{\delta}{\sigma/\sqrt{n}},1\right) \quad \hbox{e} \quad \frac{(n-1)s^2}{\sigma^2}\sim\chi_{n-1}^2$$

it follows that $T_0$ has non-central Student’s t-distribution with non-centrality parameter $\frac{\delta\sqrt{n}}{\sigma}$ and $n - 1$ degrees of freedom. So, for the two-sided test, the probability of type II error is the probability of $T_0$ be between $-t_{\alpha/2}$ and $t_{\alpha/2}$, that is

$$\beta=\Psi(t_{\alpha/2})-\Psi(-t_{\alpha/2})$$

and, for the right- and left-sided cases, the type II error probabilities are given, respectively, by

$$\Psi(t_{\alpha}) \quad \hbox{e} \quad 1-\Psi(-t_{\alpha})$$

where $\Psi$ is the cumulative distribution function of the non-central random variable t with non-centrality parameter $\frac{\delta\sqrt{n}}{\sigma}$ and $n-1$ degrees of freedom.

9. The power of the test is calculated as 1 minus the probability of type II error, i.e. $1-\beta$.

We can also use the Action software to calculate the power (given the sample size) or the sample size necessary to detect a given difference, with a previously specified power. In Action, we have sample size as parameters ($n$), the difference between the null and alternative hypotheses ($\delta$), the value of power ($P$), the significance level of the test ($\alpha$) and the standard deviation ($\sigma$). To calculate power, we provide the values of $n,\delta,\alpha$ and $\sigma$. The formulas used are

$$\text{Poder} \ =1-\Psi(t_{\alpha/2})+\Psi(-t_{\alpha/2})$$

whether the test is two-sided. If the test is left-tailed, then

$$\text{Poder} \ =\Psi(-t_{\alpha})$$

and if the test is right-sided, then $$\text{Poder} \ = 1-\Psi(t_{\alpha})$$

where $\Psi$ is the cumulative distribution function of the continuous random variable with non-central Student’s t-distribution with $n - 1$ degrees of freedom and non-centrality parameter $\frac{\delta}{\sigma}\sqrt{n}$.

To calculate the sample size necessary for the test to detect a pre-determined difference between the null and alternative hypotheses, with a certain power, we simply enter the difference values $\delta$, the standard deviation $\sigma$, the level of significance $\alpha$ and the power $P$. With this, Action provides us with the sample size value $n$. The formulas used for each test are the same as above, just solve them by isolating $n$.

Example 5.2.1

A production engineer wants to test, based on the data in Table 6.5.3 below, and to a significance level $\alpha = 0,05$, if the average height of a rod is close to the nominal value of $1055$ mm. A sample of $20$ rods was analyzed and the measurements obtained are given below.

903,88 1036,92 1098,04 1011,26
1020,70 915,38 1014,53 1097,79
934,52 1214,08 993,45 1120,19
860,41 1039,19 950,38 941,83
936,78 1086,98 1144,94 1066,12

Table 6.5.3: 20-rod sample height

Using the software Action we have the following results:

Figura6.5.16.svg

Figure 6.5.16: Data boxplot

From the data, we have $\overline{x} = 1019,37$ and $s = 91,37$. For $\alpha = 0,05$ and $n= 20$ We have, from the Student t distribution table, that $t_{\alpha/2} = 2,093$. Therefore, we reject $H_0$ if $t_{\text{obs}} \ < \ -2,093$ or if $t_{\text{obs}} \ > \ 2,093$, where

$$t_{\text{obs}}=\frac{\overline{x}-\mu_0}{\frac{s}{\sqrt{n}}}.$$

Replacing $\mu_0 = 1055$, $\overline{x} = 1019,37$, $n = 20$ and $s = 91,37$ in the equation we obtain:

$$t_{\text{obs}}=\frac{1019,37-1055}{\frac{91,37}{\sqrt{20}}}=-1,74.$$

So, how $t_{\text{obs}}$ is greater than $-2,093$ and less than $2,093$, the null hypothesis should not be rejected. In other words, the difference between $\overline{x}=1019,37$ and $\mu = 1055$ is not significant.

Figura6.5.17.svg

Figure 6.5.17: Student’s two-sided t test

The p-value is given by

$$\text{p-valor} = \mathbb{P}[|t| \ > \ |t_{\text{obs}}| \ | \ H_0]=\mathbb{P}[t \ > \ 1,74 \ | \ H_0]+\mathbb{P}[t \ < \ -1,74 \ | \ H_0]=0,097$$

How $\overline{x} = 1019,37$, $s = 91,37$, $n = 20$ and $\alpha = 0,05$, the confidence interval is given by

$$\left(1019,37-2,093\frac{91,37}{\sqrt{20}};1019,37+2,093\frac{91,37}{\sqrt{20}}\right)=(976,60;1062,13).$$

Results
T-statistic -1.744
Degrees of Freedom 19
P-value 0.0973
Sample Average 1019.3685
Sample Standard Deviation 91.3686
Sample Size 20
Alternative Hypothesis Different from 1055
Confidence Level 0.95
Lower Limit 976.6067
Upper Limit 1062.1303

Table 6.5.4: Table of results obtained by Action Stat

To calculate the power of the test to detect a difference $\delta = 35,63$, we use the Action software. In this case, we have as values $n = 20$, $\delta = 35,63$, $\alpha = 0,05$, standard deviation $\hat{\sigma} = s = 91,37$ and type of bilateral test. So, by throwing these values into Action, we are given the power result as being $0,38069$. The calculated results and graph are given below

Power of testing N Difference Significance level Deviation Hypothesis
0,380692 20 35,63 0,05 91,37 Bilateral

Table 6.5.5: Table of calculated results

Figura6.5.18.svg

Figure 6.5.18: Data Point Chart

Suppose that in this exercise we want to calculate the sample size necessary to guarantee the rejection of the null hypothesis with at least probability $0,9$ when the difference between the true value of the mean and its hypothetical value is at most $35,63$, given a standard deviation $\hat{\sigma} = s = 91,37$. To solve this problem, we use Action, providing the values $\alpha = 0,05$, $\delta = 35,63$, $\sigma = 91,37$ and power equal to $0,9$. As a result we have $n = 72$.

The calculated results and graph are given below

Power of testing N Difference Significance level Deviation Hypothesis
0,90385 72 35,63 0,05 91,37 Bilateral

Table 6.5.6: Results obtained from hypothesis testing

Figura6.5.19.svg

Figure 6.5.19: Test Power Curve Graph (n=72)

6.5.3 Test for proportion

Let us consider a population in which the proportion of individuals carrying a certain characteristic is $p$. We define the random variable $X$ as being 1 if the individual has the characteristic and 0 (zero) otherwise. So, we have to $X \sim \ \text{Bernoulli}(p)$. Let’s take a sample $X_1,\ldots,X_n$ of this population. Each $X_i$, with $i = 1,\ldots,n$, has a distribution of $\text{Bernoulli}(p)$, that is, $$X_1,X_2,\ldots,X_n\sim \ \hbox{Bernoulli(p)}$$

with average $p$ and variance $p(1-p)$.

Figura6.5.20.svg

Figure 6.5.20: Statistical Inference Flowchart with Bernoulli distribution sample

For a test of proportions, we will use the following approaches: Test for proportion using the central limit theorem, Pearson’s chi-square test and exact binomial.

6.5.3.1 Test for proportion using the Central Limit Theorem

Normal approximation

By the central limit theorem, $\overline{X}$ will have an approximately normal distribution, with mean p and variance $\frac{p(1-p)}{n}$, that is, $$\overline{X}\sim N\left(p,\frac{p(1-p)}{n}\right).$$

We observe that $\overline{X}$ is a maximum likelihood estimator for $p$, the population proportion, and, thus, for $n$ sufficiently large we can consider the sampling distribution of $\hat{p}=\overline{X}$ as approximately normal: $$\hat{p}\sim N\left(p,\frac{p(1-p)}{n}\right).$$

Hence, we have to $$Z=\frac{\hat{p}-p}{\sqrt{\frac{p(1-p)}{n}}}\sim N(0,1).$$

Let’s look at the steps for constructing the test for proportion.

1. Establish the hypotheses

$$\begin{cases}H_0: p=p_0 \cr H_1: p\neq p_0\end{cases} \quad \begin{cases}H_0:p=p_0 \cr H_1: p \ < \ p_0\end{cases} \quad \begin{cases} H_0:p=p_0 \cr H_1: p \ > \ p_0\end{cases}$$

whether the test is two-sided, left-sided, or right-sided, respectively.

2. Set the significance level $\alpha$.

3. Determine the critical region.

  • If the test is two-sided, we determine the points $-Z_{\alpha/2}$ and $Z_{\alpha/2}$ using the normal distribution table, such that $\mathbb{P}[Z \ > \ Z_{\alpha/2}]=\mathbb{P}[Z \ < \ -Z_{\alpha/2}]=\alpha/2$.

Figura6.5.21.svg

Figure 6.5.21: Two-sided hypothesis test Z Normal

  • If the test is right-sided, we determine the critical point $Z_{\alpha}$ such that $\mathbb{P}[Z \ > \ Z_{\alpha}]=\alpha$.

Figura6.5.22.svg

Figure 6.5.22: Right-sided test of Z Normal hypotheses

  • If the test is left-sided, we determine the critical point $-Z_{\alpha}$ such that $\mathbb{P}[Z \ < \ -Z_{\alpha}]=\alpha$.

Figura6.5.23.svg

Figure 6.5.23: Left-sided test of Z Normal hypotheses

4. Calculate, under the null hypothesis, the value $$Z_{\text{obs}}=\frac{\hat{p}-p_0}{\sqrt{p_0(1-p_0)/n}}.$$

5. Criteria:

  • If the test is two-sided and $Z_{\text{obs}} \ > \ Z_{\alpha/2}$ or $Z_{\text{obs}} \ < \ -Z_{\alpha/2}$, we reject $H_0$. Otherwise, we do not reject $H_0$.

  • If the test is right-sided and $Z_{\text{obs}} \ > \ Z_{\alpha}$, we reject $H_0$. Otherwise, we do not reject $H_0$.

  • If the test is left-sided and $Z_{\text{obs}} \ < \ -Z{\alpha}$, we reject $H_0$. Otherwise, we do not reject $H_0$.

6. The p-value is determined by $$\hbox{p-valor} = \mathbb{P}[|Z| \ > \ |Z_{\text{obs}}| |H_0]=2\mathbb{P}[Z \ > \ |Z_{\text{obs}}| | H_0]$$

in the bilateral test. If the test is right-sided, the p-value is determined by $$\hbox{p-valor} = \mathbb{P}[Z \ > \ Z_{\text{obs}} | H_0]$$

and, if the test is left-tailed $$\hbox{p-valor} = \mathbb{P}[Z \ < \ Z_{\text{obs}} | H_0].$$

7. As seen in Section 6.4.1.1, the confidence interval is given by $$IC(p,1-\alpha)=\left(\hat{p}-Z_{\alpha/2}\sqrt{\frac{\hat{p}(1-\hat{p})}{n}};\hat{p}+Z_{\alpha/2}\sqrt{\frac{\hat{p}(1-\hat{p})}{n}}\right)$$

whether the test is two-sided. We note here that the lower limit of the confidence interval cannot be less than zero and the upper limit must not be more than one since we are calculating the confidence interval for a proportion and it makes no sense to consider a proportion negative or greater than one in this case. In the case where the test is right-sided, the confidence interval for the parameter $p$ is given by $$IC(p,1-\alpha)=\left(\hat{p}-Z_{\alpha}\sqrt{\frac{\hat{p}(1-\hat{p}}{n}};1\right)$$

and, if the test is left-tailed, the confidence interval for the parameter $p$ is given by $$IC(p,1-\alpha)=\left(0;\hat{p}+Z_{\alpha}\sqrt{\frac{\hat{p}(1-\hat{p})}{n}}\right).$$

8. To calculate the power (given a sample size) or the sample size necessary to obtain a certain power for testing a proportion, we use the Action software. The Action receives the sample size as parameters ($n$), the proportion of the null hypothesis ($p_0$), the proportion of the alternative hypothesis ($p$), the value of power ($P$) and the level of significance ($\alpha$). So, to calculate the power of a proportion test to detect a difference between the proportion of the null hypothesis ($p_0$) and a proportion $p$ different from the null hypothesis, at a significance level $\alpha$ specific, the formulas used by Action are given by $$P=1-\Phi(Z_{\alpha/2}-(2\arcsin(\sqrt{p_0})-2\arcsin(\sqrt{p}))\sqrt{n})+\Phi(-Z_{\alpha/2}-(2\arcsin(\sqrt{p_0})-2\arcsin(\sqrt{p}))\sqrt{n})$$

for the two-sided test. If the test is left-sided, $$P=\Phi(-Z_{\alpha}-(2\arcsin(\sqrt{p_0})-2\arcsin(\sqrt{p}))\sqrt{n})$$

and if the test is right-sided, $$P=1-\Phi(Z_{\alpha}-(2\arcsin(\sqrt{p_0})-2\arcsin(\sqrt{p}))\sqrt{n})$$

where $\Phi$ is the cumulative distribution function of a random variable with standard normal distribution. The nonlinear transformation $\phi=2\arcsin(\sqrt{p})$ is used in an attempt to detect equal powers for equal differences between proportions $p$ and $p_0$.

To calculate the sample size necessary for the test to detect a difference between the hypothetical proportion $p_0$ and the real proportion $p$, with a given power, we just need to enter the values of the proportions $p_0$ and $p$, of power $P$ and the level of significance $\alpha$. With this, Action provides us with the sample size value.

Example 5.3.1.1

A manufacturer guarantees that $90%$ of the parts it supplies to the production line of a given factory are in accordance with the required specifications. The analysis of a sample of $200$ parts revealed $25$ defective. At a level of $5%$, can we say that the manufacturer’s statement is true?

1. We establish the hypotheses

$$\begin{cases}H_0: p=0,9 \cr H_1: p \ < \ 0,9\end{cases}$$

2. Let’s set the significance level $\alpha = 0,05$.

3. How $\alpha = 0,05$, $-Z_{\alpha}=-1,64$.

4. We have to $\hat{p}=0,875$ and, under the null hypothesis, $p_0=0,9$. So, $$Z_{\text{obs}}=\frac{0,875-0,9}{\sqrt{(0,9)(0,1)/200}}=-1,178.$$

Figura6.5.24.svg

Figure 6.5.24: Representation of the rejection region and $Z_{obs}$

5. Conclusion: how $-1,64 = -Z_{\alpha} \ < \ Z_{\text{obs}}= -1,178$, we do not reject $H_0$. Therefore, we have evidence that the manufacturer’s claim is true.

6. Let’s now calculate the P-value: $$\text{P-valor} \ = \mathbb{P}[Z \ < \ Z_{\text{obs}}| H_0]=\mathbb{P}[Z \ < \ -1,178 | H_0]=0,1192.$$

7. How $n = 200$, $\hat{p} = 0,875$, $-Z_{\alpha} = -1,64$, we have that the confidence interval is $$\left(0;0,875+1,64\sqrt{\frac{0,875(1-0,875)}{200}}\right)=(0;0,9134).$$

Using the software Action we have the following results:

Variables Quantity Proportions
Success 175 0,875
Failure 25 0,125

Table 6.5.7: Sample information

Information Success
Z -1,178511
P-value 0,1192964
Lower Limit 0
Upper Limit 0,9134655
Alternative Hypothesis Less than 0.9

Table 6.5.8: Test results for proportion

8. If we want to calculate the power of the test to detect the difference between the hypothetical proportion $p_0 = 0,9$ and a real proportion $p=0,8$ to a level of significance $\alpha = 0,05$, we launch the corresponding values in the Action software, choosing the left-sided test (Less than), from which we obtain that $\text{Poder} \ = 0,9910$ approximately. The results are calculated in Table 6.5.9 below

Statistics Value
Sample size 200
p 0,8
p0 0,9
Power 0,991072
Significance level 0,05
Alternative Hypothesis Less than

Table 6.5.9: Statistics for calculating Test Power (n=200)

Suppose we were in the left-sided test and wanted to calculate the sample size necessary to detect the difference between the hypothetical proportion $p_0 = 0,9$ and a real proportion $p= 0,8$ to a level of significance $\alpha = 0,05$ and with a power of $0,9$. So, using Action, we would be provided with a sample size $n = 106,3$. In other words, a sample size $107$.

The results can be seen in the table below

Statistics Value
Sample size 106,33156
p 0,8
p0 0,9
Power 0,9
Significance level 0,05
Alternative Hypothesis Less than

Table 6.5.10: Statistics for calculating sample size

Normal Approximation with Continuity Correction

It is suggested that a continuity correction be made when carrying out a test of a proportion due to the fact that the Binomial distribution, which is discrete, is approximated by a Normal one, which is continuous. This correction consists of replacing the equation $$Z=\frac{\hat{p}-p}{\sqrt{\frac{p(1-p)}{n}}}\sim N(0,1)$$

by

$$Z_c=\begin{cases}\dfrac{(\hat{p}-p_0)+1/(2n)}{\sqrt{p_0(1-p_0)/n}} \ \hbox{se} \ \hat{p}- p_0 \ < \ 0 \cr \cr \dfrac{(\hat{p}-p_0)-1/(2n)}{\sqrt{p_0(1-p_0)/n}} \hbox{se} \ \hat{p}-p_0 \ > \ 0\end{cases}$$

The idea is to prevent the rejection of $H_0$ resulting from the approximation made, which could eventually occur when $Z$ was quite close to the critical value.

Note

The test is carried out in a similar way to what was seen previously.

Example 5.3.1.2

Considering Example 5.3.1.1, we will perform the test for proportion using the Normal approximation with continuity correction.

1. We establish the hypotheses

$$\begin{cases}H_0: p=0,9 \cr H_1: p \ < \ 0,9\end{cases}$$

2. We fix the significance level $\alpha = 0,05$.

3. How $\alpha = 0,05$, we have to $-Z_{0,05} = -1,64$.

4. $\hat{p} = 0,875$ and, under the null hypothesis, $p_0 = 0,9$. So, how $\hat{p} - p_0 = 0,875 - 0,9 = -0,025 \ < \ 0$, we have from the equation $Z_c$ that $$Z_c=\frac{(0,875-0,9)+1/400}{\sqrt{(0,9)(0,1)/200}}=-1,061.$$

5. Conclusion: how $Z_c = -1,061 \ > \ -1,64$, we do not reject $H_0$. Therefore, we have evidence that the manufacturer’s claim is true.

6. Let’s now calculate the p-value: $$\text{p-valor} = \mathbb{P}[Z \ < \ -1,061 | H_0]=0,1444.$$

7. We have to $n = 200$, $\hat{p} = 0,875$, $Z_{\alpha} = 1,64$. Furthermore, $\hat{p} = 0,875 \ > \ 0,5$ which implies that $p_c = 0,875+1/400 = 0,8775$. Thus, we have that the confidence interval is given by $$\left(0;0,8775+1,64\sqrt{\frac{0,8775(1-0,8775)}{200}}\right)=(0;\ 0,9156).$$

Using the software Action we have the following results:

Variables Quantity Proportions
Success 175 0,875
Failure 25 0,125

Table 6.5.11: Sample information

Information Value
Z -1,06066017
P-value 0,144422183
Lower Limit 0
Upper Limit 0,915633254
Alternative Hypothesis Less than

Table 6.5.12: Test results for proportion

6.5.3.2 Pearson’s chi-square test

Normal Approximation

This is another type of asymptotic test for a proportion. Let us consider, as in the previous case, a simple random sample $X_1,\ldots,X_n$ where each $X_i$, with $i = 1,\ldots,n$, has a distribution of $\text{Bernoulli}(p)$, that is, $$X_1,\ldots,X_n\sim \hbox{Bernoulli(p)}.$$

Se $n$ is large enough, the Pearson statistic, given by $$Q^2=\sum_{j=1}^2\frac{(O_j-E_j)^2}{E_j}\sim\chi_1^2$$

has approximately chi-square distribution with 1 degree of freedom, in which $O_1$ is the number of successes and $E_1=np$ is the expected frequency relative to the number of successes, $O_2=n-O_1$ and $E_2 = n(1-p)$, where $n = O_1+O_2$ is the sample size.

We remember that a chi-square distribution with 1 degree of freedom is equal to a squared standardized normal distribution, that is, if $Z \sim N(0,1)$, then $$\chi_1^2 = Z^2.$$

In this case, if $y$ is such that $\mathbb{P}[\chi_1^2 \ > \ y] = \alpha$, then how $\chi_1^2 = Z^2$, we have to $$\mathbb{P}[\chi_1^2 \ > \ y]=\mathbb{P}[Z^2 \ > \ y]=\mathbb{P}[Z \ < \ -\sqrt{y}] + \mathbb{P}[Z \ > \ \sqrt{y}],$$

i.e. $$\mathbb{P}[Z \ < \ -\sqrt{y}]+\mathbb{P}[Z \ > \ \sqrt{y}]=\alpha.$$

This way, we can perform the test using the standard normal distribution instead of the chi-square, which is more advantageous, since we can consider its symmetry.

Let’s see the steps to perform the Pearson Chi-Square test.

1. Establish the hypotheses

$$\begin{cases} H_0: p = p_0 \cr H_1: p \neq p_0 \end{cases}$$

if the test is two-sided,

$$\begin{cases} H_0: p = p_0 \cr H_1: p \ > \ p_0 \end{cases}$$

whether the test is right-sided or

$$\begin{cases}H_0: p = p_0 \cr H_1: p \ < \ p_0\end{cases}$$

whether the test is left-sided

2. Set the significance level $\alpha$.

3. Determine the critical region.

  • Two-sided test.

If the test is two-sided, we must find a critical point of the distribution $\chi_1^2$, based on the critical points of the standard normal distribution $Z$. The critical points of the standard normal distribution are $-Z_{\alpha/2}$ and $Z_{\alpha/2}$.

Figura6.5.21.svg

Figure 6.5.25: Two-sided test from the standard normal distribution

How $Z^2 = \chi_1^2$, we have to $$\alpha=\mathbb{P}[Z \ < \ -Z_{\alpha/2}]+\mathbb{P}[Z \ > \ Z_{\alpha/2}]=\mathbb{P}[Z^2 \ > \ Z_{\alpha/2}^2]=P[\chi_1^2 \ > \ Z_{\alpha/2}^2].$$

Therefore, the critical point of the chi-square distribution with one degree of freedom is $Z_{\alpha/2}^2$.

Figura6.5.26.svg

Figure 6.5.26: One-sided test from the distribution $\chi^2_1$

  • One-sided tests.

If the test is right or left one-tailed, we must determine the critical point of the distribution $\chi_1^2$ based on the critical points of the standard normal distribution $Z$. The critical points for normal distribution $Z$ are given by $-Z_{\alpha}$ for the left-sided or $Z_{\alpha}$ for the right-sided test.

Figura6.5.27.svg

Figure 6.5.27: Left and right one-tailed test from standard normal distribution

For the left-sided case, as $Z^2 = \chi_1^2$, we have to $$Z \ < \ -Z_{\alpha} \Rightarrow |Z| \ > \ Z_{\alpha} \Rightarrow Z^2 \ > \ Z_{\alpha}^2 \ \Rightarrow \chi_1^2 \ > \ Z_{\alpha}^2$$

and, in the right-sided case, we have $$Z \ > \ Z_{\alpha} \ \Rightarrow Z^2 \ > \ Z_{\alpha}^2 \ \Rightarrow \chi_1^2 \ > \ Z_{\alpha}^2$$

Therefore, the critical point of the chi-square distribution with one degree of freedom is $Z_{\alpha}^2$. We can also observe that $$\mathbb{P}[\chi_1^2 \ > \ Z_{\alpha}^2]=\mathbb{P}[Z \ > \ Z_{\alpha}]+\mathbb{P}[Z \ < \ -Z_{\alpha}] = 2\alpha.$$

Figura6.5.28.svg

Figure 6.5.28: Left and right one-sided test from the distribution $\chi^2_1$

4. Calculate, under the null hypothesis, the Pearson statistic $$Q^2_{\text{obs}}=\sum_{j=1}^2\frac{(O_j-E_j)^2}{E_j}.$$

5. Criterion

  • If the test is two-sided and $Q^2_{\text{obs}}\geq Z_{\alpha/2}^2$, we reject $H_0$. Otherwise, we do not reject $H_0$.

  • If the test is left-sided we have two possibilities:

  1. Se $O_1\leq E_1$ and $Q^2_{\text{obs}}\geq Z_{\alpha}^2$ we reject $H_0$, otherwise we do not reject $H_0$.

  2. Se $O_1 \ > \ E_1$ we do not reject $H_0$ whatever the value of $Q^2_{\text{obs}}$.

  • If the test is right-sided we also have two possibilities:
  1. Se $O_1 \ < \ E_1$ so we don’t reject $H_0$, whatever the value of $Q^2_{\text{obs}}$.

  2. Se $O_1 \geq E_1$ and $Q^2_{\text{obs}}\geq Z_{\alpha}^2$ we reject $H_0$, otherwise we do not reject $H_0$.

6. The p-value is determined by $$\text{p-valor} \ = \mathbb{P}\left[\chi_1^2 \ > \ Q^2_{\text{obs}}|H_0\right]$$

if the test is two-sided,

$$\text{p-valor} = \begin{cases}\dfrac{1-P\left[\chi_1^2 \ < Q^2_{\text{obs}}\right]}{2} \ \hbox{se} \ O_1\leq np \cr \cr \dfrac{1+P\left[\chi_1^2 \ < Q^2_{\text{obs}}\right]}{2} \ \hbox{se} \ O_1 \ > \ np \end{cases}$$

whether the test is left-sided or

$$\text{p-valor} \ = \begin{cases}\dfrac{1+P\left[\chi_1^2 \ < Q^2_{\text{obs}}\right]}{2} \ \hbox{se} \ O_1\leq np \cr \dfrac{1-P\left[\chi_1^2 \ < Q^2_{\text{obs}}\right]}{2} \ \hbox{se} \ O_1 \ > \ np \end{cases}$$

whether the test is right-sided.

We can calculate the power of the test or the sample size necessary to obtain a certain power using Action. The parameters used by Action are the sample size ($n$), the proportions ($p_0$) of the null hypothesis and ($p$) of the alternative hypothesis, the degrees of freedom ($df$), the value of power ($P$) and the level of significance ($\alpha$). To calculate power, the formula used is $$\text{Poder} = \Gamma(\chi_{\alpha})$$

such that $\Gamma$ is the cumulative density function of the non-central chi-square distribution with $df$ degrees of freedom and non-centrality parameter $\varphi$ given by $$\varphi=n\sum_{i=1}^2\frac{(p_{1i}-p_{0i})^2}{p_{0i}}$$

where $p_{0i}$ are the probabilities under the null hypothesis and $p_{1i}$ the probabilities under the alternative hypothesis, satisfying $$\sum_{i=1}^2p_{0i}=1 \quad \hbox{e} \quad \sum_{i=1}^2p_{1i}=1.$$

Example 5.3.2.1

Solve Example 5.3.1.1 using Pearson’s chi-square test.

1. We establish the hypotheses

$$\begin{cases} H_0: p = 0,9 \cr H_1: p \ < \ 0,9\end{cases}$$

2. We fix the significance level $\alpha = 0,05$.

3. How $\alpha = 0,05$, $-Z_{\alpha} = -1,6448$. In this way, we have to $(-Z_{\alpha})^2 = 2,7055$.

4. We have to $O_1 = 175$ and, under the null hypothesis, $p_0 = 0,9$. Logo $E_1 = 0,9 \times 200 = 180$. Furthermore, $O_2 = 25$ and $E_2 = 0,1\times 200 = 20$. So, $$Q_{\text{obs}}^2=\frac{(175-180)^2}{180}+\frac{(25-20)^2}{20}=1,3889.$$

5. Conclusion: how $O_1 \leq E_1$ and $Q^2_{\text{obs}} = 1,3889 \ < 2,7055$ we do not reject $H_0$. Therefore, we have evidence that the manufacturer’s claim is true.

Figura6.5.29.svg

Figure 6.5.29: Representation of the rejection region and $Q^2_{\text{obs}}$

6. The p-value is given by $$\text{p-valor} \ = \dfrac{1-\mathbb{P}[\chi_1^2 \ < \ Q_{\text{obs}}^2]}{2} = \dfrac{1-\mathbb{P}[\chi_1^2 \ < \ 1,3889]}{2}= 0,1193.$$

Results Values
Pearson Statistics 1.388889
Degrees of Freedom 1
P-value 0.1192964
Proportion of success in the sample 0.875
Alternative Hypothesis Less than 0.9
Confidence Level 95%
Lower Limit 0
Upper Limit 0.9085292

Table 6.5.13: Action Stat results from the test for proportion

Normal approximation with continuity correction

When applying Pearson’s Chi-Square Test we are, again, approximating a discrete distribution with a continuous one. Therefore, a continuity correction is suggested, in this case also called Yates correction.

The steps for carrying out this test are analogous to those in the previous case, with the only difference: if the value $Q^2$ is greater than the critical value, we will replace the equation $$Q^2=\sum_{j=1}^2\frac{(O_j-E_j)^2}{E_j}$$

for your correction $Q^2_c$ given by $$Q^2_c=\sum_{j=1}^2\frac{(|O_j-E_j|-0,5)^2}{E_j}.$$

Observations

1) Obviously, it is not necessary to use the Yates correction if the value obtained $Q^2$ is smaller than the critical point, as the new value will be smaller than the first, continuing to be insignificant.

2) The idea here is also to prevent the rejection of $H_0$ resulting from the approximation made, which could eventually occur when $Q^2_{\text{obs}}$ was quite close to the critical value.

Example 5.3.2.2

Let us consider that from $75$ parts, $12$ are defective. The manufacturer guarantees that $90%$ of these parts are in accordance with the required specifications. At the level of $5%$ of significance, can we say that the manufacturer’s statement is valid? (Solve using continuity correction.)

1. We establish the hypotheses

$$\begin{cases}H_0: p=0,9 \cr H_1: p \ < \ 0,9\end{cases}$$

2. Let’s set the significance level $\alpha = 0,05$.

3. How $\alpha = 0,05$, $Z_{\alpha}^2 = 2,7055$.

4. We have to $O_1 = 63$ and, under the null hypothesis, $p_0 = 0,9$. Then, $E_1 = 0,9\times 75 = 67,5$. Furthermore, $O_2 = 12$ and $E_2 = 0,1\times 75 = 7,5$. So, $$Q^2=\frac{(63-67,5)^2}{67,5}+\frac{(12-7,5)^2}{7,5}=3.$$

How $Q^2 \ > \ 2,7055$, we calculate $Q^2_c$. $$Q^2_c=\frac{(|63-67,5|-0,5)^2}{67,5}+\frac{(|13-7,5|-0,5)^2}{7,5}=0,2370+2,1333=2,3703.$$

Variables Quantity
Success 63
Failure 12

Table 6.5.14: Sample information

Information Value
Pearson Statistics 2,37037037
Degrees of Freedom 1
P-value 0,06183
Proportion of success in the sample 0,84
Confidence Interval 95%
Lower Limit 0
Upper Limit 0,9029
Alternative Hypothesis Less than

Table 6.5.15: Test results for proportion

5. Conclusion: how $Q^2_c = 2,3073 \ < \ 2,7055$ we do not reject $H_0$. Therefore, we have evidence that the manufacturer’s claim is true.

Observations

1) As we saw in Observation 1 above, if we rework Example 5.3.2.1 using the continuity correction we do not reject the null hypothesis.

2) Carrying out Example 5.3.2.2 without using continuity correction, we obtain $$Q^2=\frac{(63-67,5)^2}{67,5}+\frac{(12-7,5)^2}{7,5}=3$$

and, how $Q^2 = 3 \ > \ 2,7055$ we reject $H_0$, unlike the test with correction.

Thus, by carrying out the test with continuity correction, we avoid rejecting $H_0$, which occurred in the test without the correction due to the asymptotic approximation.

6.5.3.3 Exact binomial test

Let us consider, as in the previous cases, a simple random sample $X_1,\ldots,X_n$ where each $X_i$, with $i = 1,\ldots,n$, has a distribution of $\text{Bernoulli}(p)$, that is, $$X_1,\ldots,X_n\sim \hbox{Bernoulli(p)}.$$

Let us consider $$Y = \hbox{número de sucessos}.$$

In this case, $Y$ is a random variable with distribution $\text{Binomial}(n,p)$. The exact binomial proportions test is a proportions test composed of the following steps:

1. For the left and right bilateral and unilateral tests, we established one of the following hypotheses, respectively.

$$\begin{cases}H_0: p = p_0 \cr H_1: p\neq p_0\end{cases} \qquad \begin{cases}H_0:p = p_0 \cr H_1:p \ < \ p_0\end{cases} \qquad \begin{cases}H_0: p = p_0 \cr H_1:p \ > \ p_0\end{cases}$$

2. We fix the significance level $\alpha$.

3. We determine the critical region.

  • If the test is two-sided, we determine the values $t_1$ and $t_2$ of the Binomial distribution table such that $\mathbb{P}(X \ < \ t_1) = \mathbb{P}(X \ > \ t_2)\approx\frac{\alpha}{2}$.

  • If the test is left-tailed, we determine the value $t$ in the Binomial distribution table such that $\mathbb{P}(X \ < \ t)\approx\alpha$.

  • If the test is right-sided, we determine the value $t$ in the Binomial distribution table such that $\mathbb{P}(X \ > \ t)\approx\alpha$.

4. Determine the statistic $Y = \text{número de sucessos}$.

5. We use the following criteria to reject or not the hypothesis test:

  • If the test is two-sided and $Y \ > \ t_2$ or $Y \ < \ t_1$ we reject $H_0$. Otherwise, we do not reject $H_0$.

  • If the test is left-sided and $Y \ < \ t$, we reject $H_0$. Otherwise, we do not reject $H_0$.

  • If the test is right-sided and $Y \ > \ t$, we reject $H_0$. Otherwise, we do not reject $H_0$.

6. The p-value is given by $\text{p-valor} \ = \mathbb{P}[X\leq Y|H_0]=\mathbb{P}[X\leq Y|p = p_0].$

Example 5.3.3.1

An industrialist claims that his manufacturing process produces $90%$ of parts within specifications. We want to investigate whether this manufacturing process is still under control. A sample of $15$ parts were analyzed and found $10$ parts within specifications. At the level of $5%$ of significance, can we say this statement is true?

1. The hypotheses to be tested are

$$\begin{cases}H_0: p = 0,9 \cr H_1: p \ < \ 0,9\end{cases}$$

2. set the level of significance $\alpha = 0,05$.

3. Determine the critical region. In this case, determine the value $t$, such that $\mathbb{P}(X \ < \ t)\approx\alpha$, having $p_0 = 0,9$ and $n= 15$. In this way, we have to $t = 11$.

4. The statistic $Y = \text{número de sucessos}$ is equal to 10.

5. Conclusion: how $Y = 10 \ < \ 11 = t$, we reject $H_0$. Thus, there is evidence that the statement is not true.

6. The p-value is given by $$\text{p-valor} \ = \mathbb{P}[X\leq Y |H_0]=\mathbb{P}[X\leq 10|p=0,9]=0,0127.$$

Using the software Action we have the following results:

Variables Quantity
Success 10
Failure 5

Table 6.5.16: Sample information

Information Value
Statistics 0,0172
P-value 0,127204
Lower Limit 0
Upper Limit 0,915633254
Alternative Hypothesis Less than

Table 6.5.17: Test results for proportion

6.5.4 Test for rate

Let us consider a population and $X$ a random variable that represents a certain characteristic of this population with Poisson distribution with parameter $\lambda$. Let’s take a random sample $X_1,\ldots,X_n$ of this population. Each $X_i = 1,\ldots,n$ has Poisson distribution with parameter $\lambda$, that is, $$X_1,\ldots,X_n \sim \ \text{Poisson}(\lambda).$$

How $$\hat{\lambda}=\sum_{i=1}^n\frac{X_i}{n}$$

is a maximum likelihood estimator for $\lambda$, then, using the Central Limit Theorem, we have $$\hat{\lambda}=\sum_{i=1}^n\frac{X_i}{n}\sim N\left(\lambda,\frac{\lambda}{n}\right)$$

which implies that $$Z=\frac{\hat{\lambda}-\lambda}{\sqrt{\lambda/n}}\sim N(0,1).$$

Now let’s see the steps to perform the rate test:

1. Establish the hypotheses.

We fix $H_0: \lambda = \lambda_0$. Depending on the information provided by the problem we are studying, the alternative hypothesis can take one of the three forms below: $$H_1:\lambda\neq\lambda_0 \quad \text{(teste bilateral)};$$

$$H_1:\lambda \ > \ \lambda_0 \quad \text{(teste unilateral à direita)};$$

$$H_1:\lambda \ < \ \lambda_0 \quad \text{(teste unilateral à esquerda)};$$

2. Set the significance level $\alpha$.

3. Determine the critical region.

  • If the test is two-sided, we determine the critical points $Z_{\alpha/2}$ and $-Z_{\alpha/2}$ such that $$\mathbb{P}[Z \ > \ Z_{\alpha/2}] = \mathbb{P}[Z\ < \ -Z_{\alpha/2}]=\frac{\alpha}{2}$$

Figura6.5.30.svg

Figure 6.5.30: Representation of the bilateral test rejection region

  • If the test is right-sided, we determine the critical value $Z_{\alpha}$ such that $$\mathbb{P}[Z \ > \ Z_{\alpha}]=\alpha$$

Figura6.5.31.svg

Figure 6.5.31: Representation of the right-sided test rejection region

  • If the test is left-sided, we determine the critical value $-Z_{\alpha}$ such that $$\mathbb{P}[Z \ < \ -Z_{\alpha}]=\alpha$$

Figura6.5.32.svg

Figure 6.5.32: Representation of the left-sided test rejection region

4. Calculate, under the null hypothesis, the value $$Z_{\text{obs}}=\frac{\hat{\lambda}-\lambda_0}{\sqrt{\lambda_0/n}}.$$

5. Criteria:

  • Two-sided test: If $Z_{\text{obs}} \ > \ Z_{\alpha/2}$ or if $Z_{\text{obs}} \ < \ -Z_{\alpha/2}$, we reject $H_0$. Otherwise, we do not reject $H_0$.

  • Right-sided test: If $Z_{\text{obs}} \ > \ Z_{\alpha}$, we reject $H_0$. Otherwise, we do not reject $H_0$.

  • Left-sided test: If $Z_{\text{obs}} \ < \ -Z_{\alpha}$, we reject $H_0$. Otherwise, we do not reject $H_0$.

6. The p-value is given by $$\text{p-valor} = \mathbb{P}[|Z| \ > \ |Z_{\text{obs}}||H_0]=2\mathbb{P}[Z \ > \ |Z_{\text{obs}}| |H_0]$$

in the bilateral case.

In the right-sided case it is determined by $$\text{p-valor} = \mathbb{P}[Z \ > \ Z_{\text{obs}}| H_0]$$

and in the unilateral case on the left, for $$\text{p-valor} = \mathbb{P}[Z \ < \ Z_{\text{obs}} | H_0].$$

7. As we saw in Section 6.4.2, the confidence interval for the parameter $\lambda$ is given by $$IC(\lambda,1-\alpha)=\left(\hat{\lambda}-Z_{\alpha/2}\sqrt{\frac{\hat{\lambda}}{n}};\hat{\lambda}+Z_{\alpha/2}\sqrt{\frac{\hat{\lambda}}{n}}\right).$$

whether the test is two-sided. If the test is right-sided, then the confidence interval for the parameter $\lambda$ is given by $$IC(\lambda,1-\alpha)=\left(\hat{\lambda}-Z_{\alpha}\sqrt{\frac{\hat{\lambda}}{n}};\infty\right)$$

and if the test is left-tailed, then the confidence interval for the parameter is given by $$IC(\lambda,1-\alpha)=\left(0;\hat{\lambda}+Z_{\alpha}\sqrt{\frac{\hat{\lambda}}{n}}\right)$$

8. Type II error is calculated by accepting $H_0$ when it is false ($H_1$ is true). $$\mathbb{P}[\hbox{Erro do tipo II}]=\mathbb{P}[\hbox{Aceitar} H_0| H_1 \hbox{é verdadeira}]=\beta.$$

9. The power of the test is calculated by: 1 minus the probability of type II error, i.e. $$\text{Poder} \ = 1-\beta.$$

As this is a normal test, to calculate the power or sample size, we use the same techniques used for the test for the mean with known variance, that is, in Action, if we want to calculate the power of the test, we launch the sample size as a parameter ($n$), the difference ($\delta$), the level of significance ($\alpha$) and the standard deviation ($\sigma$). Similarly, we can calculate the sample size necessary for the test to detect a specific difference with a given power.

Example 5.4.1

The production manager of a company aims to evaluate the performance of a new teaching methodology for new hired workers. With the old methodology, there is an average rate of $4$ errors per worker in the first week of work. In a sample of $25$ workers, the new methodology was applied and it was observed that the average was $5$ errors per week. With this information, can we say that there is a significant difference between the old and the new methodology?

1. First, let’s establish the hypotheses:

$$\begin{cases}H_0: \lambda = 4 \cr H_1: \lambda \ < \ 4\end{cases}$$

since we want to test whether the new methodology is better than the old one, that is, whether it has a lower average error rate than the old one.

2. Let’s set the significance level $\alpha = 0,05$.

3. How $\alpha = 0,05$, $-Z_{\alpha}=-Z_{0,05}=-1,64$.

4. We have to $\hat{\lambda} = 5$ and, under the null hypothesis, $\lambda_0=4$. So, $$Z_{\text{obs}}=\frac{5-4}{\sqrt{4/25}}=2,5.$$

5. Conclusion: how $Z_{\text{obs}} = 2,5 \ > \ -1,64$, we do not reject $H_0$. Therefore, we have no evidence that the average error rate of the new methodology is lower than the old one.

Figura6.5.33.svg

Figure 6.5.33: Representation of the left-sided test

6. Let’s now calculate the p-value: $$\text{p-valor} \ = \mathbb{P}[Z \ < \ Z_{\text{obs}}|H_0]=\mathbb{P}[Z \ < \ 2,5|H_0]=0,9937903.$$

7. How $n=25$, $\hat{\lambda} = 5$ and $Z_{\alpha/2} = 1,64$, we have that the confidence interval is given by $$\left(0;\ 5+1,64\sqrt{\frac{5}{25}}\right)=(0;\ 5,735601).$$

Information Value
Sample Average Rate 5
Null hypothesis 4
Statistics 2,5
p-value 0,9938
Lower Limit 0
Upper Limit 5,7356009
Alternative Hypothesis Less than

Table 6.5.18: Test results for rate

Using the Action software, we will calculate the power of the test to detect a difference $\delta = -1$. Since the standard deviation is $\sigma = 2$, the sample size is $n= 25$ and the significance level is $\alpha = 0,05$, we have the following results.

Information Value
Power of testing 0,80376
Sample Size 25
Difference -1
Significance level 0,05
Deviation 2
Alternative Hypothesis Less than

Table 6.5.19: Test power results

The graph is shown in the figure below

Figura6.5.34.svg

Figure 6.5.34: Test power graph (n=25)

6.5.5 Test for variance

Be $X_1,X_2,\ldots,X_n$ a random sample of size $n$ taken from a normal population $N(\mu,\sigma^2)$. Suppose we want to test a hypothesis about the variance $\sigma^2$ of this population.

Using Corollary 2.3.3, we know that the statistic $$Q=\frac{(n-1)s^2}{\sigma^2}$$

has a chi-square distribution with $n-1$ degrees of freedom. We denote $Q \sim \chi_{(n-1)}^2$. To perform this type of test, we can follow the steps:

1. Establish one of the hypotheses (bilateral, unilateral to the right or unilateral to the left)

$$\begin{cases}H_0:\sigma^2=\sigma_0^2 \cr H_1:\sigma^2\neq\sigma_0^2\end{cases} \quad \begin{cases}H_0:\sigma^2=\sigma_0^2 \cr H_1:\sigma^2 \ > \ \sigma_0^2\end{cases} \ \hbox{ou} \ \begin{cases}H_0:\sigma^2=\sigma_0^2 \cr H_1:\sigma^2 \ < \ \sigma_0^2\end{cases}$$

NOTE: The hypotheses $H_0$ can be replaced by $H_0:\sigma^2 \geq \sigma_0^2$, $H_0:\sigma^2\leq\sigma_0^2$, $H_0:\sigma^2 \ > \ \sigma_0^2$ or $H_0:\sigma^2 \ < \ \sigma_0^2$.

2. Set the significance level $\alpha$.

3. Determine the critical region.

  • If the test is two-sided, we must determine the critical points $Q_{\alpha/2}$ and $Q_{1-\alpha/2}$ such that $\mathbb{P}[Q \ < \ Q_{\alpha/2}]=\alpha/2$ and $\mathbb{P}[Q \ > \ Q_{1-\alpha/2}]=\alpha/2$ using the chi-square distribution table with $n-1$ degrees of freedom.

Figura6.5.35.svg

Figure 6.5.35: Representation of the two-sided chi-square distribution test $\chi^2_{n-1}$

  • If the test is right-sided, we must determine the critical point $Q_{1-\alpha}$ such that $\mathbb{P}[Q \ > \ Q_{1-\alpha}]=\alpha$.

Figura6.5.36.svg

Figure 6.5.36: Representation of the one-sided chi-square distribution test $\chi^2_{n-1}$ on the right

  • If the test is left-sided, we must determine the critical point $Q_{\alpha}$ such that $\mathbb{P}[Q \ < \ Q_{\alpha}]=\alpha$.

Figura6.5.37.svg

Figure 6.5.37: Representation of the one-sided chi-square distribution test $\chi^2_{n-1}$ left

4. Calculate, under the null hypothesis, the value $$Q_{\text{obs}}=\frac{(n-1)s^2}{\sigma_0^2}$$

5. Criteria:

  • Two-sided test: If $Q_{\text{obs}} \ > \ Q_{\alpha/2}$ or if $Q_{\text{obs}} \ < \ Q_{1-\alpha/2}$, we reject $H_0$. Otherwise, we do not reject $H_0$.

  • Right-sided test: if $Q_{\text{obs}} \ > \ Q_{1-\alpha}$, we reject $H_0$. Otherwise, we do not reject $H_0$.

  • Left-sided test: if $Q_{\text{obs}} \ < \ Q_{\alpha}$, we reject $H_0$. Otherwise, we do not reject $H_0$.

6. The p-value is given by $$\text{p-valor} = 2.\min \lbrace \mathbb{P}[Q \ > \ Q_{\text{obs}}|H_0], \ \mathbb{P}[Q \ < \ Q_{\text{obs}}|H_0] \rbrace $$

in the bilateral case.

In the right-sided case, the p-value is given by $$\text{p-valor} = \mathbb{P}[Q \ > \ Q_{\text{obs}}|H_0]$$

and, in the left-sided case, the p-value is given by $$\text{p-valor} = \mathbb{P}[Q \ < \ Q_{\text{obs}}|H_0].$$

7. As we saw in Section 6.4.3, the confidence interval for the population variance $\sigma^2$ is given by $$IC(\sigma^2,1-\alpha)=\left(\frac{(n-1)s^2}{Q_{1-\alpha/2}};\frac{(n-1)s^2}{Q_{\alpha/2}}\right)$$

whether the test is two-sided. If the test is right-sided, the confidence interval is given by $$IC(\sigma^2,1-\alpha)=\left(\frac{(n-1)s^2}{Q_{1-\alpha}};\infty\right)$$

and if the test is left-sided, the confidence interval is given by $$IC(\sigma^2,1-\alpha)=\left(0;\frac{(n-1)s^2}{Q_{\alpha}}\right).$$

Example 5.5.1

An automatic filling machine is used to fill bottles with liquid detergent. A random sample of $20$ bottles results in a sample variance of the filling volume of $s^2 = 0,0153 \ \text{onças fluídas}^2$. If the filling volume variance exceeds $0,01 \ \text{onças fluídas}^2$, there will be an unacceptable proportion of bottles that are not completely filled or overfilled. Is there evidence in the sample data to suggest that the manufacturer has a problem with bottles that are under or overfilled with detergent? Use $\alpha = 0,05$ and consider that the filling volume has a normal distribution.

The parameter of interest is the population variance

1. First let’s establish the hypotheses:

$$\begin{cases}H_0:\sigma^2=0,01 \cr H_1:\sigma^2 \ > \ 0,01\end{cases}$$

2. How $\alpha = 0,05$ we have to $Q_{0,95} = 30,14$.

3. Criteria: Reject $H_0$ if $Q_{\text{obs}} \ > \ 30,14$.

4. Calculate $Q_{\text{obs}}$, given by $$Q_{\text{obs}}=\frac{(n-1)s^2}{\sigma_0^2}=\frac{19(0,0153)}{0,01}=29,07$$

5. Conclusion: how $Q_{\text{obs}} = 29,07 \ < \ 30,14$, the null hypothesis should not be rejected. That is, there is no evidence that the filling volume variance exceeds $0,01 \ \text{onças fluídas}^2$.

Figura6.5.38.svg

Figure 6.5.38: Representation of the one-sided chi-square distribution test $\chi^2_{n-1}$ on the right

6. Let’s now calculate the p-value: $$\text{p-valor} = \mathbb{P}[Q \ > \ Q_{\text{obs}}] = \mathbb{P}[Q \ > \ 29,07] = 0,064892.$$

7. How $n = 20$, $s^2 = 0,0153$ and $Q_{0,95} = 30,14$, it follows that the confidence interval for $\sigma^2$ with 95% confidence is given by

$$IC(\sigma^2,95\char37)=\left(\frac{(n-1)s^2}{Q_{0,95}};\infty\right)=(0,00964,\infty).$$

Information Value
Sample Variance 0,0153
Degrees of Freedom 19
Null Hypothesis 0,01
Alternative Hypothesis: Greater than 0,01
Statistics 30,14
Lower Limit 0,00964
Upper Limit infinite

Table 6.5.19: Test results for variance

6.5.6 Test for comparing two variances (F Test)

Suppose we want to compare the variances $\sigma_1^2$ and $\sigma_2^2$ of two independent Normal populations. To do this, we took a random sample $X_1,X_2,\ldots,X_{n_1}$ of population 1, with distribution $N(\mu_1,\sigma_1^2)$, and a sample $Y_1,Y_2,\ldots,Y_{n_2}$ of population 2, with distribution $N(\mu_2,\sigma_2^2)$.

As we saw previously, $$Q_1=\frac{(n_1-1)}{\sigma_1^2}s_1^2\sim\chi_{n_1-1}^2 \quad (\hbox{Qui-quadrado com} \ n_1 - 1 \ \hbox{graus de liberdade})$$

$$Q_2=\frac{(n_2-1)}{\sigma_2^2}s_2^2\sim\chi_{n_2-1}^2 \quad (\hbox{Qui-quadrado com} \ n_2 - 1 \ \hbox{graus de liberdade})$$

where $s_1^2$ is the sampling variance of population 1 and $s_2^2$ the sampling variance of population 2. In this case, the expression $F$ defined by $$F=\frac{\frac{Q_1}{n_1-1}}{\frac{Q_2}{n_2-1}}=\frac{\frac{s_1^2}{\sigma_1^2}}{\frac{s_2^2}{\sigma_2^2}}=\frac{s_1^2}{s_2^2}\frac{\sigma_2^2}{\sigma_1^2}$$

has distribution $F$ from Snedecor with $n_1-1$ degrees of freedom in the numerator and $n_2-1$ degrees of freedom in the denominator, which we denote by $F_{(n_1-1;n_2-1)}$.

To run the test, we can perform the following steps:

1. Establish one of the following hypotheses

$$\begin{cases}H_0:\sigma_1^2=\sigma_2^2 \cr H_1:\sigma_1^2\neq\sigma_2^2\end{cases} \quad \begin{cases}H_0:\sigma_1^2=\sigma_2^2 \cr H_1:\sigma_1^2 \ > \ \sigma_2^2\end{cases} \ \hbox{ou} \ \begin{cases}H_0:\sigma_1^2=\sigma_2^2 \cr H_1:\sigma_1^2 \ < \ \sigma_2^2\end{cases}$$

which are equivalent to the hypotheses

$$\begin{cases}H_0:\dfrac{\sigma_1^2}{\sigma_2^2}=1 \cr H_1:\dfrac{\sigma_1^2}{\sigma_2^2}\neq 1\end{cases} \quad \begin{cases}H_0:\dfrac{\sigma_1^2}{\sigma_2^2}=1 \cr H_1:\dfrac{\sigma_1^2}{\sigma_2^2} \ > \ 1\end{cases} \ \hbox{ou} \begin{cases}H_0:\dfrac{\sigma_1^2}{\sigma_2^2}=1 \cr H_1:\dfrac{\sigma_1^2}{\sigma_2^2} \ < \ 1\end{cases}$$

2. Set the significance level $\alpha$.

3. Determine the critical region.

  • If the test is two-sided, we must determine the critical points $F_{\alpha/2}$ and $F_{1-\alpha/2}$ of distribution $F$ with $n_1-1$ degrees of freedom in the numerator and $n_2-1$ degrees of freedom in the denominator using the Fisher-Snedecor distribution table so that $\mathbb{P}[F \ < \ F_{\alpha/2}]=\mathbb{P}[F \ > \ F_{1-\alpha/2}]=\alpha/2$.

Figura6.5.39.svg

Figure 6.5.39: Representation of the two-sided Fisher-Snedecor distribution test

  • If the test is right-sided, we determine the point $F_{1-\alpha}$ such that $\mathbb{P}[F \ > \ F_{1-\alpha}]=\alpha$.

Figura6.5.40.svg

Figure 6.5.40: Representation of the right-sided test of Fisher-Snedecor distribution

  • If the test is left-sided, we determine the point $F_{\alpha}$ such that $\mathbb{P}[F \ < \ F_{\alpha}]=\alpha$.

Figura6.5.41.svg

Figure 6.5.41: Representation of the left-sided test of Fisher-Snedecor distribution

4. Calculate, under the null hypothesis, the value $$F_{obs}=\frac{s_1^2}{s_2^2}$$

5. Criteria:

  • Two-sided test: If $F_{obs} \ > \ F_{1-\alpha/2}$ or $F_{obs} \ < \ F_{\alpha/2}$ we must reject $H_0$, otherwise we do not reject $H_0$.

  • Left-sided test: If $F_{obs} \ < \ F_{\alpha}$ we must reject $H_0$. Otherwise, we do not reject $H_0$.

  • Right-sided test: If $F_{obs} \ > \ F_{1-\alpha}$ we must reject $H_0$. Otherwise, we do not reject $H_0$.

6. The p-value is given by $$\text{p-valor} \ = 2\min\lbrace\mathbb{P}[F \ > \ F_{\text{obs}}|H_0]; \mathbb{P}[F \ < \ F_{\text{obs}}|H_0]\rbrace.$$

in the bilateral test. In the right-sided test, the p-value is given by $$\text{p-valor} \ = \mathbb{P}[F \ > \ F_{\text{obs}}|H_0]$$

and, in the left-sided test, the p-value is given by $$\text{p-valor} \ = \mathbb{P}[F \ < \ F_{\text{obs}}|H_0]$$

7. The confidence interval for the ratio between variances, as we saw in Section 6.4.4, is given by $$IC\left(\frac{\sigma_1^2}{\sigma_2^2},1-\alpha\right)=\left(\frac{1}{F_{(1-\alpha/2)}}\frac{s_1^2}{s_2^2};\frac{1}{F_{(\alpha/2)}}\frac{s_1^2}{s_2^2}\right)$$

whether the test is two-sided. If the test is one-tailed to the right, then the confidence interval for the ratio between the variances is given by $$IC\left(\frac{\sigma_1^2}{\sigma_2^2},1-\alpha\right)=\left(\frac{1}{F_{1-\alpha}}\frac{s_1^2}{s_2^2};\infty\right)$$

and, if the test is left-tailed, then the confidence interval for the ratio of variances is given by $$IC\left(\frac{\sigma_1^2}{\sigma_2^2},1-\alpha\right)=\left(0,\frac{1}{F_{\alpha}}\frac{s_1^2}{s_2^2}\right).$$

Example 5.6.1

A quality analyst wants to evaluate whether there is a difference between the variability in the production of camshafts developed by two machining systems. Table 6.5.20 below presents the measurements of two independent populations with Normal distribution. Can we say that the variances of both are equal?

Machining System Measurement Machining System Measurement
1 18.7997 2 21.1609
1 20.5035 2 26.1371
1 18.6214 2 21.4737
1 19.9192 2 30.9934
1 21.117 2 22.8421
1 20.8353 2 24.4133
1 17.527 2 20.4137
1 17.078 2 25.5475
1 17.6197 2 21.8791
1 21.4255 2 22.6706
1 18.7545 2 24.7531
1 19.2026 2 25.7219
1 18.4187 2 22.6389
1 20.7641 2 26.2308
1 21.0553 2 26.7998
1 17.5905 2 28.4708
1 18.7561 2 26.9941
1 18.9772 2 25.1489
1 20.3084 2 24.6179
1 18.8988 2 27.0194
1 19.1688 2 25.0589
1 19.2898 2 22.1119
1 22.059 2 20.3069
1 18.5854 2 23.6758
1 17.8896 2 27.1201
2 29.6136
2 25.9948
2 18.223
2 23.7336
2 22.4208

Table 6.5.20: Measurements of two independent populations with Normal distribution

From sample 1, we have $$\overline{x}_1=\frac{18,7997+\ldots+21,0553}{25}=19,3266$$

$$s_1=\sqrt{\frac{(18,7997-19,3266)^2+\ldots+(21,0553-19,3266)^2}{25-1}}=1,36234$$

From sample 2, we have $$\overline{x}_2=\frac{21,1609+\ldots+22,4208}{30}=24,4729$$

$$s_2=\sqrt{\frac{(21,1609-24,4729)^2+\ldots+(22,4208-24,4729)^2}{30-1}}=2,88760$$

Let’s establish the hypotheses

$$\begin{cases}H_0:\sigma_1^2=\sigma_2^2 \cr H_1:\sigma_1^2\neq\sigma_2^2\end{cases}$$

Let’s set the significance level $\alpha = 0,05$.

How $s_1 = 1,36$ and $s_2 = 2,89$ we have to $$F_{obs}=\frac{(1,36)^2}{(2,89)^2}=0,223.$$

Observing the Fisher-Snedecor distribution table with $24$ degrees of freedom in the numerator and $29$ in the denominator we have $F_{(24;29;0,975)} = 2,154$ and $F_{(24;29;0,025)} = 0,451$.

How $F_{\text{obs}}=0,223 \ < \ F_{(24;29;0,025)} = 0,451$, we reject $H_0$.

Figura6.5.42.svg

Figure 6.5.42: Representation of the critical region

Now let’s calculate the p-value. $$\text{p-valor} = 2\min\lbrace\mathbb{P}[F \ > \ 0,223 | H_0];\mathbb{P}[F \ < \ 0,223 | H_0]\rbrace=0,000358.$$

The confidence interval is given by $$IC(\sigma_1^2/\sigma_2^2,1-\alpha)=\left(\frac{1}{2,154}\times\frac{1,8496}{8,3347};\frac{1}{0,451}\times\frac{1,8496}{8,3347}\right)=(0,103;0,494).$$

since the test is two-sided.

See below the results obtained by the software Action.

Information Value
F-statistic 0,2226
Degrees of freedom (Numerator) 24
Degrees of freedom (Denominator) 29
P-value 0,00035785
Sample 1 standard deviation 1,362342862
Sample 2 standard deviation 2,887603214
Confidence Interval for $\frac{\sigma_1^2}{\sigma^2_2}$ 95%
Lower Limit 0,103335823
Upper Limit 0,493571669

Table 5.6.21: Test for Two Variances

Lower limit Standard deviation Upper limit
Sample 1 1,0638 1,3623 1,8952
Sample 2 2,2997 2,8876 3,8818

Table 5.6.22: Confidence Interval for Standard Deviation

Figura6.5.43.svg

Figure 6.5.43: Representation of Confidence Intervals

6.5.7 Test for comparing two means (t-test)

Suppose we want to compare two means of two independent populations and both with Normal distribution. From population 1 we took a random sample $X_1,X_2,\ldots,X_{n_1}$ in size $n_1$ and from population 2 we take a random sample $Y_1,Y_2,\ldots,Y_{n_2}$ in size $n_2$.

Let’s assume that $X\sim N(\mu_1,\sigma_1^2)$ and $Y\sim N(\mu_2,\sigma_2^2)$. So we have to $$\overline{X}\sim N\left(\mu_1,\frac{\sigma_1^2}{n_1}\right) \quad \hbox{e} \quad \overline{Y}\sim N\left(\mu_2,\frac{\sigma_2^2}{n_2}\right).$$

Furthermore, $$\overline{X}-\overline{Y}\sim N\left(\mu_1-\mu_2,\frac{\sigma_1^2}{n_1}+ \frac{\sigma_2^2}{n_2} \right).$$

We considered two distinct cases for hypothesis testing to compare two means. The first case in which we have unknown but equal population variances and the second case in which we have unknown and distinct variances.

6.5.7.1 Comparison of Means: Equal Variances

We will now consider that the variances of the populations are equal, however, unknown, that is, $\sigma_1^2 = \sigma_2^2 = \sigma^2$. We denote $s^2_i$ the sampling variance of the sample $i=1,2$. Since the samples are independent, we obtain that $$\frac{(n_1-1)s^2_1}{\sigma^2} \quad \text{e} \quad \frac{(n_2-1)s^2_2}{\sigma^2}$$ are independent random variables with chi-square distribution with $n_1-1$ and $n_2-1$ degrees of freedom, respectively. Since the sum of independent chi-square distributions also has a chi-square distribution with the degrees of freedom given by the sum, we obtain that $$\frac{(n_1-1)s^2_1}{\sigma^2} + \frac{(n_2-1)s^2_2}{\sigma^2}=\frac{(n_1-1)s^2_1 + (n_2-1)s^2_2}{\sigma^2}$$ has a chi-square distribution with $n_1 + n_2 -2$ degrees of freedom. On the other hand, given that the variances are equal, we have $$\frac{\bar{X} - \bar{Y} - (\mu_1 - \mu_2)}{\sigma \sqrt{\frac{1}{n_1} + \frac{1}{n_2}} } $$ has a normal distribution with zero mean and variance $1$.

From the properties of the sampling distribution of the mean and the sampling distribution of the variance for normal populations, we know that the sampling mean and the sampling variance are independent random variables. In this way, we can apply the definition of t-Student distribution to obtain that the random variable $$T = \frac{(\overline{X}-\overline{Y})-(\mu_1-\mu_2)}{s_p\sqrt{\frac{1}{n_1}+\frac{1}{n_2}}}$$ which has t-Student distribution with $n_1+n_2-2$ degrees of freedom. Here, $s_p$ is the pooled standard deviation, which is given by $$s_p=\sqrt{\frac{(n_1-1)s_1^2+(n_2-1)s_2^2}{n_1+n_2-2}}$$

where

  • $s_1^2$: sample variance from population 1.

  • $s_2^2$: sample variance from population 2.

To perform the test for equality of two means with equal but unknown variances, we must perform the following steps:

1. Establish one of the hypotheses, for example:

$$\begin{cases}H_0: \mu_1=\mu_2 \cr H_1: \mu_1\neq\mu_2\end{cases} \quad \begin{cases}H_0:\mu_1=\mu_2 \cr H_1:\mu_1 \ > \ \mu_2 \end{cases} \ \hbox{ou} \ \begin{cases}H_0:\mu_1=\mu_2 \cr H_1:\mu_1 \ < \ \mu_2 \end{cases}$$

2. Set the significance level $\alpha$.

3. Determine the critical region.

  • If the test is two-sided, we determine the critical points $-t_{\alpha/2}$ and $t_{\alpha/2}$ such that $\mathbb{P}[T \ < \ -t_{\alpha/2}]=\mathbb{P}[T \ > \ t_{\alpha/2}]=\alpha/2$.

Figura6.5.44.svg

Figure 6.5.44: Representation of two-sided t-student distribution test

  • If the test is right-sided, we determine the critical point $t_{\alpha}$ such that $\mathbb{P}[T \ > \ t_{\alpha}]=\alpha$.

Figura6.5.14.svg

Figure 6.5.45: Representation of right-sided test of t-student distribution

  • If the test is left-sided, we determine the critical point $-t_{\alpha}$ such that $\mathbb{P}[T \ < \ -t_{\alpha}]=\alpha$.

Figura6.5.15.svg

Figure 6.5.46: Representation of left-sided test of t-student distribution

4. Calculate $T_{\text{obs}}$ which is the value of the variable $T$ under the null hypothesis. How $$T=\frac{(\overline{x}-\overline{y})-(\mu_1-\mu_2)}{s_p\sqrt{\frac{1}{n_1}+\frac{1}{n_2}}}$$

we have to $T_{\text{obs}}$ is given by $$T_{\text{obs}}=\frac{(\overline{x}-\overline{y})}{s_p\sqrt{\frac{1}{n_1}+\frac{1}{n_2}}}.$$

5. Criteria:

  • Two-sided test: If $T_{\text{obs}} \ < \ -t_{\alpha/2}$ or $T_{\text{obs}} \ > \ t_{\alpha/2}$, we reject $H_0$. Otherwise, we do not reject $H_0$.

  • Right-sided test: If $T_{\text{obs}} \ > \ t_{\alpha}$ we reject $H_0$. Otherwise, we do not reject $H_0$.

  • Left-sided test: If $T_{\text{obs}} \ < \ -t_{\alpha}$ we reject $H_0$. Otherwise, we do not reject $H_0$.

6. The p-value is determined by $$\text{p-valor} = \mathbb{P}[|T| \ > \ |T_{\text{obs}}| | H_0] = 2\mathbb{P}[T \ > \ |T_{\text{obs}}| |H_0].$$

whether the test is two-sided. If the test is right-sided, the p-value is given by $$\text{p-valor} = \mathbb{P}[T \ > \ T_{\text{obs}} | H_0]$$

and if the test is left-sided, the p-value is given by $$\text{p-valor} = \mathbb{P}[T \ < \ T_{\text{obs}} | H_0].$$

7. As we saw in Section 4.6.2, if we consider b the number of degrees of freedom, that is, $b=n_1+n_2-2$, the confidence interval for the difference between two means with unknown but equal variances is given by $$IC(\mu_1-\mu_2,1-\alpha)=\left((\overline{X}-\overline{Y})-t_{(b,\alpha/2)}s_p\sqrt{\frac{1}{n_1}+\frac{1}{n_2}};\ (\overline{X}-\overline{Y})+t_{(b,\alpha/2)}s_p\sqrt{\frac{1}{n_1}+\frac{1}{n_2}}\right)$$

whether the test is two-sided. In the case where the test is right-sided, the confidence interval is given by

$$IC(\mu_1-\mu_2,1-\alpha)=\left((\overline{X}-\overline{Y})-t_{(b,\alpha)}s_p\sqrt{\frac{1}{n_1}+\frac{1}{n_2}};\ \infty\right)$$

and, if the test is left-sided, the confidence interval will be given by $$IC(\mu_1-\mu_2,1-\alpha)=\left(-\infty;\ (\overline{X}-\overline{Y})+t_{(b,\alpha)}s_p\sqrt{\frac{1}{n_1}+\frac{1}{n_2}}\right).$$

8. Type II error is calculated by accepting $H_0$ when it is false ($H_1$ is true).

Suppose, for example, that the null hypothesis is false and that the true difference between the means is $\Delta = \mu_1-\mu_2$. So, analogously to the case of a sample, we have $$\frac{\overline{X_1}-\overline{X_2}}{S_p\sqrt{\frac{1}{n_1}+\frac{1}{n_2}}}$$

has distribution $t$ non-central, with $n_1+n_2-2$ degrees of freedom and non-centrality parameter $$\frac{\Delta}{\sigma\sqrt{\frac{1}{n_1}+\frac{1}{n_2}}}.$$

With this, we conclude that the type II error is given by

  • $\beta = \psi(t_{\alpha/2})-\psi(-t_{\alpha/2})$ whether the test is two-sided;

  • $\beta = \psi(t_{\alpha})$ whether the test is right-sided;

  • $\beta = 1-\psi(-t_{\alpha})$ whether the test is left-tailed.

where $\psi$ is the cumulative distribution function of the distribution $t$ not central with $n_1+n_2-2$ degrees of freedom and non-centrality parameter $\frac{\Delta}{\sigma\sqrt{\frac{1}{n_1}+\frac{1}{n_2}}}$.

9. The power of the test is calculated as 1 minus the probability of type II error, i.e. $$P = 1-\beta$$

We use the Action software to calculate power (given the sample size) or calculate the sample size necessary for the test to detect a certain difference between the differences between the means, with a certain power. In Action, we have as parameters the size of the first sample ($n_1$), the size of the second sample ($n_2$), the difference to be detected ($\Delta$), the power ($P$), the level of significance ($\alpha$) and the standard deviation ($\sigma$). So, to calculate the power of the test, we throw in the values of $n_1,n_2,\Delta,\alpha$ and $\sigma$ and we are provided with the power of testing. The formulas used to calculate power are $$P=1-\Psi(t_{\alpha/2})+\Psi(-t_{\alpha/2})$$

for the two-sided test, $$P = \Psi(-t_{\alpha})$$

for the left-sided test and $$P = 1-\Psi(t_{\alpha})$$

for the right-sided test. Here $\Psi$ is the cumulative distribution function of the distribution $t$ not central with $n_1+n_2-2$ degrees of freedom and non-centrality parameter $\varphi = \frac{\Delta}{\sigma\sqrt{\frac{1}{n_1}+\frac{1}{n_2}}}$.

To calculate the sample size necessary for the test to detect a pre-determined difference between the null and alternative hypotheses, with a certain power, we simply enter the difference values $\Delta$, the standard deviation $\sigma$, the level of significance $\alpha$ and the power $P$. With this, Action provides us with the sample size value $n = n_1 = n_2$. The formulas used for each test are the same as above, just rewrite them isolating $n$.

Example 5.7.1.1

To illustrate the application of this hypothesis test, consider the data from two samples presented below and, at a significance level $\alpha = 0,05$, decide whether there is a significant difference between the population averages $\mu_1$ and $\mu_2$.

Group Measurement Group Measurement
1 18.8000 2 22.284
1 20.5040 2 21.901
1 18.6210 2 25.302
1 19.9190 2 22.447
1 21.1170 2 22.771
1 17.5910 2 22.057
1 18.7560 2 22.881
1 18.9770 2 17.968
1 20.3080 2 23.382
1 18.8990 2 21.043
1 20.8350 2 22.629
1 17.5270 2 22.86
1 17.0780 2 24.515
1 17.6200 2 22.426
1 21.4260 2 21.203
1 19.1690 2 24.62
1 19.2900 2 22.058
1 22.0590 2 23.15
1 18.5850 2 22.787
1 17.8900 2 24.009
1 18.7550 2 21.491
1 19.2030 2 22.699
1 18.4190 2 24.662
1 20.7640 2 21.983
1 21.0550 2 21.917
2 21.198
2 22.909
2 23.327
2 24.534
2 21.152

Table 6.5.23: Measurements of two samples of equal variances

Let’s test whether the means of samples 1 and 2 are the same or different, therefore

1. We establish the hypotheses

$$\begin{cases}H_0:\mu_1=\mu_2 \cr H_1:\mu_1\neq\mu_2\end{cases}$$

which are equivalent to the hypotheses

$$\begin{cases}H_0:\mu_1-\mu_2=0 \cr H_1:\mu_1-\mu_2\neq0\end{cases}$$

We have from the data that the mean and standard deviation of sample 1 are $\overline{x} = 19,3267$ and $s_1 = 1,36228$, respectively. The mean and standard deviation of sample 2 are $\overline{y} = 22,6055$ and $s_2 = 1,43822$, respectively. The size of each sample is $n_1 = 25$ and $n_2 = 30$. With this, we have that the pooled standard deviation is given by $$s_p=\sqrt{\frac{(25-1)(1,36228)^2+(30-1)(1,43822)^2}{25+30-2}}=1,40434.$$

2. For this example, we set the significance level $\alpha = 0,05$.

3. As the test is two-sided and knowing that the number of degrees of freedom is $b = n_1+n_2-2 = 53$, we find in the Distribution Table $t$ of Student the following critical values $-t_{0,025} = -2,005$ and $t_{0,025} = 2,005$.

4. We calculate the value of the statistic $T_{\text{obs}}$. $$T_{\text{obs}}=\frac{(19,3267-22,6055)}{1,40434\sqrt{\left(\frac{1}{25}+\frac{1}{30}\right)}}=-8,62.$$

5. How $T_{\text{obs}} \ < \ -2,005$, we reject the null hypothesis, that is, we reject the hypothesis that the means are equal.

6. Let’s now calculate the p-value. As the test is two-sided, we have to $$\text{p-valor} = \mathbb{P}[|T| \ > \ |T_{obs}||H_0] = 2\mathbb{P}[T \ > \ 8,62] = 1,15E - 11.$$

7. The confidence interval for the difference $\mu_1-\mu_2$ is given by $$IC(\mu_1-\mu_2,1-\alpha)=\left((\overline{X}-\overline{Y})-t_{(b,\alpha/2)}s_p\sqrt{\frac{1}{n_1}+\frac{1}{n_2}};(\overline{X}-\overline{Y})+t_{(b,\alpha/2)}s_p\sqrt{\frac{1}{n_1}+\frac{1}{n_2}}\right),$$

i.e. $$IC(\mu_1-\mu_2,1-\alpha)=(-4,041;-2,516).$$

The results obtained in Action are given in the following table.

Information Value
T-statistic -8.621733
Degrees of Freedom 53
P-value 1.151931e-11
Average of 1 19.32668
Average of 2 22.6055
Standard Deviation of 1 1.362278
Standard Deviation of 2 1.43822
Pooled Standard Deviation 1.40434
Size of 1 25
Size 2 30
Alternative Hypothesis Different from 0
Confidence Level 95%
Lower Limit -4.041599
Upper Limit -2.516041

Table 5.6.24: Test results for comparing two means (equal variances)

Let’s calculate the power of the test when accepting $H_0$ when it is false ($H_1$ is true), for a difference $\Delta = 3,2$ between the differences in the means. We will do this using the Action software. How $n_1 = 25$, $n_2 = 30$, $\alpha = 0,05$ and $s_p = 1,40434$, we have that the power calculation is given by

$$P=1-\Psi(z_{0,025})+\Psi(z_{0,025})=1-0+0=1$$

Figura6.5.47.svg

Figure 6.5.47: Test power curve

Suppose now that given the size of one of the samples $N = 30$, we want to calculate the other sample size needed to detect a difference $\Delta = 1,2$ between the null and alternative hypotheses with a power of at least $0,9$, with standard deviation $1,40434$.

The results obtained in Action are given in the following table.

Figura6.5.48.svg

Figure 6.5.48: Test power curve

We have that both samples must contain $30$ elements in the sample to have at least $0,9$ of power, with a difference $\Delta = 1,2$ and standard deviation $1,40434$.

6.5.7.2 Comparison of means: different variances

Let’s now see how to perform a test for equality of means with unknown and different variances ($\sigma_1^2\neq\sigma_2^2$).

For this we consider the variable $T$ such that $$T=\frac{(\overline{X}-\overline{Y})-(\mu_1-\mu_2)}{\sqrt{\frac{s_1^2}{n_1}+\frac{s_2^2}{n_2}}}\sim t_{\nu}$$

that is, the variable $T$ given has distribution $t$ of Student with $\nu$ degrees of freedom, where $$\nu=\frac{\left(\frac{s_1^2}{n_1}+\frac{s_2^2}{n_2}\right)^2}{\frac{\left(\frac{s_1^2}{n_1}\right)^2}{n_1-1}+\frac{\left(\frac{s_2^2}{n_2}\right)^2}{n_2-1}}.$$

In practice, we can follow the steps

1. Establish the hypotheses

$$\begin{cases}H_0:\mu_1 = \mu_2 \cr H_1:\mu_1\neq \mu_2\end{cases} \quad \begin{cases}H_0:\mu_1=\mu_2 \cr H_1:\mu_1 \ > \ \mu_2\end{cases} \ \hbox{ou} \ \begin{cases}H_0:\mu_1=\mu_2 \cr H_1:\mu_1 \ < \ \mu_2\end{cases}$$

or equivalent hypotheses

$$\begin{cases}H_0:\mu_1-\mu_2=0 \cr H_1:\mu_1-\mu_2\neq 0\end{cases} \quad \begin{cases} H_0:\mu_1-\mu_2=0 \cr H_1:\mu_1-\mu_2 \ > \ 0 \end{cases} \ \hbox{ou} \ \begin{cases}H_0:\mu_1-\mu_2=0 \cr H_1:\mu_1-\mu_2 \ < \ 0 \end{cases}$$

2. Set the significance level $\alpha$.

3. Determine the critical region.

  • If the test is two-sided, we must determine the critical points $-t_{\alpha/2}$ and $t_{\alpha/2}$ of distribution $t$ of Student with $\nu$ degrees of freedom such that $\mathbb{P}[T \ > \ t_{\alpha/2}]=\mathbb{P}[T \ < \ -t_{\alpha/2}]=\alpha/2$.

Figura6.5.13.svg

Figure 6.5.49: Representation of critical region of two-sided t-student distribution test

  • If the test is right-sided, we determine the critical point $t_{\alpha}$ such that $\mathbb{P}[T \ > \ t_{\alpha}]=\alpha$.

Figura6.5.14.svg

Figure 6.5.50: Representation of critical region of right-sided test of t-student distribution

  • If the test is left-sided, we determine the critical point $-t_{\alpha}$ such that $\mathbb{P}[T \ < \ -t_{\alpha}] = \alpha$.

Figura6.5.15svg

Figure 6.5.51: Representation of critical region of left-sided test of t-student distribution

4. Calculate under $H_0$,

$$T_{\text{obs}}=\frac{(\overline{x}-\overline{y})}{\sqrt{\frac{s_1^2}{n_1}+\frac{s_2^2}{n_2}}}.$$

5. Conclusion:

  • Two-sided test: If $T_{\text{obs}} \ < \ -t_{\alpha/2}$ or $T_{\text{obs}} \ > \ t_{\alpha/2}$, we reject $H_0$.Otherwise, we do not reject $H_0$.

  • Left-sided test: If $T_{\text{obs}} \ < \ -T_{\alpha}$ we reject $H_0$. Otherwise, we do not reject $H_0$.

  • Right-sided test: If $T_{\text{obs}} \ > \ T_{\alpha}$ we reject $H_0$. Otherwise, we do not reject $H_0$.

6. We have that the p-value is given by $$\hbox{p-valor} = \mathbb{P}[|t| \ > \ |T_{\text{obs}}||H_0]=2\mathbb{P}[t \ > \ |T_{\text{obs}}| | H_0]$$

whether the test is two-sided. If the test is right-sided, the p-value is given by $$\hbox{p-valor} = \mathbb{P}[t \ > \ T_{\text{obs}}|H_0]$$

and if the test is left-sided, the p-value is given by $$\hbox{p-valor} = \mathbb{P}[t \ < \ T_{\text{obs}}|H_0]$$

where $t$ has distribution $t$ of Student with $\nu$ degrees of freedom.

7. The confidence interval, as seen in Section 4.6.3 is given by $$IC(\mu_1-\mu_2,1-\alpha)=\left((\overline{X}-\overline{Y})-t_{(\nu,\alpha/2)}\sqrt{\frac{s_1^2}{n_1}+\frac{s_2^2}{n_2}};(\overline{X}-\overline{Y})+t_{(\nu,\alpha/2)}\sqrt{\frac{s_1^2}{n_1}+\frac{s_2^2}{n_2}}\right)$$

whether the test is two-sided. If the test is left-sided, the confidence interval is given by $$IC(\mu_1-\mu_2,1-\alpha)=\left(-\infty;(\overline{X}-\overline{Y})+t_{(\nu,\alpha)}\sqrt{\frac{s_1^2}{n_1}+\frac{s_2^2}{n_2}}\right)$$

and, if the test is right-sided, then the confidence interval is given by $$IC(\mu_1-\mu_2,1-\alpha)=\left((\overline{X}-\overline{Y})-t_{(\nu,\alpha)}\sqrt{\frac{s_1^2}{n_1}+\frac{s_2^2}{n_2}};\infty\right).$$

Example 5.7.2.1

Compare the sample means given in Example 5.6.1, assuming that the variances are unknown and different.

1. Initially we established the hypotheses

$$\begin{cases}H_0:\mu_1=\mu_2 \cr H_1:\mu_1\neq\mu_2\end{cases}$$

which are equivalent to the hypotheses

$$\begin{cases}H_0:\mu_1-\mu_2=0 \cr H_1:\mu_1-\mu_2\neq0\end{cases}$$

From the data, we have that the mean and standard deviation of sample 1 are $\overline{x} = 19,3267$ and $s_1 = 1,36228$, respectively. The mean and standard deviation of sample 2 are $\overline{y} = 24,4729$ and $s_2 = 2,8876$, respectively. The size of each sample is $n_1 = 25$ and $n_2 = 30$. Therefore, we have that the number of degrees of freedom is given by: $$\nu=\frac{\left(\frac{(1,36228)^2}{25}+\frac{(2,8876)^2}{30}\right)^2}{\frac{\left(\frac{(1,36228)^2}{25}\right)^2}{25-1}+\frac{\left(\frac{(2,8876)^2}{30}\right)^2}{30-1}}=42,86563.$$

2. We fix the significance level $\alpha = 0,05$.

3. As the test is two-sided and we have $\nu=42,86563$ degrees of freedom, it follows that the critical points are $-t_{0,025} = -2,017$ and $t_{0,025} = 2,017$.

4. We calculate the statistics $T_{\text{obs}}$. $$T_{\text{obs}}=\frac{(19,3267-24,4729)}{\sqrt{\left(\frac{(1,36228)^2}{25}+\frac{(2,8876)^2}{30}\right)}}=-8,6734.$$

5. How $T_{\text{obs}} \ < \ -2,017$, we reject the hypothesis that the averages $\mu_1$ and $\mu_2$ are the same.

The p-value is given by $$\text{p-valor}=\mathbb{P}[|t| \ > \ |T_{\text{obs}}||H_0]=2\mathbb{P}[t \ > \ |T_{\text{obs}}| |H_0]=5,53E - 11.$$

The confidence interval is $$IC(\mu_1-\mu_2,1-\alpha)=\left((\overline{X}-\overline{Y})-t_{(\nu,\alpha/2)}\sqrt{\frac{s_1^2}{n_1}+\frac{s_2^2}{n_2}};(\overline{X}-\overline{Y})+t_{(\nu,\alpha/2)}\sqrt{\frac{s_1^2}{n_1}+\frac{s_2^2}{n_2}}\right),$$

i.e. $$IC(\mu_1-\mu_2,1-\alpha)=(-6,3432;-3,9494).$$

See below the results obtained by the software Action.

Information Value
T-statistic -8.671819
Degrees of Freedom 42.86563
P-value 5.561165e-11
Average of 1 19.32668
Average of 2 24.47288
Standard Deviation of 1 1.362278
Standard Deviation of 2 2.887603
Pooled Standard Deviation 1.40434
Size of 1 25
Size 2 30
Alternative Hypothesis Different from 0
Confidence Level 95%
Lower Limit -6.343187
Upper Limit -3.949365

Table 5.6.25: Test results for comparing two means (different and unknown variances)

6.5.8 Paired t-test

To perform equality of variance tests and mean tests, we need the two populations to be independent. However, in practice, we have some situations where populations are not independent. In an inter-laboratory comparison situation where two laboratories measure the same part, for example, the measurements between the laboratories are not independent. In this case, we use the test $t$ paired.

Let us consider two dependent samples $X_1,\ldots,X_n$ and $Y_1,\ldots,Y_n$. In this case we will consider paired observations, that is, we can consider that we actually have a sample of pairs $(X_1,Y_1), \ldots, (X_n,Y_n)$. Let’s define $D_i = X_i-Y_i$, for $i = 1,2,\ldots,n$. This way we will obtain the sample $D_1,\ldots,D_n$, resulting from the differences between the values of each pair. Here, although the samples are dependent, we will consider that $D_i\sim N(\mu_D,\sigma_D^2)$.

To perform the test $t$ paired we must first establish one of the hypotheses

$$\begin{cases}H_0:\mu_D=0 \cr H_1:\mu_D\neq 0\end{cases} \quad \begin{cases} H_0:\mu_D=0 \cr H_1:\mu_D \ > \ 0\end{cases} \ \hbox{ou} \ \begin{cases}H_0:\mu_D=0 \cr H_1:\mu_D \ < \ 0\end{cases}$$

The parameter $\mu_D$ will be estimated by the sample mean of the differences, that is, $\overline{D}$, The parameter $\sigma_D^2$ will be estimated by the sampling variance of the differences, that is, $$s_D^2=\frac{\sum_{i=1}^n(D_i-\overline{D})^2}{n-1}.$$

The test will be performed by the expression $$T=\frac{\overline{D}-\mu_D}{\frac{s_D}{\sqrt{n}}}$$

that under $H_0$ follows a distribution $t$ of Student with $n - 1$ degrees of freedom. Everything that was said for the test $t$ common serves for the test $T$ paired, just replace the average with $\mu_D$ and the sample standard deviation per $s_D$. With this, we have that at a level of significance $\alpha$:

1. Critical points are determined by $t_{\alpha/2}$ and $-t_{\alpha/2}$ for the bilateral case, $t_{\alpha}$ for the right-sided case and $-t_{\alpha}$ for the one-sided one on the left.

2. We calculate under the null hypothesis, the value $$T_{\text{obs}}=\frac{\overline{D}-\mu_D}{\frac{s_D}{\sqrt{n}}}$$

3. Criteria:

  • Two-sided test: if $T_{\text{obs}} \ > \ t_{\alpha/2}$ or $T_{obs} \ < \ -t_{\alpha/2}$ we reject $H_0$. Otherwise, we do not reject $H_0$.

Figura6.5.13.svg

Figure 6.5.52: Representation of critical region of two-sided t-student distribution test

  • Right-sided test: if $T_{\text{obs}} \ > \ t_{\alpha}$ we reject $H_0$. Otherwise, we do not reject $H_0$.

Figura6.5.14.svg

Figure 6.5.53: Representation of critical region of right-sided test of t-student distribution

  • Left-sided test: if $T_{\text{obs}} \ < \ -t_{\alpha}$ we reject $H_0$. Otherwise we will not reject $H_0$.

Figura6.5.15svg

Figure 6.5.54: Representation of critical region of left-sided test of t-student distribution

4. The p-value in the bilateral case is given by $$\text{p-valor} = \mathbb{P}[|t| \ > \ |T_{\text{obs}}||H_0] = 2\mathbb{P}[t \ > \ |T_{\text{obs}}| | H_0].$$

If the test is right-sided, the p-value is given by $$\text{p-valor} = \mathbb{P}[t \ > \ T_{\text{obs}}|H_0]$$

and if the test is left-sided, the p-value is given by $$\text{p-valor} = \mathbb{P}[t \ < \ T_{\text{obs}}|H_0]$$

5. The confidence interval for the parameter $\mu_D$ is given by $$IC(\mu_D,1-\alpha)=\left(\overline{D}-t_{\alpha/2}\frac{s_D}{\sqrt{n}};\overline{D}+t_{\alpha/2}\frac{s_D}{\sqrt{n}}\right)$$

for the bilateral case. If the test is right-sided, the confidence interval for the parameter $\mu_D$ is given by $$IC(\mu_D,1-\alpha)=\left(\overline{D}-t_{\alpha}\frac{s_D}{\sqrt{n}};\infty\right)$$

and, if the test is left-tailed, the confidence interval for the parameter $\mu_D$ is given by $$IC(\mu_D,1-\alpha)=\left(-\infty;\overline{D}+t_{\alpha}\frac{s_D}{\sqrt{n}}\right).$$

6. The probability of type II error is given by $$\beta=\Psi(t_{\alpha/2})-\Psi(-t_{\alpha/2})$$

for the bilateral case and, for the right and left unilateral cases, the type II error probabilities are given, respectively, by $$\beta=\Psi(t_{\alpha})\quad \hbox{e}\quad \beta=1-\Psi(-t_{\alpha})$$

where $\Psi$ is the cumulative density function of the distribution $t$ with $n - 1$ degrees of freedom and non-centrality parameter $\frac{\delta\sqrt{n}}{s_D}$.

7. To calculate the power of the test or the sample size, we use the Action software in the same way as in the test $T$ common.

Example 5.8.1

Let us consider $X_1,\ldots,X_{20}$ a sample of measurements from the Company’s laboratory $A$ and $Y_1,\ldots,Y_{20}$ a sample of measurements from the Company’s laboratory $B$. The tests from both laboratories are carried out to the same standard, therefore, there is a correlation between them, that is, the samples are dependent. Evaluate the compatibility of measurements between the company’s laboratory $A$ and the company’s laboratory $B$.

Laboratory of Company A ($X_i$) Company B Laboratory ($Y_i$) Difference ($D_i$)
1,00552 0,01942 0,98610
-1,49928 -0,46512 -1,03416
0,21367 0,53218 -0,31851
0,44658 -0,14844 0,59502
0,62766 -0,60021 1,22787
0,31091 0,06495 0,24596
-0,83878 0,33013 -1,16891
-0,29054 0,12116 -0,41170
-0,08487 0,74269 -0,82756
-1,26465 -1,64232 0,37767
-0,06353 0,05497 -0,11850
-1,07632 0,76342 -1,83974
-1,34134 1,74131 -3,08265
-0,55062 -0,06392 -0,48670
1,61848 -1,88146 3,49994
0,50997 -0,76135 1,27132
0,76027 -0,23009 0,99036
0,68061 -1,16800 1,84861
-1,91464 0,88392 -2,79856
-0,20072 0,96512 -1,16584

Table 6.5.26: Two samples of measurements from the Company’s laboratory $A$ and the Company’s laboratory $B$

In this case, to minimize the impact of this correlation, we take the difference between the measurements from the two laboratories and apply a test $T$ paired.

We have to $\overline{D} = -0,110499$ and $s_D = 1,56908$ then, under $H_0$, $$T_{\text{obs}}=\frac{-0,11}{\frac{1,57}{\sqrt{20}}}=-0,31$$

Considering $\alpha = 0,05$, we find in the table $t$ of Student with $19$ degrees of freedom critical values $-t_{0,025} = -2,093$ and $t_{0,025} = 2,093$. So, how $-2,093 \ < \ T_{\text{obs}} \ < \ 2,093$, we can say that we have no evidence to reject the hypothesis that the means are equal.

The p-value is given by $$\text{p-valor}=\mathbb{P}[|t| \ > \ |T_{\text{obs}}||H_0]= 2\mathbb{P}[t \ > \ |T_{\text{obs}}| | H_0]=0,7562.$$

The confidence interval is given by $$IC(\mu_D,0,95)=\left(-0,1105-2,093\frac{1,569}{\sqrt{20}};-0,1105+2,093\frac{1,569}{\sqrt{20}}\right)=(-0,8449;0,6239).$$

See below the results obtained by the software Action.

Information Value
T-statistic -0.3149408
Degrees of Freedom 19
P-value 0.7562392
Average of 1 -0.147581
Average of 2 -0.037082
Standard Deviation of differences 1.569078
Sample Size 20
Alternative Hypothesis Different from 0
Confidence Level 95%
Lower Limit -0.84485
Upper Limit 0.623852

Table 5.6.27: Test results for comparing two means (paired t-test)

Let’s use Action to calculate the test’s power to detect a difference $\delta = 1,2$ between the real and the hypothetical value. Then entering the values $n = 20$, $\delta = 1,2$, $\sigma = 1,56908$ and $\alpha = 0,05$ we have as a result $P = 0,90024$.

The probability of type II error is given by $$\beta=\Psi(t_{0,025})-\Psi(-t_{-0,025})=0,099762$$

from which we conclude that the power of the test in detecting this difference is $$P=1-\beta=1-0,99762=0,90024.$$

See below the results obtained by the software Action.

Information Value
Power 0.9002383
Sample size 20
Difference 1.2
Significance level 0.05
Standard deviation 1.56908
Alternative Hypothesis Different

Table 6.5.28: Test power results for comparing two means (paired t-test)

Figura6.5.55.svg

Figure 6.5.55: Representation of the Paired T Test Power Curve

Example 5.8.2

In order to determine the effectiveness of an antipyretic medication, the body temperature (in degrees Celsius) of 20 individuals was measured. The medicine was then administered and after an hour the temperature was measured again. The results can be found in Table 6.5.27 below.

Individual Temperature before Temperature after
1 37.5 37.8
2 36 36.4
3 39 37.6
4 38 37.2
5 37.8 36.9
6 38.5 37.7
7 36.9 36.8
8 39.4 38.1
9 37.2 36.7
10 38.1 37.3
11 39.3 38
12 37.5 37.1
13 38.5 36.6
14 39 37.5
15 36.9 37
16 37 36.2
17 38.5 37.6
18 39 36.8
19 36.2 36.4
20 36.8 36.8

Table 6.5.29: Sample effects of an antipyretic medication

As we want to evaluate whether or not there was a decrease in the individuals' temperature and as there is a clear dependence between the samples before and after administration of the medication, since the samples are related to the same individuals, we must use the paired T test.

Since we want to evaluate the effectiveness of the medicine, we want to test the following hypotheses

$$\begin{cases}H_0:\mu_D = 0 \cr H_1:\mu_D \ > \ 0\end{cases}$$

because the differences $D_i$’s are calculated between the elements of the first sample and the second sample and, with the alternative hypothesis $H_1$, we are testing whether the average differences in the population before applying the medicine are greater than the average after application, that is, does the application of the medicine reduce the population average of temperatures?

Next, we calculate the differences $D_i = X_i - Y_i$.

Individual Difference Individual Difference
1 -0,3 11 1,3
2 -0,4 12 0,4
3 1,4 13 1,9
4 0,8 14 1,5
5 0,9 15 -0,1
6 0,8 16 0,8
7 0,1 17 0,9
8 1,3 18 2,2
9 0,5 19 -0,2
10 0,8 20 0

Table 6.5.30: Differences in body temperatures for each individual

From the table of differences, we have that the average of the differences is given by $\overline{D} = 0,73$ and the standard deviation of the differences is given by $s_D = 0,735634$. In this case, we have that the test statistic, under $H_0$ is given by $$T_{\text{obs}} = \frac{0,73}{\frac{0,735634}{\sqrt{20}}} = 4,438.$$

Considering $\alpha = 0,05$, we have the distribution $t$ of Student with $19$ degrees of freedom that $t_{0,05} = 1,729$. So, how $1,729 = t_{0,05} \ < \ 4,438 = T_{\text{obs}}$, we can say that we have evidence to reject the hypothesis that the averages between populations are equal, that is, we have evidence that the average temperature before administration of the medicine is higher than the average after. With this, we can assume that the medicine is efficient.

The p-value is given by $$\text{p-valor} = \mathbb{P}\left[t \ > \ T_{\text{obs}}|H_0\right] = \mathbb{P}\left[t \ > \ 4,438|H_0\right] = 1,41 \times 10^{-4}.$$

The confidence interval with level $0,95$, is given by $$IC(\mu_D,0,95) = \left(0,73 - 1,729\frac{0,735634}{\sqrt{20}};\infty\right) = \left(0,4455;\infty\right).$$

See below the results obtained by the Action software.

Information Value
T-statistic 4.437883
Degrees of Freedom 19
P-value 0.0001411638
Average Temperature before 37.855
Average temperature after 37.125
Standard Deviation of differences 0.7356343
Sample Size 20
Alternative Hypothesis Greater than 0
Confidence Level 95%
Lower Limit 0.44557
Upper Limit Infinity

Table 5.6.31: Test results for comparing two means (paired t-test)

Let’s use Action to calculate the test’s power to detect an average temperature difference $\delta = 0,6$ degrees between the real and hypothetical value. So, entering the values $n = 20$, $\delta = 0,6$, $\sigma = 0,735634$ and $\alpha = 0,05$ we have as a result $P = 0,96915$.

The probability of type II error is given by $$\beta=\Psi(t_{0,05})=0,03085$$

from which we conclude that the power of the test in detecting this difference is $$P=1-\beta=1-0,03085=0,96915.$$

See below the results obtained by the software Action.

Information Value
Power 0.9691524
Sample size 20
Difference 0.6
Significance level 0.05
Standard deviation 0.735634
Alternative Hypothesis Greater than

Table 6.5.32: Test power results for comparing two means (paired t-test)

Figura6.5.56.svg

Figure 6.5.56: Representation of the Paired T Test Power Curve

6.5.9 Test for comparing two proportions

Let us consider $X$ and $Y$ random variables that represent a certain characteristic of two populations with Bernoulli distribution with parameters $p_1$ and $p_2$ respectively.

Let us take two independent random samples, $X_1,\ldots,X_{n_1}$ and $Y_1,\ldots,Y_{n_2}$, of these populations. Each $X_i$, $i = 1,\ldots,n_1$ and each $Y_j$, $j = 1,\ldots,n_2$, has a Bernoulli distribution with parameters $p_1$ and $p_2$ respectively, that is,

$$X_1,\ldots,X_{n_1}\sim\hbox{Bernoulli}(p_1) \quad \text{e} \quad Y_1,\ldots,Y_{n_2}\sim\hbox{Bernoulli}(p_2)$$

with averages $p_1$ and $p_2$ and variances $\sigma_1^2 = p_1(1-p_1)$ and $\sigma_2^2 = p_2(1-p_2)$, respectively.

The variables $\hat{p}_1 = \overline{X}$ and $\hat{p}_2=\overline{Y}$ are maximum likelihood estimators for $p_1$ and $p_2$, respectively, and has an approximately normal sampling distribution: $$\hat{p}_1\sim N\left(p_1,\frac{p_1(1-p_1)}{n_1}\right)\quad\text{e}\quad\hat{p}_2\sim N\left(p_2,\frac{p_2(1-p_2)}{n_2}\right).$$

So, we have to $$\hat{p}_1-\hat{p}_2\sim N\left(p_1-p_2,\frac{p_1(1-p_1)}{n_1}+\frac{p_2(1-p_2)}{n_2}\right)$$

i.e. $$\frac{\hat{p}_1-\hat{p}_2-(p_1-p_2)}{\sqrt{\frac{p_1(1-p_1)}{n_1}+\frac{p_2(1-p_2)}{n_2}}}\sim N(0,1).$$

To perform the test for two proportions with Normal approximation, we will consider the null hypothesis $p_1 = p_2$. Thus, under the null hypothesis, $\hat{p}_1-\hat{p}_2$ has a normal distribution with a mean $\mu = 0$ and standard deviation $$\sigma=\sqrt{\frac{p_1(1-p_1)}{n_1}+\frac{p_2(1-p_2)}{n_2}}=\sqrt{\frac{p(1-p)}{n_1}+\frac{p(1-p)}{n_2}}$$

where $p = p_1 = p_2$.

Since we don’t know the value $p$, we will estimate it as a weighted average of $\hat{p}_1$ and $\hat{p}_2$: $$\hat{p}=\frac{n_1\hat{p}_1+n_2\hat{p}_2}{n_1+n_2}$$

This is the value that will be used instead of $p$ for calculating $\sigma$. Therefore, we have to $$Z=\frac{\hat{p}_1-\hat{p}_2}{\sqrt{\frac{\hat{p}(1-\hat{p})}{n_1}+\frac{\hat{p}(1-\hat{p})}{n_2}}}\sim N(0,1)$$

With this information, let’s look at the standard steps to construct a hypothesis test for two proportions:

1. Establish any of the hypotheses

$$\begin{cases}H_0:p_1=p_2 \cr H_1:p_1\neq p_2\end{cases} \quad \begin{cases}H_0:p_1=p_2 \cr H_1:p_1 \ > \ p_2\end{cases} \ \hbox{ou} \ \begin{cases}H_0:p_1=p_2 \cr H_1:p_1 \ < \ p_2\end{cases}$$

i.e.

$$\begin{cases}H_0:p_1-p_2=0 \cr H_1:p_1-p_2\neq0\end{cases} \quad \begin{cases}H_0:p_1-p_2=0 \cr H_1:p_1-p_2 \ > \ 0\end{cases} \ \hbox{ou} \ \begin{cases}H_0:p_1-p_2=0 \cr H_1:p_1-p_2 \ < \ 0\end{cases}$$

2. Set the significance level $\alpha$.

3. Determine the critical region.

  • If the test is two-sided, we must determine the critical points $Z_{\alpha/2}$ and $-Z_{\alpha/2}$ such that $\mathbb{P}[Z \ > \ Z_{\alpha/2}]=\mathbb{P}[Z \ < \ -Z_{\alpha/2}]=\alpha/2$.

Figura6.5.57.svg

Figure 6.5.57: Representation of the two-sided normal distribution test

  • If the test is right-sided, we must determine the critical point $Z_{\alpha}$ such that $\mathbb{P}[Z \ > \ Z_{\alpha}]=\alpha$.

Figura6.5.58.svg

Figure 6.5.58: Representation of the right-sided test of normal distribution

  • If the test is left-sided, we determine the critical point $-Z_{\alpha}$ such that $\mathbb{P}[Z \ < \ -Z_{\alpha}]=\alpha$.

Figura6.5.59.svg

Figure 6.5.59: Representation of the left-sided test of normal distribution

4. Calculate the value of $\hat{p}$.

5. Calculate, under the null hypothesis, the value $$Z_{\text{obs}}=\frac{\hat{p}_1-\hat{p}_2}{\sqrt{\frac{\hat{p}(1-\hat{p})}{n_1}+\frac{\hat{p}(1-\hat{p})}{n_2}}}$$

6. Criteria:

  • For the bilateral case, if $Z_{\text{obs}} \ > \ z_{\alpha/2}$ or $Z_{\text{obs}} \ < \ -z_{\alpha/2}$, we reject $H_0$. Otherwise, we do not reject $H_0$.

  • For the right-sided case, if $Z_{\text{obs}} \ > \ z_{\alpha}$, we reject $H_0$. Otherwise, we do not reject $H_0$.

  • For the left-sided case, if $Z_{\text{obs}} \ < \ -z_{\alpha}$, we reject $H_0$. Otherwise, we do not reject $H_0$.

7. To calculate the power needed for the two-proportion test to detect the difference between the proportions $p_1$ and $p_2$, we use the Action software. The Action receives as parameters the size of the first sample ($n_1$), the size of the second sample ($n_2$), the propositions ($p_1$) and ($p_2$), the value of power ($P$) and the level of significance ($\alpha$). The formulas used are given by $$1-\Phi\left(z_{\alpha/2}-(2\arcsin(\sqrt{p_1})-2\arcsin(\sqrt{p_2}))\sqrt{\frac{n_1n_2}{n_1+n_2}}\right)+$$

$$\qquad\qquad+\Phi\left(-z_{\alpha/2}-(2\arcsin(\sqrt{p_1})-2\arcsin(\sqrt{p_2}))\sqrt{\frac{n_1n_2}{n_1+n_2}}\right)$$

for the two-sided test, $$\Phi\left(-z_{\alpha}-(2\arcsin(\sqrt{p_1})-2\arcsin(\sqrt{p_2}))\sqrt{\frac{n_1n_2}{n_1+n_2}}\right)$$

for the left-sided test and $$1-\Phi\left(z_{\alpha}-(2\arcsin(\sqrt{p_1})-2\arcsin(\sqrt{p_2}))\sqrt{\frac{n_1n_2}{n_1+n_2}}\right)$$

for the right-sided test.

To calculate the sample size necessary for the test to detect a difference between the proportions $p_1$ and $p_2$, with a given power, we just need to enter the values of the proportions $p_1$ and $p_2$, of power $P$ and the level of significance $\alpha$. With this, Action provides us with the value of the sample sizes. The formulas used follow those above, isolating $n$ depending on the other parameters.

Example 5.9.1

A company that provides economic advisory services to other companies is interested in comparing the rate of complaints about its services in two of its offices in two different cities. Suppose the company randomly selected $100$ services performed by the city office $A$ and it was found that in $12$ there was some kind of complaint from them. From the city B office, they were selected $120$ services and $18$ received some type of complaint. The company wants to know whether these results are sufficient to conclude that the two offices have a significant difference between their approval rates.

First, let’s see that the sample proportions of approval for city office services $A$ and $B$ are, respectively, $\hat{p}_1 = 0,88$ and $\hat{p}_2 = 0,85$.

1. We want to test the following hypotheses:

$$\begin{cases}H_0:p_1=p_2 \cr H_1:p_1\neq p_2\end{cases}$$

i.e.

$$\begin{cases}H_0:p_1-p_2=0 \cr H_1:p_1-p_2\neq 0\end{cases}$$

2. Let’s set the significance level $\alpha = 0,05$.

3. How $\alpha = 0,05$, we have to $-z_{\alpha/2} = -1,96$ and $z_{\alpha/2} = 1,96$.

4. How $n_1 = 100$, $n_2 = 120$, $\hat{p}_1 = 0,88$ and $\hat{p}_2 = 0,85$, we have to $$\hat{p}=\frac{n_1\hat{p}_1+n_2\hat{p}_2}{n_1+n_2}=\frac{100\times 0,88+120\times 0,85}{220}=\frac{190}{220}=0,864.$$

5. Thus, under the null hypothesis, we have $$Z_{\text{obs}}=\frac{\hat{p}_1-\hat{p}_2}{\sqrt{\frac{\hat{p}(1-\hat{p})}{n_1}+\frac{\hat{p}(1-\hat{p})}{n_2}}}=\frac{0,03}{0,0464}=0,645.$$

6. Conclusion: how $-1,96 \ < \ Z_{\text{obs}} = 0,645 \ < \ 1,96$ the null hypothesis of equality between proportions should not be rejected based on the sample data obtained. Thus, at the level of significance of $5%$, there is evidence that approval rates on services provided by the company’s offices in cities $A$ and $B$ are the same.

See below the results obtained by the software Action.

Quantity Proportions
Success 88 0.88
Failure 12 0.12

Table 6.5.33: Results - Data Set 1 (from city A)

Quantity Proportions
Success 102 0.85
Failure 18 0.15

Table 6.5.34: Results - Dataset 2 (from city B)

Information Value
Z Statistics 0.6456331
P-value 0.518517
Success Proportion in Sample 1 0.88
Success Proportion in Sample 2 0.85
Alternative Hypothesis Different from 0
Confidence Level 95%
Lower Limit -0.06021159
Upper Limit 0.1202116

Table 5.6.35: Test results for comparing two proportions

7. Let’s calculate the power of the test to detect the difference between the proportions $p_1 = 0,88$ and $p_2 = 0,85$. For this, we use the Action software. Entering the values $n_1 = 100$, $n_2 = 120$, $p_1 = 0,88$, $p_2 = 0,85$, at a level of significance $\alpha = 0,05$, we are given the power $P = 0,099$.

Power is calculated below: $$P=1-\Phi\left(z_{\alpha/2}-(2\arcsin(\sqrt{p_1})-2\arcsin(\sqrt{p_2}))\sqrt{\frac{n_1n_2}{n_1+n_2}}\right)+$$

$$\qquad\qquad+\Phi\left(-z_{\alpha/2}-(2\arcsin(\sqrt{p_1})-2\arcsin(\sqrt{p_2}))\sqrt{\frac{n_1n_2}{n_1+n_2}} \right)=$$

$$=0,099522497$$

for the two-sided test.

↑