# Matlab ttest does what exactly?

Can anyone clarify what exactly is output by the command ttest when run on a vector of numbers $a_1, a_2, \ldots, a_n$? OK to answer in a form such as "it outputs the value $x$ that maximizes $y$."

I realize this is probably a trivial question for the experts, but I can't easily find a clear answer.

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.

• Thanks. Can you say what is tinv (again not terribly clear to me), and how is the p-value p calculated in a call [h, p] = ttest?
– Manu
Dec 14 '13 at 13:27
• The student's t distribution is a probability distribution with a parameter $\nu$ (called the "degrees of freedom") If x=tinv(0.95,nu), then for a random variable $t$ with the Student's t distribution with $\nu$ degrees of freedom, $P(t<=x)=0.95$. In other words, x is the 95th percentile of this probabilitiy distribution. Dec 15 '13 at 5:46
• Or if you prefer: ttest returns either 1 or zero. The array or vector fed to ttest is analyzed in order to ascertain if the vector came from a population that was normally distributed. Or not. Return of 1 means "yes" (95% CI), zero means no. Zero can also mean that the vector did not satisfy the assumption that the mean be zero. Other arguments to ttest have different meanings. This is for H = ttest(x); Dec 15 '13 at 18:15