Investment Studio > Expressions > Functions > Statistical > TTEST

float ttest(float array a, float array b, integer tails, integer type)

Returns the probability value of the Student's t test specified by tails and type on the samples in arrays a and b.

Arrays a and b contain population samples. The populations must have at least approximately normal distributions for the test result to be valid. If type = 1, the arrays must contain the same number of values.

All array elements are converted to float, with exclusion if conversion fails.

tails Î [1, 2] is the number of Student's t distribution tails to use for the computation of the test's probability value (see tdist).

Use tails = 2 to test the non-directional hypothesis that the two samples are drawn from populations with the same mean (or equivalently that the differences between the two samples are caused by chance).

Use tails = 1 to test directional hypotheses (the mean of the population represented by a is larger than the mean of the population represented by b, or vice versa).

type Î [1, 2, 3] determines which kind of t test is performed, i.e. how the t statistic and the number of degrees of freedom are computed:

  1. Paired t-Test. Often applied on the same population in before-after situations to determine whether a significant change has occurred. Requires arrays a and b to contain the same number of values.
  2. Two-sample equal variance (homoscedastic). Assumes that the two populations are known to have the same variance.
  3. Two-sample unequal variance (heteroscedastic). Assumes that the two populations are known to have different variances.

Example

Looking at a multi-year chart, we observe that a financial index seems to follow a seasonal pattern: the month of September features abnormally high average returns.

To test the statistical significance of this observation, we exploit the fact that ln(close / previous close) is approximately normal (i.e. price moves in the index are approximately lognormal, as is commonly the case in financial markets) making the Student's t test applicable to the following table:

Year Average ln(close / previous close) in September Average ln(close / previous close) ex September
1991 0.001887260352157 -0.00094856341711249
1992 0.000944521239452024 -0.000621424094849182
1993 -0.00591115665484843 0.00318688721634653
1994 0.00521243370777938 -0.00128662401851862
1995 0.00062384346507704 0.000362663496932615
1996 -0.00391055598148315 0.000201967453599865
1997 0.00486279492131019 -0.00239450094696158
1998 0.0203705664153688 -0.00242634476204215
1999 0.00835795005265914 -0.000564398894544307
2000 -0.0023669586520414 -0.00100387252056409
2001 0.00143424858275795 0.000152656813894097

(Can you guess which index this is?)

If we put the values of the September column in an array called _sep and the values of the ex-September column in an array called _exsep, the paired Student's t test

=ttest(array(_sep), array(_exsep), 2, 1)

returns a probability » 20.9% that both data sets have the same mean, i.e. that the observed seasonal pattern is due to chance.

See also chitest, ftest, tdist, tinv, ztest.