h = ztest(x,m,sigma) returns
a test decision for the null hypothesis that the data in the vector x comes
from a normal distribution with mean m and a
standard deviation sigma, using the z-test.
The alternative hypothesis is that the mean is not m.
The result h is 1 if the test
rejects the null hypothesis at the 5% significance level, and 0 otherwise.

h= ztest(x,m,sigma,Name,Value) returns
a test decision for the z-test with additional
options specified by one or more name-value pair arguments. For example,
you can change the significance level or conduct a one-sided test.

Load the sample data. Create a vector containing the first
column of the students' exam grades data.

load examgrades;
x = grades(:,1);

Test the null hypothesis that the data comes from a normal
distribution with mean m = 65 and standard deviation sigma
= 10, against the alternative that the mean is greater than
65.

[h,p] = ztest(x,65,10,'Tail','right')

h =
1
p =
2.8596e-28

The returned value of h = 1 indicates that ztest rejects
the null hypothesis at the default 5% significance level, in favor
of the alternative hypothesis that the population mean is greater
than 65.

Population standard deviation, specified as a scalar value.

Data Types: single | double

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments.
Name is the argument
name and Value is the corresponding
value. Name must appear
inside single quotes (' ').
You can specify several name and value pair
arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Tail','right','Alpha',0.01 specifies
a right-tailed hypothesis test at the 1% significance level.

Significance level of the hypothesis test, specified as the
comma-separated pair consisting of 'Alpha' and
a scalar value in the range (0,1).

Example: 'Alpha',0.01

Data Types: single | double

'Dim' — Dimensionfirst nonsingleton dimension (default) | positive integer value

Dimension of the input matrix along which to test the means,
specified as the comma-separated pair consisting of 'Dim' and
a positive integer value. For example, specifying 'Dim',1 tests
the column means, while 'Dim',2 tests the row means.

p-value of the test, returned as a scalar
value in the range [0,1]. p is the probability
of observing a test statistic as extreme as, or more extreme than,
the observed value under the null hypothesis. Small values of p cast
doubt on the validity of the null hypothesis.

Confidence interval for the true population mean, returned as
a two-element vector containing the lower and upper boundaries of
the 100 × (1 – Alpha)% confidence
interval.

The z-test is a parametric
hypothesis test used to determine whether a sample data set comes
from a population with a particular mean. The test assumes the sample
data comes from a population with a normal distribution and a known
standard deviation.

The test statistic is

$$z=\frac{\overline{x}-\mu}{\sigma /\sqrt{n}},$$

where $$\overline{x}$$ is the sample mean, μ is
the population mean, σ is the population standard deviation,
and n is the sample size. Under the null hypothesis,
the test statistic has a standard normal distribution.

The first nonsingleton dimension is the first
dimension of an array whose size is not equal to 1. For example, if x is
a 1-by-2-by-3-by-4 array, then the second dimension is the first nonsingleton
dimension of x.