ztest - z-test

Syntax

h = ztest(x,m,sigma)
h = ztest(...,alpha)
h = ztest(...,alpha,tail)
h = ztest(...,alpha,tail,dim)
[h,p] = ztest(...)
[h,p,ci] = ztest(...)
[h,p,ci,zval] = ztest(...)

Description

h = ztest(x,m,sigma) performs a z-test of the null hypothesis that data in the vector x are a random sample from a normal distribution with mean m and standard deviation sigma, against the alternative that the mean is not m. The result of the test is returned in h. h = 1 indicates a rejection of the null hypothesis at the 5% significance level. h = 0 indicates a failure to reject the null hypothesis at the 5% significance level.

x can also be a matrix or an N-dimensional array. For matrices, ztest performs separate z-tests along each column of x and returns a vector of results. For N-dimensional arrays, ztest works along the first non-singleton dimension of x.

The test treats NaN values as missing data, and ignores them.

h = ztest(...,alpha) performs the test at the (100*alpha)% significance level. The default, when unspecified, is alpha = 0.05.

h = ztest(...,alpha,tail) performs the test against the alternative specified by the string tail. There are three options for tail:

tail must be a single string, even when x is a matrix or an N-dimensional array.

h = ztest(...,alpha,tail,dim) works along dimension dim of x. Use [] to pass in default values for alpha or tail.

[h,p] = ztest(...) returns the p-value of the test. The p-value is the probability, under the null hypothesis, of observing a value as extreme or more extreme of the test statistic

where is the sample mean, μ = m is the hypothesized population mean, σ is the population standard deviation, and n is the sample size. Under the null hypothesis, the test statistic will have a standard normal distribution, N(0,1).

[h,p,ci] = ztest(...) returns a 100*(1 – alpha)% confidence interval on the population mean.

[h,p,ci,zval] = ztest(...) returns the value of the test statistic.

Example

Simulate a random sample of size 100 from a normal distribution with mean 0.1 and standard deviation 1:

x = normrnd(0.1,1,1,100);

Test the null hypothesis that the sample comes from a standard normal distribution:

[h,p,ci] = ztest(x,0,1)
h =
     0
p =
    0.1391
ci =
   -0.0481    0.3439

The test fails to reject the null hypothesis at the default α = 0.05 significance level. Under the null hypothesis, the probability of observing a value as extreme or more extreme of the test statistic, as indicated by the p-value, is greater than α. The 95% confidence interval on the mean contains 0.

Simulate a larger random sample of size 1000 from the same distribution:

y = normrnd(0.1,1,1,1000);

Test again if the sample comes from a normal distribution with mean 0:

[h,p,ci] = ztest(y,0,1)
h =
     1
p =
  5.5160e-005
ci =
    0.0655    0.1895

This time the test rejects the null hypothesis at the default α = 0.05 significance level. The p-value has fallen below α = 0.05 and the 95% confidence interval on the mean does not contain 0.

Because the p-value of the sample y is less than 0.01, the test will still reject the null hypothesis when the significance level is lowered to α = 0.01:

[h,p,ci] = ztest(y,0,1,0.01)
h =
     1
p =
  5.5160e-005
ci =
    0.0461    0.2090

This example will produce slightly different results each time it is run, because of the random sampling.

See Also

ttest, ttest2

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS