**[R] prtest** -- Tests of proportions

__Syntax__

One-sample test of proportion

**prtest** *varname* **==** *#p* [*if*] [*in*] [**,** *onesampleopts*]

Two-sample test of proportions using groups

**prtest** *varname* [*if*] [*in*] **,** **by(***groupvar***)** [*twosamplegropts*]

Two-sample test of proportions using variables

**prtest** *varname1* **==** *varname2* [*if*] [*in*] [**,** __l__**evel(***#***)**]

Immediate form of one-sample test of proportion

**prtesti** *#obs1* *#p1* *#p2* [**,** __l__**evel(***#***)** __c__**ount**]

Immediate form of two-sample test of proportions

**prtesti** *#obs1* *#p1* *#obs2* *#p2* [**,** __l__**evel(***#***)** __c__**ount**]

*onesampleopts* Description
-------------------------------------------------------------------------
Main
__l__**evel(***#***)** confidence level; default is **level(95)**
**cluster(***varname***)** variable defining the clusters
**rho(***#***)** intraclass correlation
-------------------------------------------------------------------------

*twosamplegropts* Description
-------------------------------------------------------------------------
Main
* **by(***groupvar***)** variable defining the groups
__l__**evel(***#***)** confidence level; default is **level(95)**
**cluster(***varname***)** variable defining the clusters
**rho(***#***)** common intraclass correlation
**rho1(***#***)** intraclass correlation for group 1
**rho2(***#***)** intraclass correlation for group 2
-------------------------------------------------------------------------
* **by(***groupvar***)** is required.

**by** is allowed with **prtest**; see **[D] by**.

__Menu__

__prtest__

**Statistics > Summaries, tables, and tests >** **Classical tests of**
**hypotheses > Proportion test**

__prtesti__

**Statistics > Summaries, tables, and tests >** **Classical tests of**
**hypotheses > Proportion test calculator**

__Description__

**prtest** performs tests on the equality of proportions using large-sample
statistics. The test can be performed for one sample against a
hypothesized population value or for no difference in population
proportions estimated from two samples. Clustered data are supported.

**prtesti** is the immediate form of **prtest**; see immed.

__Options for prtest__

+------+
----+ Main +-------------------------------------------------------------

**by(***groupvar***)** specifies a numeric variable that contains the group
information for a given observation. This variable must have only
two values. Do not confuse the **by()** option with the **by** prefix; both
may be specified.

**level(***#***)** specifies the confidence level, as a percentage, for confidence
intervals. The default is **level(95)** or as set by **set level**.

**cluster(***varname***)** specifies the variable that identifies clusters. The
**cluster()** option is required to adjust the computation for
clustering.

**rho(***#***)** specifies the intraclass correlation for a one-sample test or the
common intraclass correlation for a two-sample test. The **rho()**
option is required to adjust the computation for clustering for a
one-sample test.

**rho1(***#***)** specifies the intraclass correlation of the first group for a
two-sample test using groups. The **rho()** option or both **rho1()** and
**rho2()** options are required to adjust the computation for clustering.

**rho2(***#***)** specifies the intraclass correlation of the second group for a
two-sample test using groups. The **rho()** option or both **rho1()** and
**rho2()** options are required to adjust the computation for clustering.

__Options for prtesti__

+------+
----+ Main +-------------------------------------------------------------

**level(***#***)** specifies the confidence level, as a percentage, for confidence
intervals. The default is **level(95)** or as set by **set level**.

**count** specifies that integer counts instead of proportions be used in the
immediate forms of **prtest**. In the first syntax, **prtesti** expects that
*#obs1* and *#p1* are counts -- *#p1* __<__ *#obs1* -- and *#p2* is a proportion.
In the second syntax, **prtesti** expects that all four numbers are
integer counts, that *#obs1* __>__ *#p1*, and that *#obs2* __>__ *#p2*.

__Remarks__

For one-sample tests of proportions with small sample sizes and to obtain
exact p-values, researchers should use **bitest**.

__Examples__

---------------------------------------------------------------------------
Setup
**. sysuse auto**

One-sample test of proportion
**. prtest foreign==.4**

One-sample test of proportion adjusted for clustering with clusters
defined by **rep78** and with an intraclass correlation of 0.4
**. prtest foreign==.4, cluster(rep78) rho(0.4)**

---------------------------------------------------------------------------
Setup
**. webuse cure**

Two-sample test of proportions using variables
**. prtest cure1==cure2**

---------------------------------------------------------------------------
Setup
**. webuse cure2**

Two-sample test that **cure** has same proportion for males and females
**. prtest cure, by(sex)**

----------------------------------------------------------------------------
Setup
**. webuse pneumoniacrt**

Two-sample test that **pneumonia** has same proportion for two vaccine
groups, adjusted for clustering with clusters defined by **cluster** and
with a common intraclass correlation of 0.02
**. prtest pneumonia, by(vaccine) cluster(cluster) rho(0.02)**

---------------------------------------------------------------------------
Immediate form of one-sample test of proportion
**. prtesti 50 .52 .70**

First two numbers are counts
**. prtesti 30 4 .7, count**

Immediate form of two-sample test of proportions
**. prtesti 30 .4 45 .67**

All numbers are counts
**. prtesti 30 4 45 17, count**

---------------------------------------------------------------------------

__Stored results__

One-sample **prtest** and **prtesti** store the following in **r()**:

Scalars
**r(N)** sample size
**r(P)** sample proportion
**r(se)** standard error of sample proportion
**r(lb)** lower confidence bound of sample proportion
**r(ub)** upper confidence bound of sample proportion
**r(z)** z statistic
**r(p_l)** lower one-sided p-value
**r(p)** two-sided p-value
**r(p_u)** upper one-sided p-value
**r(level)** confidence level

Cluster-adjusted one-sample **prtest** also stores the following in **r()**:

Scalars
**r(K)** number of clusters K
**r(M)** cluster size M
**r(rho)** intraclass correlation
**r(CV_cluster)** coefficient of variation for cluster sizes

Two-sample **prtest** and two-sample **prtesti** store the following in **r()**:

Scalars
**r(N1)** sample size of population one
**r(N2)** sample size of population two
**r(P1)** sample proportion for population one
**r(P2)** sample proportion for population two
**r(P_diff)** difference of proportions
**r(se1)** standard error of population-one sample proportion
**r(se2)** standard error of population-two sample proportion
**r(se_diff)** standard error of the difference of proportions
**r(se_diff0)** standard error of the difference of proportions
under H_0
**r(lb1)** lower confidence bound of population-one sample
proportion
**r(ub1)** upper confidence bound of population-one sample
proportion
**r(lb2)** lower confidence bound of population-two sample
proportion
**r(ub2)** upper confidence bound of population-two sample
proportion
**r(lb_diff)** lower confidence bound of the difference of
proportions
**r(ub_diff)** upper confidence bound of the difference of
proportions
**r(z)** z statistic
**r(p_l)** lower one-sided p-value
**r(p)** two-sided p-value
**r(p_u)** upper one-sided p-value
**r(level)** confidence level

Cluster-adjusted two-sample **prtest** using the **by()** option also stores the
following in **r()**:

Scalars
**r(K1)** population-one number of clusters K_1
**r(K2)** population-two number of clusters K_2
**r(M1)** population-one cluster size M_1
**r(M2)** population-two cluster size M_2
**r(rho)** common intraclass correlation
**r(rho1)** population-one intraclass correlation
**r(rho2)** population-two intraclass correlation
**r(CV_cluster1)** population-one coefficient of variation for cluster
sizes
**r(CV_cluster2)** population-two coefficient of variation for cluster
sizes