A two proportion z-test is used to determine if there is a statistically significant difference between two population proportions.
This test uses the following null hypothesis:
- H0: μ1 = μ2 (the two population proportions are equal)
The alternative hypothesis can be either two-tailed, left-tailed, or right-tailed:
- H1 (two-tailed): π1 ≠ π2 (the two population proportions are not equal)
- H1 (left-tailed): π1 < π2 (population 1 proportion is less than population 2 proportion)
- H1 (right-tailed): π1 > π2 (population 1 proportion is greater than population 2 proportion)
We use the following formula to calculate the test statistic z:
z = (p1-p2) / √
where p1 and p2 are the sample proportions, n1 and n2 are the sample sizes, and where p is the total pooled proportion calculated as:
p = (p1n1 + p2n2)/(n1+n2)
If the p-value that corresponds to the test statistic z is less than your chosen significance level (common choices are 0.10, 0.05, and 0.01) then you can reject the null hypothesis.
The following example shows how to perform a two proportion z-test in SAS.
Example: Two Proportion Z-Test in SAS
Suppose we want to know if there is a difference in the proportion of residents who support a certain law in county A compared to the proportion who support the law in county B.
To test this, we collect a random sample of 50 residents from each county and count how many support the law.
The following code shows how to create a dataset that summarizes the number of residents that support the law from each county:
/*create dataset*/ data my_data; input county $ status $ count; datalines; A Support 34 A Reject 16 B Support 29 B Reject 21 ; run; /*view dataset*/ proc print data=my_data;
We can then use the PROC FREQ statement with the option riskdiff(equal var = null) to perform the two proportion z-test:
/*perform two proportion z-test*/ proc freq data=my_data; weight count; tables county * status / riskdiff(equal var = null); run;
From the Risk Difference Test table in the output we can see the following information:
- z-test statistic: -1.0356
- two-sided p-value: 0.3004
This particular two proportion z-test used the following hypotheses:
- H0: π1 = π2 (the two population proportions are equal)
- H1: π1 ≠ π2 (the two population proportions are not equal)
Since the p-value in the output is not less than 0.05, we fail to reject the null hypothesis.
This means we do not have sufficient evidence to say that the proportion of residents who support this law is different between the two counties.
The following tutorials explain how to perform other common statistical tests in SAS: