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

### Options

`PRINT` = string tokens |
Controls printed output (`confidence` , `summary` , `test` , `variance` , `permutationtest` ); default `conf` , `summ` , `test` , `vari` |
---|---|

`METHOD` = string token |
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 token |
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 |

`PLOT` = string token |
How to plot the statistics from a permutation test (`histogram` ); default `*` i.e. no plots |

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

`PERMMETHOD` = string token |
Which statistic to use in a permutation test (`difference` , `t` ); default `t` |

`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 |

`TESTRESULTS` = 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 |

`SAVEPERMUTATIONS` = variates |
Saves the permutation statistics |

### 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, 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`

, `LOWER`

and `UPPER`

parameters. `TESTRESULTS`

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. 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.

Options: `PRINT`

, `METHOD`

, `GROUPS`

, `CIPROBABILITY`

, `NULL`

, `VMETHOD`

, `PLOT`

, `NTIMES`

, `PERMMETHOD`

, `SEED`

.

Parameters: `Y1`

, `Y2`

, `TESTRESULTS`

, `LOWER`

, `UPPER`

, `W1`

, `W2`

, `SAVEPERMUTATIONS`

.

### 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 alloca tions 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 `TESTRESULTS`

will be removed.

### Reference

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

### See also

Procedure: `STTEST`

, `AONEWAY`

, `A2WAY`

, `MANNWHITNEY`

, `SIGNTEST`

, `WILCOXON`

.

Commands for: Basic and nonparametric statistics.

### Example

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