Matlab's ttest
takes your vector of data and performs a Student's (one-sample) t-test on it, assuming that:
- the population mean you're testing against, $\mu_{0}$, is zero
- $n$ is equal to
length(x)
- the level of statistical signficance, or Type I error, you're willing to accept is 5%; you can change the amount of Type I error you're willing to accept in the arguments of the function
The $t$-test calculates the mean of the data in x
(i.e., $\bar{x} =$ sum(x)/length(x)
), and its sample standard deviation, $s$, typically with the formula
\begin{align}
s = \sqrt{\frac{1}{n - 1}\sum_{i = 1}^{n}(x_{i} - \bar{x})^{2}},
\end{align}
which corrects for the fact that $s$ estimates the true standard deviation of the population from which x
samples.
Then, the $t$-statistic is
\begin{align}
t = \frac{\bar{x} - \mu_{0}}{s/\sqrt{n}} = \frac{\bar{x}}{s/\sqrt{n}},
\end{align}
because $\mu_{0}$ is assumed equal to zero. The documentation doesn't say, so I assume that the test is a bidirectional $t$-test, which means that ttest
returns 1 if $t$ is greater than tinv(0.95, length(x))
or less than tinv(0.05, length(x))
(these are the t-statistics corresponding to a 5% level of significance; it should be the case that tinv(0.05, length(x))
equals -tinv(0.95, length(x))
). Otherwise, ttest
returns 0.