0

我正在尝试将以下内容传递给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

我想fail/sample作为pwr.t.test.

以下是我如何实施它无济于事:

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

我之前有一些运气lapply,但这只是使用单个向量(而不是数据框的两列)。

我知道这很容易与家庭ddply成员或其中一位成员一起完成apply

谢谢你。

4

1 回答 1

3

西兰花,试试:

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

但是,鉴于您实际上并不需要两个变量,而实际上只需要两者的比率,您可以很容易地做到:

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

我还没有测试过这个 b/c 我不知道你使用的功能是从哪里来的,所以你可能需要稍微调整一下。

于 2014-03-03T19:21:03.433 回答