# 17.3.1.2 Algorithms (One-Sample T-Test)

## Contents

A one sample t-test can be employed to test whether or not the true mean of a population, $\mu\,\!$, is equal to or different than a specified test mean, $\mu_0\,\!$,. The test can either be one- or two-tailed, and the hypotheses take the form:

$H_0$:$\mu=\mu_0 ,$ vs $H_1$:$\mu \ne \mu_0$, two tailed

$H_0$:$\mu \le \mu_0$ vs $H_1$:$\mu > \mu_0$, upper tailed

$H_0$:$\mu \ge \mu_0$ vs $H_1$:$\mu < \mu_0$, lower tailed

### Test Statistics

Let $X(x_1,x_2,...,x_n)\,\!$ be the input dataset, the statistic t-value has a Student's t-distribution with (n-1) degrees of freedom, which computed as:

$t=\frac{\bar{x}-\mu}{s/\sqrt{n}}$

Where $\bar{x}=\frac{1}{n}\sum_{i=1}^n x_i$ and $s=\sqrt{\sum_{i=1}^n \frac{(x_i-\bar{x})^2}{n-1}}$

For a given significance level, $\alpha\,\!$, we will reject the null hypothesis $H_0\,\!$, when:

$|t|>t_{\alpha/2}\,\!$, for two tailed test

$t>t_{\alpha}\,\!$, for upper tailed test

$t<-t_{\alpha}\,\!$, for lower tailed test

where $t_\alpha\,\!$ is the critical value from t distribution indexed at $\alpha\,\!$ level by $(n-1)$ degrees of freedom. For a better way to express the probability of hypothesis, the P-Value is also reported. And we can reject the null hypothesis $H_0\,\!$ if $p < \alpha\,\!$. The P-value for t-statistic is associated with the incomplete beta function:

$p(t>t_{\alpha})=1-I_{\frac{DOF}{DOF+I^2}}(\frac{DOF}{2},\frac{1}{2})$

where $I_x(\alpha,\beta)=\frac{I'(\alpha+\beta)}{I'(\alpha)\cdot I'(\beta)} \int_0^x t^{\alpha-1}(1-t)^{\beta-1}\,dt$

### Confidence Intervals

For the specified significance level, the confidence interval for the sample mean is:

Null Hypothesis Confidence Interval
$H_0:\mu=\mu_0\,\!$ $\left[\bar{x}-t_{n-1,\alpha/2}\frac{s}{\sqrt{n}},\bar{x}+t_{n-1,\alpha/2}\frac{s}{\sqrt{n}}\right]$
$H_0:\mu \le \mu_0$ $\left[\bar{x}-t_{n-1,\alpha}\frac{s}{\sqrt{n}}, \infty\right]$
$H_0:\mu \ge \mu_0$ $\left[-\infty, \bar{x}+t_{n-1,\alpha}\frac{s}{\sqrt{n}}\right]$

### Power Analysis

The power of a one sample t-test is a measurement of its sensitivity. In terms of the null and alternative hypotheses, power is the probability that the test statistic T will be extreme enough to allow the rejection of the null hypothesis when it should in fact be rejected (i.e. given the null hypothesis is not true). For each of the three different null hypotheses, power is mathematically defined below:

Null Hypothesis Power
$H_0:\mu=\mu_0$ $1-P \left\{T \le t_{1-\alpha/2}(n-1)-t\right\}+P\left\{T
$H_0:\mu \le \mu_0$ $1-P \left\{T \le t_{1-\alpha}(n-1)-t\right\}$
$H_0:\mu \ge \mu_0$ $P \left\{T \le t_{\alpha}(n-1)-t\right\}$

where T is a random variable having a t-distribution with $(n-1)$ degrees of freedom. The computation for hypothetical power is the same as for actual power except that the test statistic t , the critical value and degree of freedom are recomputed using hypothetical sample sizes instead of the actual sample size.