**[R] sdtest** -- Variance-comparison tests

__Syntax__

One-sample variance-comparison test

**sdtest** *varname* **==** *#* [*if*] [*in*] [**,** __l__**evel(***#***)**]

Two-sample variance-comparison test using groups

**sdtest** *varname* [*if*] [*in*] **,** **by(***groupvar***)** [__l__**evel(***#***)**]

Two-sample variance-comparison test using variables

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

Immediate form of one-sample variance-comparison test

**sdtesti** *#obs* {*#mean* | **.** } *#sd* *#val* [**,** __l__**evel(***#***)**]

Immediate form of two-sample variance-comparison test

**sdtesti** *#obs1* {*#mean1* | **.** } *#sd1* *#obs2* {*#mean2* | **.** } *#sd2* [**,**
__l__**evel(***#***)**]

Robust tests for equality of variances

**robvar** *varname* [*if*] [*in*] **,** **by(***groupvar***)**

**by** is allowed with **sdtest** and **robvar**; see **[D] by**.

__Menu__

__sdtest__

**Statistics > Summaries, tables, and tests >** **Classical tests of**
**hypotheses > Variance-comparison test**

__sdtesti__

**Statistics > Summaries, tables, and tests >** **Classical tests of**
**hypotheses >** **Variance-comparison test calculator**

__robvar__

**Statistics > Summaries, tables, and tests >** **Classical tests of**
**hypotheses > Robust equal-variance test**

__Description__

**sdtest** performs tests on the equality of standard deviations (variances).
In the first form, **sdtest** tests that the standard deviation of *varname* is
*#*. In the second form, **sdtest** performs the same test, using the standard
deviations of the two groups defined by *groupvar*. In the third form,
**sdtest** tests that *varname1* and *varname2* have the same standard deviation.

**sdtesti** is the immediate form of **sdtest**; see immed.

Both the traditional F test for the homogeneity of variances and
Bartlett's generalization of this test to K samples are sensitive to the
assumption that the data are drawn from an underlying Gaussian
distribution. See, for example, the cautionary results discussed by
Markowski and Markowski (1990). Levene (1960) proposed a test statistic
for equality of variance that was found to be robust under nonnormality.
Then Brown and Forsythe (1974) proposed alternative formulations of
Levene's test statistic that use more robust estimators of central
tendency in place of the mean. These reformulations were demonstrated to
be more robust than Levene's test when dealing with skewed populations.

**robvar** reports Levene's robust test statistic (W_0) for the equality of
variances between the groups defined by *groupvar* and the two statistics
proposed by Brown and Forsythe that replace the mean in Levene's formula
with alternative location estimators. The first alternative (W_50)
replaces the mean with the median. The second alternative replaces the
mean with the 10% trimmed mean (W_10).

__Options__

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

**by(***groupvar***)** specifies the *groupvar* that defines the groups to be
compared. For **sdtest**, there should be two groups, but for **robvar**
there may be more than two groups. Do not confuse the **by()** option
with the **by** prefix; both may be specified.

__Examples__

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

Test standard deviation of **mpg** against 5
**. sdtest mpg == 5**

---------------------------------------------------------------------------
Setup
**. webuse fuel**

Test that **mpg1** and **mpg2** have same standard deviation
**. sdtest mpg1 == mpg2**

---------------------------------------------------------------------------
Setup
**. webuse fuel2**

Test that the two groups of **treat** have same standard deviation
**. sdtest mpg, by(treat)**

Test sd=6 when observed sd=6.5 and n=75
**. sdtesti 75 . 6.5 6**

Test sd1=sd2 when observed n1=75, sd1=6.5, n2=65, and sd2= 7.5
**. sdtesti 75 . 6.5 65 . 7.5**

---------------------------------------------------------------------------
Setup
**. webuse stay**

Test whether length of stay differs by gender
**. robvar lengthstay, by(sex)**
---------------------------------------------------------------------------

__Stored results__

**sdtest** and **sdtesti** store the following in **r()**:

Scalars
**r(N)** number of observations
**r(p_l)** lower one-sided p-value
**r(p_u)** upper one-sided p-value
**r(p)** two-sided p-value
**r(F)** F statistic
**r(sd)** standard deviation
**r(sd_1)** standard deviation for first variable
**r(sd_2)** standard deviation for second variable
**r(df)** degrees of freedom
**r(df_1)** numerator degrees of freedom
**r(df_2)** denominator degrees of freedom
**r(chi2)** chi-squared

**robvar** stores the following in **r()**:

Scalars
**r(N)** number of observations
**r(w50)** Brown and Forsythe's F statistic (median)
**r(p_w50)** Brown and Forsythe's p-value
**r(w0)** Levene's F statistic
**r(p_w0)** Levene's p-value
**r(w10)** Brown and Forsythe's F statistic (trimmed mean)
**r(p_w10)** Brown and Forsythe's p-value (trimmed mean)
**r(df_1)** numerator degrees of freedom
**r(df_2)** denominator degrees of freedom

__References__

Brown, M. B., and A. B. Forsythe. 1974. Robust test for the equality of
variances. *Journal of the American Statistical Association* 69:
364-367.

Levene, H. 1960. Robust tests for equality of variances. In *Contributions*
*to Probability and Statistics: Essays in Honor of Harold* *Hotelling*,
ed. I. Olkin, S. G. Ghurye, W. Hoeffding, W. G. Madow, and H. B.
Mann, 278-292. Menlo Park, CA: Stanford University Press.

Markowski, C. A., and E. P. Markowski. 1990. Conditions for the
effectiveness of a preliminary test of variance. *American*
*Statistician* 44: 322-326.