TTEST procedure

Performs a one- or two-sample t-test (S.J. Welham).


Options

PRINT = strings
Controls printed output (confidence, summary, test, variance, permutationtest); default conf, summ, test, vari

METHOD = string
Type of test required (twosided, greaterthan, lessthan); default twos

GROUPS = factor
Defines the groups for a two-sample test if only the Y1 parameter is specified

CIPROBABILITY = scalar
The probability level for the confidence interval; for a one-sided test this will be for the mean and for a two-sided test for the difference in means; default *, i.e. no confidence interval is produced

NULL = scalar
The value of the mean under the null hypothesis; default 0

VMETHOD = string
Selects between the standard two-sample t-test, with a pooled estimate of the variances of the samples, and the use of separate estimates for the sample variances (automatic, pooled, separate); default auto uses a pooled estimate unless there is evidence of unequal variances

NTIMES = scalar
Number of random allocations to make when PRINT=perm; default 999

SEED = scalar
Seed for the random number generator used to make the allocations; default 0 continues from the previous generation or (if none) initializes the seed automatically


Parameters

Y1 = variates
Identifier of the variate holding the first sample

Y2 = variates
Identifier of the variate holding the second sample

TEST = variates
Identifier of variate (length 3) to save test statistic, d.f. and probability value

LOWER = scalars
Identifier of scalar to save the lower limit of each confidence interval

UPPER = scalars
Identifier of scalar to save the upper limit of each confidence interval

W1 = variates
Weights (replications) of the values in Y1; default * i.e. all 1

W2 = variates
Weights (replications) of the values in Y2; default * i.e. all 1


Description

The data for TTEST are specified by the parameters Y1 and Y2 and the option GROUPS. For a one-sample test, the Y1 parameter should be set to a variate containing the data. TTEST then performs a one-sample t-test for the mean of a Normal distribution. The value of the mean under the null hypothesis can be specified by the option NULL; by default NULL=0.

   The data for a two-sample test can either be specified in two separate variates using the parameters Y1 and Y2. Alternatively, they can be given in a single variate, with the GROUPS option set to a factor to identify the two samples; the GROUPS option is ignored when the Y2 parameter is set. The standard two-sample t-test assumes that the two samples arise from Normal distributions with equal variances and forms a pooled estimate for the variance of both samples. If, however, the variances are unequal, a separate estimate can be used for the variance of each sample. The degrees of freedom of the test are then only approximate (see, for example, Snedecor & Cochran 1989, page 97) but these seem to work well in practice. The VMETHOD option specifies how to estimate the variances for the test. The default setting, automatic, uses a pooled estimate unless there is evidence of unequal variances, pooled always uses a pooled estimate and separate always uses separate estimates. If either pooled or automatic are selected, TTEST will print a warning if there is evidence of inequality of variances.

   The W1 and W2 parameters can supply variates of weights to accompany Y1 or Y2, respectively. You can use these to specify replicate observations. For example, instead of specifying variate for Y1 with values (11, 12, 12, 13, 14, 14, 14, 15) you could give Y1 the values (11, 12, 13, 14, 15) together with weight variate W1 containing values (1, 2, 1, 3, 1) indicating the number of replications of each of the values in Y1. The calculation of the t-test assumes that the weights are positive integers defining the

replications of the values inside Y1 or Y2 (or zero or missing values to exclude the corresponding values in Y1 or Y2). A warning is given if any positive weight is given that is not an integer.

   For both one- and two-sample cases, the test is assumed to be two-sided unless otherwise requested by the METHOD option. Setting METHOD=greaterthan will give a one-sided test of the null hypothesis that mean(Y1) is not greater than mean(Y2) or NULL (for a two sample or one sample test, respectively). Similarly, METHOD=lessthan will produce a test of the null hypothesis that mean(Y1) is not less than mean(Y2) or NULL. A small "p-value" indicates that the data is inconsistent with the null hypothesis.

   If any sample has fewer than 6 values, a warning is given that the sample size is too small and the test may not be valid.

   Printed output is controlled by the PRINT option with settings:

    summary
number of observations, mean, variance, standard deviation and standard error of mean;

    test
t-statistic and probability level;

    confidence
confidence interval for the difference between mean and NULL for a one-sample test, or the two means for a two-sample test;

    variance
F test for equality of the sample variances in a two-sample test; and

    permutationtest
probabilities calculated by a random permutation test (relevant only for two-sample tests).

The default is PRINT=summary,test,confidence,variance. Usually a 95% confidence interval is calculated, but this can be changed by setting the CIPROBABILITY option to the required value (between 0 and 1) or leaving it unset to suppress the interval. By default, when PRINT=perm, TTEST makes 999 random allocations of the data to the two samples (using a default seed), and determines the probability of the t-statistic from its distribution over these randomly generated datasets. The NTIMES option of TTEST allows you to request another number of allocations, and the SEED option allows you to specify another seed. TTEST checks whether NTIMES is greater than the number of possible ways in which the data values can be allocated. If so, it does an exact test instead, which takes each possible allocation once.

   Results can be saved using the TEST, LOWER and UPPER parameters. TEST saves the t-statistic, its degrees of freedom and probability level in a variate of length 3. LOWER and UPPER save the lower and upper limits of the confidence interval.

 

Options: PRINT, METHOD, GROUPS, CIPROBABILITY, NULL, VMETHOD, NTIMES, SEED.

Parameters: Y1, Y2, TEST, LOWER, UPPER, W1, W2.


Method

A standard t-statistic is calculated in both cases, together with an F-statistic in the two-sample case (to test equality of variances) as described in any standard textbook. The squared t-statistics and the F-ratio are compared with the appropriate F-distribution using the function FPROBABILITY, and confidence intervals are constructed using the function FED. For the exact test, the alloactions are formed using the SETALLOCATIONS directive.


Action with RESTRICT

Y1 and Y2 may be subject to different restrictions; these restrictions will be obeyed. Restrictions are also obeyed on Y1 and GROUPS, allowing RESTRICT to be used for example to limit the data to only one or two groups when the GROUPS factor has more than two levels. Any restrictions on TEST will be removed.


Reference

Snedecor, G.W. & Cochran, W.G. (1989). Statistical Methods (eighth edition). Iowa State University Press, Ames.