Documentation

# `stats`::`tTest`

T-test for a mean

MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

## Syntax

```stats::tTest(`x1, x2, …`, `m`, <Normal>)
stats::tTest(`[x1, x2, …]`, `m`, <Normal>)
stats::tTest(`s`, <`c`>, `m`, <Normal>)
```

## Description

```stats::tTest( [x1, x2, …], m )``` tests the null hypothesis: “the true mean of the data xi is larger than `m`”.

`stats::tTest` accepts numerical data as well as symbolic data.

If all data are real floating-point numbers, the returned values `p` and `t` are floating-point numbers.

If `m` is a floating-point number, the sample data are converted to floating-point numbers automatically.

For a sample x1, x2, … of size n, `stats::tTest` computes , where is the empirical mean of the data and is the empirical variance.

`stats::tTest(data, m)` returns the list ```[PValue = p, StatValue = t]```, where the observed significance level `p` is computed as `p` = `stats::tCDF````(n - 1)(t)```.

`stats::tTest(data, m, Normal)` returns the list `[PValue = p, StatValue = t]`, where the observed significance level `p` is computed as `p` = `stats::normalCDF````(0, 1)(t)```. For large n, this is an approximation of `stats::tCDF``(n - 1)(t)`.

Intuitively, `p` corresponds to the “probability” that the true mean of the data (the expectation value of the underlying distribution) is larger than m.

The most relevant information returned by `stats::tTest` is the observed significance level `PValue = p`. It has to be interpreted in the following way:

The t-test may be used as a one-tailed test of the null hypothesis: “the true mean of the data is larger than m”. In this case, the null hypothesis may be rejected at level α if the observed significance level p satisfies p < α.

Alternatively, the t-test may also be used as a one-tailed test of the null hypothesis: “the true mean of the data is smaller than m”. In this case, the null hypothesis may be rejected at level α if the observed “significance level” p satisfies p > 1 - α.

Alternatively, the t-test may also be used as a two-tailed test of the null hypothesis: “the true mean of the data is m”. If the observed “significance level” `p` returned by `stats::tTest` satisfies either or for some given level 0 < α < 1, this null hypothesis may be rejected at level α.

External statistical data stored in an ASCII file can be imported into a MuPAD® session via `import::readdata`. In particular, see Example 1 of the corresponding help page.

## Environment Interactions

The function is sensitive to the environment variable `DIGITS` which determines the numerical working precision.

## Examples

### Example 1

10 experiments produced the values 1, - 2, 3, - 4, 5, - 6, 7, - 8, 9, 10, which are assumed to be normally distributed with unknown mean and variance. The empirical mean of the sample data is 1.5. There is only a small probability `p` = that the true mean is larger than 5.0:

```data := [1, -2, 3, -4, 5, -6, 7, -8, 9, 10]: stats::tTest(data, 5.0)```
` `

We compare this result with the observed significance level computed via a standard normal distribution:

`stats::tTest(data, 5.0, Normal)`
` `

The approximation of the observed significance level `p` by the standard normal distribution is rather poor because of the small sample size. Next, we consider a larger sample. The true mean of the random data should be 10:

```r := stats::normalRandom(10, 12, Seed = 0): data := [r() \$ i = 1..100]: stats::tTest(data, 10);```
` `
`stats::tTest(data, 10, Normal)`
` `

With the observed significance level of `p` = , the data are not disqualified as having the true mean 10. For samples of this size, the normal distribution approximates the t-distribution well.

`delete data, r:`

## Parameters

 `x1, x2, …` The statistical data: arithmetical expressions `m` The estimate for the true mean of the data: an arithmetical expression `s` A sample of domain type `stats::sample`. `c` An integer representing a column index of the sample `s`. This column provides the data x1, x2 etc. There is no need to specify a column number `c` if the sample has only one non-string column.

## Options

 `Normal` Compute the observed significance level by a standard normal distribution instead of a t-distribution.

## Return Values

a list of two equations `[PValue = p, StatValue = t]` with numerical values `p` and `t`. See the `Details' section below for the interpretation of these values.

If the variance of the data vanishes, `FAIL` is returned.

## Algorithms

If the data are normally distributed with expectation value ('true mean') μ, the variable is t-distributed with n - 1 degrees of freedom. The probability of the event that T attains values not larger than t is Pr(Tt)=`stats::tCDF````(n - 1)(t)```.

#### Mathematical Modeling with Symbolic Math Toolbox

Get examples and videos