# [R] sample size for t-tests

Peter Dalgaard p.dalgaard at biostat.ku.dk
Wed Sep 1 12:02:05 CEST 2004

Adaikalavan Ramasamy <ramasamy at cancer.org.uk> writes:

> Look into the code of power.t.test in the stats package. For example,
> the sample size for two-sample t-test, two-tail testing and strict
> interpretation of tail probability can be found by solving the following
> equation iteratively :
>
>
>  1 - \beta =   \Pr ( t_{v,ncp}^{*} <  t_{v, \alpha/2 } )
>              + \Pr ( t_{v,ncp}^{*} >  t_{v, 1 - \alpha/2 } )
>
>
> where :
>
> 1) $t_{v, \alpha/2}$ is the $\alpha/2$ quantile of a central
> t-distribution with $v$ degrees of freedom and $v = n1 + n2 - 2$
>
> 2) $t_{v,ncp}^{*}$ follows a non-central t-distribution $v$ degrees of
> freedom and non-centrality parameter of $ncp$
>
> 3) non-centralitity parameter in 2) estimated by
> $ncp = \delta / ( \sigma \sqrt{ \frac{1}{n_1} + \frac{1}{n_2} } )$
>
> As usual, $alpha$ and $beta$ represent type I and type II error and
> \delta, \sigma represents the desired difference in group means and
> variance.
>
> This would be explained in a textbook but none comes to my mind at the
> moment. There is an approximate analytical solution based on normality
> assumption but the results are very close for large sample sizes. It is
> better to use the exact equation as the computations (via uniroot) is
> fast anyway.

Yep, just a few nits/qualifications:

- sigma is the standard deviation, not variance

- n1 and n2 are generally set equal in sample size calculations since
that is known to be optimal (largest power for given n1+n2)

- all the solutions are based on normality assumptions, the analytical
formulas come out of assuming the variance known in advance (so that
you can use the normal distribution instead of the t distribution).
These ignore the uncertainty from having to estimate the variance
and so give somewhat too small sample sizes.

--
O__  ---- Peter Dalgaard             Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics     2200 Cph. N
(*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907