[R] power.t.test threading on 'power'
Stephen Kennedy
stephen at prollenium.com
Thu Oct 2 00:27:16 CEST 2014
Thanks. I’ve been getting some nice workarounds. I was pleasantly surprised when the function ‘threaded’ on the number of samples, but I guess that was not really part of the design, just an accident.
Best,
Steve
On Oct 1, 2014, at 6:15 PM, Uwe Ligges <ligges at statistik.tu-dortmund.de> wrote:
On 01.10.2014 14:29, Stephen Kennedy wrote:
> Simple question. A vector of ‘number of observations’ can be input to power.t.test, and a vector of ‘power’ s is output. But, inputting a vector of powers generates an error. Am I missing something?
>
> Vector of ’n’ s
>
> power.t.test(n=c(28,29,30), delta=2, sd=3, sig.level=0.05, type="two.sample", alternative="one.sided")
>
> Two-sample t test power calculation
>
> n = 28, 29, 30
> delta = 2
> sd = 3
> sig.level = 0.05
> power = 0.7933594, 0.8058963, 0.8177506
> alternative = one.sided
>
> NOTE: n is number in *each* group
>
>
>
> Vector of ‘power’ s
>
> power.t.test(power=c(0.7,0.8,0.9), delta=2, sd=3, sig.level=0.05, type="two.sample", alternative="one.sided")
> Error in uniroot(function(n) eval(p.body) - power, c(2, 1e+07)) :
> f() values at end points not of opposite sign
> In addition: Warning messages:
> 1: In if (is.na(f.lower)) stop("f.lower = f(lower) is NA") :
> the condition has length > 1 and only the first element will be used
> 2: In if (is.na(f.upper)) stop("f.upper = f(upper) is NA") :
> the condition has length > 1 and only the first element will be used
>
power.t.test oes not work on vectors in general.
Here, you want:
lapply(c(0.7, 0.8, 0.9),
function(power)
power.t.test(power=power, delta=2, sd=3, sig.level=0.05,
type="two.sample", alternative="one.sided")
)
Best,
Uwe Ligges
>
> Thanks,
>
> Steve
> ______________________________________________
> 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.
>
More information about the R-help
mailing list