Categories &

Functions List

Function Reference: ztest2

statistics: h = ztest2 (x1, n1, x2, n2)

statistics: h = ztest2 (x1, n1, x2, n2, Name, Value)

statistics: [h, p] = ztest2 (…)

statistics: [h, p, ci] = ztest2 (…)

statistics: [h, p, ci, stats] = ztest2 (…)

Two proportions Z-test.

If x1 and n1 are the counts of successes and trials in one sample, and x2 and n2 those in a second one, test the null hypothesis that the success probabilities p1 and p2 are the same. The result is h = 0 if the null hypothesis cannot be rejected at the significance level alpha, or h = 1 if it can.

Under the null, the test statistic approximately follows a standard normal distribution.

The size of h and p is the common size of x1, n1, x2, and n2, which must be scalars or of common size. A scalar input functions as a constant matrix of the same size as the other inputs.

[h, p] = ztest2 (…) returns the p-value. That is the probability of observing the given result, or one more extreme, by chance if the null hypothesis true.

[h, p, ci] = ztest2 (…) returns a 100 (1 - alpha)% confidence interval for p1 - p2, Newcombe’s hybrid score interval, which combines the Wilson score intervals of the two proportions. It has one row per test, and is one-sided for a one-sided test: [lower, 1] for 'right', [-1, upper] for 'left'.

[h, p, ci, stats] = ztest2 (…) also returns a structure with the following fields:

zvalthe value of the test statistic.
CohensHCohen’s h, the difference between the arcsine transforms 2 asin (sqrt (p1)) - 2 asin (sqrt (p2)) of the two estimated proportions.
CohensHCIits confidence interval, h -/+ z sqrt (1/n1 + 1/n2) with z the normal quantile at the level of the test, one row per test, within [-pi, pi] and one-sided as ci is.

[…] = ztest2 (…, Name, Value, …) specifies one or more of the following Name/Value pairs:

NameValue
'alpha'the significance level of h and the level of both confidence intervals. Default is 0.05.
'tail'a string specifying the alternative hypothesis
'both'p1 is not p2 (two-tailed, default)
'left'p1 is less than p2 (left-tailed)
'right'p1 is greater than p2 (right-tailed)

See also: chi2test, fishertest

Source Code: ztest2