**[R] ci** -- Confidence intervals for means, proportions, and variances

__Syntax__

Confidence intervals for means, normal distribution

**ci** __mean__**s** [*varlist*] [*if*] [*in*] [*weight*] [**,** *options*]

**cii** __mean__**s** *#obs* *#mean* *#sd* [**,** __l__**evel(***#***)**]

Confidence intervals for means, Poisson distribution

**ci** __mean__**s** [*varlist*] [*if*] [*in*] [*weight*]**,** __pois__**son** [__exp__**osure(***varname***)**
*options*]

**cii** __mean__**s** *#exposure* *#events***,** __pois__**son** [__l__**evel(***#***)**]

Confidence intervals for proportions

**ci** __prop__**ortions** [*varlist*] [*if*] [*in*] [*weight*] [**,** *prop_options* *options*]

**cii** __prop__**ortions** *#obs* *#succ* [**,** *prop_options* __l__**evel(***#***)**]

Confidence intervals for variances

**ci** __var__**iances** [*varlist*] [*if*] [*in*] [*weight*] [**,** __bon__**ett** *options*]

**cii** __var__**iances** *#obs* *#variance* [**,** __l__**evel(***#***)**]

**cii** __var__**iances** *#obs* *#variance* *#kurtosis***,** __bon__**ett** [__l__**evel(***#***)**]

Confidence intervals for standard deviations

**ci** __var__**iances** [*varlist*] [*if*] [*in*] [*weight*]**,** **sd** [__bon__**ett** *options*]

**cii** __var__**iances** *#obs* *#sd***,** **sd** [__l__**evel(***#***)**]

**cii** __var__**iances** *#obs* *#sd* *#kurtosis***,** **sd** __bon__**ett** [__l__**evel(***#***)**]

*#obs* must be a positive integer. *#exposure*, *#sd*, and *#variance* must be a
positive number. *#succ* and *#events* must be a positive integer or
between 0 and 1. If the number is between 0 and 1, Stata interprets
it as the fraction of successes or events and converts it to an
integer number representing the number of successes or events. The
computation then proceeds as if two integers had been specified. If
option **bonett** is specified, you must additionally specify *#kurtosis*
with **cii variances**.

*prop_options* Description
-------------------------------------------------------------------------
**exact** calculate exact confidence intervals; the default
**wald** calculate Wald confidence intervals
**wilson** calculate Wilson confidence intervals
__agres__**ti** calculate Agresti-Coull confidence intervals
__jeff__**reys** calculate Jeffreys confidence intervals
-------------------------------------------------------------------------

*options* Description
-------------------------------------------------------------------------
__l__**evel(***#***)** set confidence level; default is **level(95)**
__sep__**arator(***#***)** draw separator line after every *#* variables;
default is **separator(5)**
**total** add output for all groups combined (for use with
**by** only)
-------------------------------------------------------------------------

**by** and **statsby** are allowed with **ci**; see prefix.
**aweight**s are allowed with **ci means** for normal data, and **fweight**s are
allowed with all **ci** subcommands; see weight.

__Menu__

__ci__

**Statistics > Summaries, tables, and tests >** **Summary and descriptive**
**statistics > Confidence intervals**

__cii for a normal mean__

**Statistics > Summaries, tables, and tests >** **Summary and descriptive**
**statistics > Normal mean CI calculator**

__cii for a Poisson mean__

**Statistics > Summaries, tables, and tests >** **Summary and descriptive**
**statistics > Poisson mean CI calculator**

__cii for a proportion__

**Statistics > Summaries, tables, and tests >** **Summary and descriptive**
**statistics > Proportion CI calculator**

__cii for a variance__

**Statistics > Summaries, tables, and tests >** **Summary and descriptive**
**statistics > Variance CI calculator**

__cii for a standard deviation__

**Statistics > Summaries, tables, and tests >** **Summary and descriptive**
**statistics > Standard deviation CI calculator**

__Description__

**ci** computes confidence intervals for population means, proportions,
variances, and standard deviations.

**cii** is the immediate form of **ci**; see immed for a general discussion of
immediate commands.

__Options for ci and cii means__

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

**poisson** specifies that the variables (or numbers for **cii**) are
Poisson-distributed counts; exact Poisson confidence intervals will
be calculated. By default, confidence intervals for means are
calculated based on a normal distribution.

**exposure(***varname***)** is used only with **poisson**. You do not need to specify
**poisson** if you specify **exposure()**; **poisson** is assumed. *varname*
contains the total exposure (typically a time or an area) during
which the number of events recorded in *varlist* was observed.

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

**separator(***#***)** specifies how often separation lines should be inserted into
the output. The default is **separator(5)**, meaning that a line is
drawn after every five variables. **separator(10)** would draw the line
after every 10 variables. **separator(0)** suppresses the separation
line.

**total** is used with the **by** prefix. It requests that in addition to output
for each by-group, output be added for all groups combined.

__Options for ci and cii proportions__

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

**exact**, **wald**, **wilson**, **agresti**, and **jeffreys** specify how binomial
confidence intervals are to be calculated.

**exact** is the default and specifies exact (also known in the
literature as Clopper-Pearson [1934]) binomial confidence intervals.

**wald** specifies calculation of Wald confidence intervals.

**wilson** specifies calculation of Wilson confidence intervals.

**agresti** specifies calculation of Agresti-Coull confidence intervals.

**jeffreys** specifies calculation of Jeffreys confidence intervals.

See Brown, Cai, and DasGupta (2001) for a discussion and comparison
of the different binomial confidence intervals.

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

**separator(***#***)** specifies how often separation lines should be inserted into
the output. The default is **separator(5)**, meaning that a line is
drawn after every five variables. **separator(10)** would draw the line
after every 10 variables. **separator(0)** suppresses the separation
line.

**total** is used with the **by** prefix. It requests that in addition to output
for each by-group, output be added for all groups combined.

__Options for ci and cii variances__

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

**sd** specifies that confidence intervals for standard deviations be
calculated. The default is to compute confidence intervals for
variances.

**bonett** specifies that Bonett confidence intervals be calculated. The
default is to compute normal-based confidence intervals, which assume
normality for the data.

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

**separator(***#***)** specifies how often separation lines should be inserted into
the output. The default is **separator(5)**, meaning that a line is
drawn after every five variables. **separator(10)** would draw the line
after every 10 variables. **separator(0)** suppresses the separation
line.

**total** is used with the **by** prefix. It requests that in addition to output
for each by-group, output be added for all groups combined.

__Examples__

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

Obtain 90% confidence intervals for means of normally distributed
variables
**. ci means mpg price, level(90)**

----------------------------------------------------------------------------
Setup
**. webuse petri**

Obtain exact Poisson confidence interval for the mean of a count variable
**. ci means count, poisson**

---------------------------------------------------------------------------
Setup
**. webuse rm**

Obtain confidence interval for a rate based on total exposure
**. ci means deaths, exposure(pyears)**

---------------------------------------------------------------------------
Setup
**. webuse promonone**

Obtain various binomial confidence intervals for proportions
**. ci proportions promoted**
**. ci proportions promoted, wilson**
**. ci proportions promoted, agresti**
**. ci proportions promoted, jeffreys**

---------------------------------------------------------------------------
Setup
**. webuse peas_normdist**

Obtain confidence interval for the variance
**. ci variances weight**

Obtain 90% Bonett confidence interval for the standard deviation
**. ci variances weight, sd bonett level(90)**

--------------------------------------------------------------------------
Obtain confidence interval for mean for data with 166 observations,
mean=19509, and sd=4379
**. cii means 166 19509 4379**

Same as above, but obtain 90% confidence interval
**. cii means 166 19509 4379, level(90)**

Obtain Poisson confidence interval for data with 1 exposure and 27 events
**. cii means 1 27, poisson**

Obtain binomial confidence interval for data with 10 binomial events and
1 observed success
**. cii proportions 10 1**

Same as above, but obtain the Wilson confidence interval
**. cii proportions 10 1, wilson**

Obtain a confidence interval for the variance based on a sample with 15
observations and sample variance of 2.1
**. cii variances 15 2.1**

Obtain 90% Bonett confidence interval for the standard deviation based on
a sample with 15 observations, sd = 0.7, and kurtosis = 5.2
**. cii variances 15 0.7 5.2, sd bonett level(90)**
---------------------------------------------------------------------------

__Stored results__

**ci means** and **cii means** store the following in **r()**:

Scalars
**r(N)** number of observations or, if **poisson** is specified,
exposure
**r(mean)** mean
**r(se)** estimate of standard error
**r(lb)** lower bound of confidence interval
**r(ub)** upper bound of confidence interval
**r(level)** confidence level of confidence interval

Macros
**r(citype)** **normal** or **poisson**; type of confidence interval
**r(exposure)** name of exposure variable with **poisson**

**ci proportions** and **cii proportions** store the following in **r()**:

Scalars
**r(N)** number of observations
**r(proportion)** proportion
**r(se)** estimate of standard error
**r(lb)** lower bound of confidence interval
**r(ub)** upper bound of confidence interval
**r(level)** confidence level of confidence interval

Macros
**r(citype)** **exact**, **wald**, **wilson**, **agresti**, or **jeffreys**; type of
confidence interval

**ci variances** and **cii variances** store the following in **r()**:

Scalars
**r(N)** number of observations
**r(Var)** variance
**r(sd)** standard deviation, if **sd** is specified
**r(kurtosis)** kurtosis, only if **bonett** is specified
**r(lb)** lower bound of confidence interval
**r(ub)** upper bound of confidence interval
**r(level)** confidence level of confidence interval

Macros
**r(citype)** **normal** or **bonett**, type of confidence interval

__References__

Brown, L. D., T. T. Cai, and A. DasGupta. 2001. Interval estimation for
a binomial proportion. *Statistical Science* 16: 101-133.

Clopper, C. J., and E. S. Pearson. 1934. The use of confidence or
fiducial limits illustrated in the case of the binomial. *Biometrika*
26: 404-413.