[R] power.t.test threading on 'power'

Uwe Ligges ligges at statistik.tu-dortmund.de
Thu Oct 2 00:15:03 CEST 2014


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