Question

I'm trying to pass the following to pwr.t.test:

> twelve
       fail sampsize     sd
1  0.047619       21 0.9759
2  0.000000       28 0.0000
3  0.000000        1 0.0000
4  0.000000       13 0.0000
5  0.000000        1 0.0000
6  0.000000        1 0.0000
7  0.000000        1 0.0000
8  0.000000        1 0.0000
9  0.000000        5 0.0000
10 0.000000        7 0.0000
11 0.100000       20 1.3416
12 0.000000        1 0.0000
13 0.000000        2 0.0000
14 0.000000        9 0.0000
15 0.000000       10 0.0000
16 1.000000        3 0.0000
17 0.133333       30 1.8619
18 0.000000        1 0.0000
19 0.000000        6 0.0000
20 0.000000       11 0.0000

I'd like to get fail/sample as an argument to pwr.t.test.

Here's how I'm implementing it to no avail:

powertest<-function(x,y) 

{pwr.t.test(d=x/y,power=.8,sig.level=.05,type="one.sample",alternative="two.sided")}
twelvelist<-list(twelve$fail,twelve$sd)
mapply(powertest, twelvelist)
Error in x/y : 'y' is missing

I had some luck earlier with lapply, but that was just using a single vector (not two columns of a dataframe).

I know this is easy to do with ddply or one of the members of the apply family.

Thank you.

Was it helpful?

Solution

Brocolli, try:

with(twelve, mapply(powertest, fail, samplesize))

But, given you don't really need two variables, but really just the ratio of the two, you could just as easily do:

with(twelve, sapply(fail / samplesize, pwr.t.test, power=.8, sig.level=.05, ...))  # replace ... with actual arguments

I haven't tested this b/c I don't know where the function you're using is coming from, so you may need to tweak a little.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top