stats
::tTest
Ttest for a mean
MuPAD® notebooks are not recommended. 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.
stats::tTest(x_{1}, x_{2}, …
,m
, <Normal>) stats::tTest([x_{1}, x_{2}, …]
,m
, <Normal>) stats::tTest(s
, <c
>,m
, <Normal>)
stats::tTest( [x_{1}, x_{2},
…], m )
tests the null hypothesis: “the true
mean of the data x_{i} is
larger than m
”.
stats::tTest
accepts numerical data as well
as symbolic data.
If all data are real floatingpoint numbers, the returned values p
and t
are
floatingpoint numbers.
If m
is a floatingpoint number, the sample
data are converted to floatingpoint numbers automatically.
For a sample x_{1}, x_{2},
… 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 ttest may be used as a onetailed 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 ttest may also be used as a onetailed 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 ttest may also be used as a twotailed 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.
The function is sensitive to the environment variable DIGITS
which
determines the numerical working precision.
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
tdistribution well.
delete data, r:

The statistical data: arithmetical expressions 

The estimate for the true mean of the data: an arithmetical expression 

A sample of domain type 

An integer representing a column index of the sample 

Compute the observed significance level by a standard normal distribution instead of a tdistribution. 
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.
If the data are normally distributed with expectation value
('true mean') μ,
the variable is
tdistributed with n  1 degrees
of freedom. The probability of the event that T attains
values not larger than t is Pr(T ≤ t)=stats::tCDF
(n
 1)(t)
.