[porto_container animation_duration=“1000” animation_delay=“0”][/porto_container]

One-tailed Z‑test

The Z‑test is used when you want to com­pare the means of two large sam­ples (>30 obser­va­tions). In a one-sided test, you test the null hypoth­e­sis (H0): µ1 ≥ µ2 or µ1 ≤ µ2. That is that the mean of pop1 is larger/smaller or equal to the mean of pop2.

The dif­fer­ence with a two sided Z‑test is thus that we have a rea­son to believe that the mean of one of the pop­u­la­tions (e.g. pop1) is larg­er or small­er than the oth­er. For exam­ple, you want to test if the mean of pop1 is larg­er than the mean of pop2. The alter­na­tive hypoth­e­sis (H1) is then µ1 > µ2, the mean of pop1 is larg­er than the mean of pop2. The null-hypoth­e­sis cov­ers all oth­er pos­si­bil­i­ties, µ1 ≤ µ2; the mean of pop1 is equal to or small­er than the mean of pop2.

You need to check the fol­low­ing assump­tions before pro­ceed­ing with the Z‑test:

  1. The obser­va­tions are independent
  2. The sam­ples have the same variance
  3. That the Cen­tral Lim­it The­o­rem holds true (it does if the sam­ple sizes > 30)

The Z‑test relies on the test sta­tis­tic Z, which is cal­cu­lat­ed by:



where  \overline{x}_1 and \overline{x}_2 are the means,  s_1^2 and s_2^2 are the vari­ances, and n_1 and n_2  are the sam­ple sizes of sam­ple 1 and 2, respectively.

The null hypoth­e­sis is reject­ed when Z > 1.645 and 2.33 at a sig­nif­i­cance lev­el of α = 0.05 and 0.01, respec­tive­ly. That is, you are cer­tain at a degree of 95 and 99 %, respec­tive­ly, that the null-hypoth­e­sis can be reject­ed; e.g. that the mean of pop1 is larg­er than the mean of pop2. If Z is neg­a­tive and beyond the lim­it of the crit­i­cal val­ue, the null-hypoth­e­sis can’t be reject­ed as the mean of pop2 is larg­er.


You want to test if the month­ly salaries of indus­tri­al work­ers are high­er in India com­pared to China.

  1. Con­struct the null-hypothesis

H0: the mean salary in India is equal to or less than the mean salary in Chi­na and (µIndia ≤ µChi­na)

Take a ran­dom sam­ple of at least 30 salaries of indus­tri­al work­ers from Chi­na and India

  1. Cal­cu­late the mean (\overline{x} ) and vari­ance (s^2 ) for each sam­ple, in this case:

3. Check that the vari­ances are equal
— Per­form a F‑test, cal­cu­late the F statistic
— Cal­cu­late the degrees of free­dom (v)
v_{china} = 45 - 1 = 44
v_{india} = 32 - 1 = 31

- Check the crit­i­cal val­ue for F at α=0.05 where v1 = 44 and v2 = 31 in a    table of crit­i­cal F val­ues: Fα=0.05 = 1.8–2.01

- Com­pare the cal­cu­lat­ed F sta­tis­tic with Fα=0.05

F < Fα=0.05 = 1.14 < 1.8

- Reject H0 or H

H0 can’t be reject­ed; the assump­tion of equal vari­ances holds true.

4. Cal­cu­late the Z statistic:

z_onetailed- Look up the crit­i­cal val­ue for Z at α = 0.05

In the case of crit­i­cal val­ues for Z we don’t have to check a table it is sim­ply Zα=0.05 = 1.645 for a one-sided Z test, inde­pen­dent of the degrees of free­dom of the sam­ples as the test relies on the Cen­tral Lim­it Theorem.

- Com­pare the cal­cu­lat­ed Z sta­tis­tic with Zα=0.05

Z > Zα=0.05 = ‑12.3 < 1.645

5. Reject H0 or H1

H0 can’t be reject­ed; the mean salary is not high­er in India com­pared to chi­na (µIndia < µChi­na)

We are less than 95 % cer­tain that the salaries of indus­tri­al work­ers in India are high­er com­pared to China.

6. Inter­pret the result

The mean salary is not high­er in India com­pared to china.

How to do it in R

#Function to calculate the Z statistic




One tailed Z test in depth

The one-tailed Z‑test works just like the two-tailed except that the bor­ders under the nor­mal curve of dif­fer­ences (d) between the means are altered. The only inter­est is if one of the means is larg­er or small­er than the oth­er, depend­ing on the alter­na­tive hypoth­e­sis (H1). There­fore, the null-hypoth­e­sis is only reject­ed if the cal­cu­lat­ed Z val­ue exceeds the crit­i­cal Z val­ue in one of the tails of the nor­mal dis­tri­b­u­tion of d’s. In order words, the null-hypoth­e­sis can’t be reject­ed if the cal­cu­lat­ed Z‑value falls with­in the oppo­site tail. Then, to set α=0.05 it is nec­es­sary to move the bor­der of the crit­i­cal Z value:

95 and 99 % of the d val­ues found from one tail over the cen­tre of the dis­tri­b­u­tion are found at Z = ± 1.645 and 2.33, respec­tive­ly. Beyond these bor­ders 5 and 1 %, respec­tive­ly, of the rest of the d val­ues are found, gath­ered in one tail.

Now, the null-hypoth­e­sis can, for exam­ple, be expressed as d ≤ 0. In this case, H0 can only be reject­ed if d is sta­tis­ti­cal sig­nif­i­cant­ly larg­er than 0 (d>0). This is the case when Z >1.645 or 2.33 depend­ing on α.

How to produce the graph in R


 mnorm<-function(my, sigma,x){


 for(i in 1:length(x)) {

 plot(x,p,ylab="",xlab="Difference between means (d)",type="n",las=1,bty="l",pch=19,yaxt="n")