Re: [R] sample size for t-tests

2004-09-01 Thread Adaikalavan Ramasamy
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 :

\begin{equation}
 1 - \beta =   \Pr ( t_{v,ncp}^{*}   t_{v, \alpha/2 } ) 
 + \Pr ( t_{v,ncp}^{*}   t_{v, 1 - \alpha/2 } )
\end{equation}
  
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. 

Regards, Adai



 On Tue, 2004-08-31 at 18:49, Caimiao Wei wrote:
  Dear all,
  
  Could any one please tell me the exact formula R uses to calculate the sample size 
  for one-sample and two-sample t-tests? Thanks,
  
  Caimiao
  [[alternative HTML version deleted]]
  
  __
  [EMAIL PROTECTED] mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
 

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] sample size for t-tests

2004-09-01 Thread Peter Dalgaard
Adaikalavan Ramasamy [EMAIL PROTECTED] 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 :
 
 \begin{equation}
  1 - \beta =   \Pr ( t_{v,ncp}^{*}   t_{v, \alpha/2 } ) 
  + \Pr ( t_{v,ncp}^{*}   t_{v, 1 - \alpha/2 } )
 \end{equation}
   
 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
~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] sample size for t-tests

2004-08-31 Thread Caimiao Wei
Dear all,

Could any one please tell me the exact formula R uses to calculate the sample size for 
one-sample and two-sample t-tests? Thanks,

Caimiao
[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] sample size for t-tests

2004-08-31 Thread Thomas Lumley
On Tue, 31 Aug 2004, Caimiao Wei wrote:

 Dear all,

 Could any one please tell me the exact formula R uses to calculate the
 sample size for one-sample and two-sample t-tests? Thanks,

There isn't a formula in closed form.  The exact procedure is in the code.

In words: the critical value for the t-test comes from a t-distribution.
The distribution of the t-statistic under the alternative is a non-central
t-distribution, and the sample size is adjusted to get the requested
power.

-thomas

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html