proportionZTest
Performs a one-sample proportion z-test for whether the true proportion equals p0.
The null hypothesis is that the probability of success in each trial equals p0. The test computes a z-statistic using the standard error under the null hypothesis and compares it to the standard normal distribution. This is an asymptotic test appropriate when the sample size is large enough for the normal approximation to hold (commonly n * p0 >= 5 and n * (1 - p0) >= 5). For small samples, consider binomialTest instead.
The confidence interval is a Wald interval based on the observed proportion.
Example:
val result = proportionZTest(successes = 60, trials = 100, p0 = 0.5)
result.statistic // 2.0 (z-statistic)
result.pValue // 0.0455 (two-sided)
result.confidenceInterval // Wald 95% CI for the observed proportion
result.isSignificant() // true at alpha = 0.05Return
a TestResult containing the z-statistic, p-value, a Wald confidence interval for the observed proportion, and additional info with "observedProportion", "hypothesizedProportion", and "standardError".
Parameters
the number of observed successes. Must be in [0, trials].
the total number of trials. Must be positive.
the hypothesized proportion under the null hypothesis. Must be in (0, 1). Defaults to 0.5.
the direction of the alternative hypothesis. Defaults to Alternative.TWO_SIDED, which tests whether the true proportion differs from p0 in either direction.
the confidence level for the Wald confidence interval. Must be in (0, 1). Defaults to 0.95 (95%).
See also
for an exact test suitable for small sample sizes.
Performs a two-sample proportion z-test for whether two populations have the same proportion.
The null hypothesis is that the true proportions in both populations are equal. The test pools the two samples to estimate the common proportion, computes a z-statistic using the pooled standard error, and compares it to the standard normal distribution. This is an asymptotic test appropriate when both samples are large enough for the normal approximation.
The confidence interval for the difference in proportions uses the unpooled standard error (each sample's own observed proportion), which is the standard approach for proportion difference intervals.
Example:
val result = proportionZTest(
successes1 = 45, trials1 = 100,
successes2 = 30, trials2 = 80
)
result.statistic // z-statistic
result.pValue // two-sided p-value
result.confidenceInterval // 95% CI for the difference (p1 - p2)
result.isSignificant() // true if p < 0.05Return
a TestResult containing the z-statistic, p-value, a confidence interval for the proportion difference (p1 - p2), and additional info with "proportion1", "proportion2", "proportionDifference", "pooledProportion", and "standardError".
Parameters
the number of observed successes in the first sample. Must be in [0, trials1].
the total number of trials in the first sample. Must be positive.
the number of observed successes in the second sample. Must be in [0, trials2].
the total number of trials in the second sample. Must be positive.
the direction of the alternative hypothesis. Defaults to Alternative.TWO_SIDED, which tests whether the two proportions differ in either direction.
the confidence level for the confidence interval on the proportion difference. Must be in (0, 1). Defaults to 0.95 (95%).