Performs a one- or two-sample t-test (S.J. Welham).
|Controls printed output (
||Type of test required (
||Defines the groups for a two-sample test if only the
||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
||The value of the mean under the null hypothesis; default 0|
||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 (
||How to plot the statistics from a permutation test (
||Number of random allocations to make when
||Which statistic to use in a permutation test (
||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|
||Limits for equivalence, non-inferiority or non-superiority|
||Identifier of the variate holding the first sample|
||Identifier of the variate holding the second sample|
||Identifier of variate (length 3) to save test statistic, d.f. and probability value|
||Identifier of scalar to save the lower limit of each confidence interval|
||Identifier of scalar to save the upper limit of each confidence interval|
||Weights (replications) of the values in Y1; default
||Weights (replications) of the values in Y2; default
||Saves the permutation statistics|
The data for
TTEST are specified by the parameters
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
The data for a two-sample test can either be specified in two separate variates using the parameters
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. This is known as Welch’s t-test or Welch’s analysis of variance (Welch 1947).
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
automatic are selected,
TTEST will print a warning if there is evidence of inequality of variances.
W2 parameters can supply variates of weights to accompany
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
Y2 (or zero or missing values to exclude the corresponding values in
Y2). A warning is given if any positive weight is given that is not an integer.
METHOD option indicates the type of test to be done, with the following settings:
twosided does a two-sided test (default).
does a one-sided test of the null hypothesis that mean(
Y1) is not greater than mean(
NULL (for a two-sample or one-sample test, respectively);
lessthan does a test of the null hypothesis that mean(
Y1) is not less than mean(
equivalence does an equivalence test;
noninferiority does a non-inferiority test;
nonsuperiority does a non-superiority test;
A small “p-value” indicates that the data is inconsistent with the null hypothesis. If any sample has fewer than six values, a warning is given that the sample size is too small and the test may not be valid.
For a two-sample equivalence test, the null hypothesis is that the difference between the mean of the first sample and the mean of the second sample lies outside two limits specified, in a variate, by the
EQLIMITS option. For a one-sample test, the difference is the mean of the sample minus
TTEST does two tests: first to test whether the difference is outside the lower limit (specified by the first element of the variate), then to test whether it is outside the upper limit. The p-value is the larger of the values from the two tests.
For a two-sample non-inferiority test, the null hypothesis is that the mean of the first sample minus the mean of the second sample is less than the negative value specified, in a scalar, by the
EQLIMITS option. For a one-sample test, the null hypothesis is that the mean of the sample minus
NULL is less than that value.
For a two-sample non-superiority test, the null hypothesis is that the mean of the first sample minus the mean of the second sample is greater than the positive value specified, in a scalar, by the
EQLIMITS option. For a one-sample test, it is that the mean of the sample minus
NULL is greater than that value.
Printed output is controlled by the
||number of observations, mean, variance, standard deviation and standard error of mean;|
||t-statistic and probability level;|
||confidence interval for the difference between mean and
||F test for equality of the sample variances in a two-sample test; and|
||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. For equivalence tests, the confidence interval is an amalgamation of two one-sided intervals, as you are making two one-sided tests. Each limit is therefore calculated for twice the distance from 100% (e.g. 90% instead of 95%, corresponding to a significance level of 5% for the test of equivalence).
By default, for the permutation test,
TTEST makes 999 random allocations of the data to the two samples (using a default seed), and determines the probability from the distribution of the t-statistic over these randomly generated data sets. Alternatively, you can set option
PERMMETHOD=difference to use the difference between the means instead of the t-statistic. The
NTIMES option 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. For a visual indication, you can set option
PLOT=histogram to display a histogram of the statistics from the permuted data sets, with a vertical line to show the position of the statistic from the original data set.
Results can be saved using the
TESTRESULTS saves the t-statistic, its degrees of freedom and probability level in a variate of length 3.
UPPER save the lower and upper limits of the confidence interval. The
SAVEPERMUTATIONS parameter can save the values of the statistics from the permutation tests in a variate; the final value in the variate is the statistic from the original data set.
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 allocations are formed using the
Y2 may be subject to different restrictions; these restrictions will be obeyed. Restrictions are also obeyed on
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
TESTRESULTS will be removed.
Snedecor, G.W. & Cochran, W.G. (1989). Statistical Methods (eighth edition). Iowa State University Press, Ames.
Welch, B.L. (1947).The generalization of ‘Student’s’ problem when several different population variances are involved. Biometrika, 34, 28-35.
Commands for: Basic and nonparametric statistics.
CAPTION 'TTEST example',\ !t('Data from Statistical Methods in Agriculture and',\ 'Experimental Biology (R. Mead & R.N. Curnow), pages 26 & 30-1.');\ STYLE=meta,plain VARIATE [VALUES=25,21,24,20,26,22] New CAPTION !T('One-sample, two-sided t-test for New with null hypothesis mean',\ '20, saving the 95% confidence interval and the test results.') TTEST [NULL=20] Y1=New; TEST=Test; LOWER=lower; UPPER=upper PRINT Test & lower,upper CAPTION !T('One-sided t-test on same data, testing whether New is greater',\ 'than null hypothesis mean 20.') TTEST [METHOD=greater; NULL=20] Y1=New CAPTION 'Two-sample t-test for New and Standard.' VARIATE [VALUES=22,19,18,21,21,17,23,20,17,22] Standard TTEST Y1=New; Y2=Standard