statsmodels.stats.proportion.proportions_ztest¶

statsmodels.stats.proportion.
proportions_ztest
(count, nobs, value=None, alternative='twosided', prop_var=False)[source]¶ Test for proportions based on normal (z) test
 Parameters
 countinteger or array_like
the number of successes in nobs trials. If this is array_like, then the assumption is that this represents the number of successes for each independent sample
 nobsinteger or arraylike
the number of trials or observations, with the same length as count.
 valuefloat, array_like or None, optional
This is the value of the null hypothesis equal to the proportion in the case of a one sample test. In the case of a twosample test, the null hypothesis is that prop[0]  prop[1] = value, where prop is the proportion in the two samples. If not provided value = 0 and the null is prop[0] = prop[1]
 alternativestring in [‘twosided’, ‘smaller’, ‘larger’]
The alternative hypothesis can be either twosided or one of the one sided tests, smaller means that the alternative hypothesis is
prop < value
and larger meansprop > value
. In the two sample test, smaller means that the alternative hypothesis isp1 < p2
and larger meansp1 > p2
wherep1
is the proportion of the first sample andp2
of the second one. prop_varFalse or float in (0, 1)
If prop_var is false, then the variance of the proportion estimate is calculated based on the sample proportion. Alternatively, a proportion can be specified to calculate this variance. Common use case is to use the proportion under the Null hypothesis to specify the variance of the proportion estimate.
 Returns
 zstatfloat
test statistic for the ztest
 pvaluefloat
pvalue for the ztest
Notes
This uses a simple normal test for proportions. It should be the same as running the mean ztest on the data encoded 1 for event and 0 for no event so that the sum corresponds to the count.
In the one and two sample cases with twosided alternative, this test produces the same pvalue as
proportions_chisquare
, since the chisquare is the distribution of the square of a standard normal distribution.Examples
>>> count = 5 >>> nobs = 83 >>> value = .05 >>> stat, pval = proportions_ztest(count, nobs, value) >>> print('{0:0.3f}'.format(pval)) 0.695
>>> import numpy as np >>> from statsmodels.stats.proportion import proportions_ztest >>> count = np.array([5, 12]) >>> nobs = np.array([83, 99]) >>> stat, pval = proportions_ztest(count, nobs) >>> print('{0:0.3f}'.format(pval)) 0.159