An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090423/fe97eb7a/attachment-0001.pl>
power.t.test formula
7 messages · Usuario R, Peter Dalgaard, Greg Snow +1 more
Usuario R wrote:
Hi, Does anyone of you knows a reference for the formula used in power.t.test function? And also why it uses the Student's distribution instead of Normal. (I know both of them can be used but don't see whether choose one or the other)
It is a straightforward first-principles calculation. The t distribution calculation is exact for normally distributed data with the same unknown variance in both groups. Formulas based on the normal distribution assumes the variance to be known, which overestimates small n.
O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Peter Dalgaard:
Does anyone of you knows a reference for the formula used in power.t.test function? And also why it uses the Student's distribution instead of Normal. (I know both of them can be used but don't see whether choose one or the other)
It is a straightforward first-principles calculation. The t distribution calculation is exact for normally distributed data with the same unknown variance in both groups.
I didn?t know about power.t.test. A very nice function, indeed. Is there a similar function that handles unequal number of observations for each group, and unequal variances? The help file mislead me into thinking that power.t.test handles unequal number of observations, and for example ?power.t.test(c(10,3),1)? *does* give some output (and not a warning or error), just not the output I was expecting. (It gives two power values, one for sample of size 10 (for each group) and one for samples of size 3 (for each group), while I was expecting the power for a sample size 10 for one group and 3 for the other group).
Karl Ove Hufthammer
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090424/334200bc/attachment-0001.pl>
Usuario R wrote:
Hello, Thank you, but can you understand this result? first I calculate the sd for n = 2 and then n with that sd. It should give me 2 right?
FC = 1.5 alfa = 0.01 power = 0.85 sd1 <- power.t.test( n = 2, delta = FC, sig.level = alfa,
+ power = power, type = "two.sample", sd = NULL)$sd
n1 <- round( power.t.test( n = NULL, delta = FC, sig.level =
alfa,power = power, type = "two.sample", sd = sd1)$n) Error in uniroot(function(n) eval(p.body) - power, c(2, 1e+07)) : f() values at end points not of opposite sign
The error message pretty much says it: uniroot is looking for a root between 2 and 1e7 and complains that the root is not properly bracketed. If the root is supposed to be AT 2, then this easily happens due to rounding issues. (This could have better error trapping, but you're really not expected to be planning studies with such low n.)
O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Look at the pwr package, it has functions for 2 samples of different sizes. Hope this helps,
Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111 > -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Karl Ove Hufthammer > Sent: Friday, April 24, 2009 2:41 AM > To: r-help at stat.math.ethz.ch > Subject: Re: [R] power.t.test formula > > Peter Dalgaard: > > >> Does anyone of you knows a reference for the formula used in > power.t.test > >> function? And also why it uses the Student's distribution instead of > >> Normal. (I know both of them can be used but don't see whether > choose one > >> or the other) > > > > It is a straightforward first-principles calculation. The t > > distribution calculation is exact for normally distributed data with > the > > same unknown variance in both groups. > > I didn?t know about power.t.test. A very nice function, indeed. Is > there a > similar function that handles unequal number of observations for each > group, and unequal variances? > > The help file mislead me into thinking that power.t.test handles > unequal > number of observations, and for example ?power.t.test(c(10,3),1)? > *does* > give some output (and not a warning or error), just not the output I > was > expecting. > > (It gives two power values, one for sample of size 10 (for each group) > and > one for samples of size 3 (for each group), while I was expecting the > power > for a sample size 10 for one group and 3 for the other group). > > -- > Karl Ove Hufthammer > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code.
Greg Snow:
Look at the pwr package, it has functions for 2 samples of different sizes. Hope this helps,
Great! Thanks.
Karl Ove Hufthammer