Statistics: ztest2

### Function Reference: `ztest2`

statistics: h = ztest2 (x1, n1, x2, n2)
statistics: h = ztest2 (x1, n1, x2, n2, Name, Value)
statistics: [h, pval] = ztest2 (…)
statistics: [h, pval, zvalue] = 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 5% significance level, or h = 1 if the null hypothesis can be rejected at the 5% level.

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

The size of h, pval, and zvalue is the common size of x, 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, pval] = ztest2 (…)` returns the p-value. That is the probability of observing the given result, or one more extreme, by chance if the null hypothesisis true.

`[h, pval, zvalue] = ztest2 (…)` returns the value of the test statistic.

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

| Name | Value
--- | --- | ---
| `"alpha"` | the significance level. 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