To perform a z-test, you should compute the *standard score* (or *z-score*) of your sample :math:`X`.
The *z-score*, noted :math:`Z`, characterizes how far from the population mean :math:`\mu` your sample mean :math:`\overline{x}` is, in unit of standard deviation :math:`\sigma`.
In this case, :math:`Z` technically follow a t-distribution (student test).
However, if :math:`n` is sufficiently large, the distribution followed by :math:`Z` is very close to a normal one.
So close that, using z-test in place of the student test to compute *p-values* leads to nominal differences (`source <https://stats.stackexchange.com/questions/625578/why-is-the-sample-standard-deviation-used-in-the-z-test>`__).
This exercice is inpired from `this video <https://www.youtube.com/results?search_query=ztest>`__*(be careful the video uses a wrong formula)*.
A complain was registered stating that the boys in the municipal school are underfed.
The average weight of boys of age 10 is 32kg with a standard deviation of 9kg.
A sample of 25 boys of age 10 from the school is selected. Their average weight is 29.5kg.
We want to check whether the complain is true or not with a confidence level of :math:`\alpha=0.05`.
**--- Solution ---**
Hypothesis:
*:math:`H_0` : No significant difference (:math:`\overline{x} \ge 32`), the boys from the are not underfed
*:math:`H_1` : There is significant difference (:math:`\overline{x} < 32`), the boys from the are underfed
..math::
Z=\frac{29.5-32}{9}=-0.2777778
From this z-score, the *p-value* is 0.3905915. As it is greater than 0.05, we cannot reject :math:`H_0`.
Thus, the boys from the are not underfed.
Two-tailed
^^^^^^^^^^^
This exercice is inpired from `this website <https://www.mathandstatistics.com/learn-stats/hypothesis-testing/two-tailed-z-test-hypothesis-test-by-hand>`__.
The USA mean public school yearly funding is $6800 per student per year, with a standard deviation of $400.
We want to assess if a certain state in the USA, Michigan, receives a significantly different amount of public school funding (per student) than the USA average,
with :math:`\alpha=0.05`. A sample of 1000 students reveals that in average, they received $6873.
*:math:`H_0` : No significant difference (:math:`\overline{x} = 6800`), Michigan receives the same amount of public school funding per student
*:math:`H_1` : There is significant difference (:math:`\overline{x} \ne 6800`), Michigan do not receives the same amount of public school funding per student
..math::
Z=\frac{6873-6800}{400}=0.1825
| The *p-value* associated with the left tail (using :math:`-Z` with the CDF) is 0.4275952.
| Thus, as we are doing a *two-tailed* z-test the *p-value* is :math:`2\times 0.4275952 = 0.8551904`.
| We multiply by two has the two tails of the normal law are symetric.
Since :math:`0.8551904 >> 0.05` we cannot reject the null hypothesis :math:`H_0`.
Thus, Michigan receives the same amount of public school funding per student.