r中的样本大小和功率计算是否可以替代SAS中的处理能力? [英] Sample size and power calculation in r as viable alternative to proc power in SAS?

查看:186
本文介绍了r中的样本大小和功率计算是否可以替代SAS中的处理能力?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我试图查看SAS中的proc power和r中的一些样本大小函数之间的样本大小计算(对于两个样本独立比例,样本大小不相等)有多接近.我正在使用UCLA网站上此处找到的数据.

So I am trying to see how close the sample size calculations (for two sample independent proportions with unequal samples sizes) are between proc power in SAS and some sample size functions in r. I am using the data found here at a UCLA website.

UCLA网站提供的参数如下:

The UCLA site gives parameters as follows:

p1 = .3,p2 = .15,功率= .8,零差= 0,对于双向测试,它假定样本大小相同;

p1=.3,p2=.15,power=.8,null difference=0, and for the two-sided tests it assumes equal sample sizes;

对于不相等的样本量测试,参数是相同的,第1组的权重为1,第2组的权重为2,并且它们执行的测试是单面的.

for the unequal sample size tests the parameters are the same, with group weights of 1 for group1 and 2 for group2, and the tests they perform are one-sided.

我正在使用r函数

pwr.t.test(n=NULL,d=0,sig.level=0.05,type="two.sample",alternative="two.sided")

来自pwr包.

因此,如果像第一个示例那样输入参数选择(如UCLA站点一样),则会出现以下错误:

So if I input the parameter selections as the UCLA site has for their first example, I get the following error:

Error in uniroot(function(n) eval(p.body) - power, c(2, 1e+07)) :
  f() values at end points not of opposite sign. 

这似乎是因为r无法检测到差异.我设置d = .5,它就运行了. SAS也会因为差异太小而产生错误?在示例中,因为它们的零差也为零,所以没有.

This appears to be because the difference is undetectable by r. I set d=.5 and it ran. Would SAS give error as well for too small difference? It doesn't in the example as their null difference is zero also.

使用

pwr.2p.test(h = 0, n = , sig.level =.05, power = .8) 

pwr.chisq.test(w =0, N = , df =1 , sig.level =.05, power =.8 ).

我可能做错了很严重的事情,但是如果假设的差异为0,我似乎找不到真正的解决方法.

I may be doing something horribly wrong, but I cant seem to really find a way if the hypothesized difference is 0.

我知道SAS和r使用不同的方法来计算功效,因此我不应该期望得到相同的结果.我真的只是想看看我是否可以在r中复制proc power结果.

I understand that SAS and r are using different methods for calculating the power, so I shouldn't expect to get the same result. I am really just trying to see if I can replicate proc power results in r.

对于第一个示例,我能够获得几乎相同的结果,并且样本大小相同,并且使用

I have been able to get near identical results for the first example with equal sample sizes and a two-sided alternative using

 bsamsize(p1=.30,p2=.15,fraction=.5, alpha=.05, power=.8)

包中的

.但是,当他们使用不相等的样本量进行单面测试时,我无法复制它们.

from the Hmisc package. But when they do 1-sided tests with unequal sample sizes I can't replicate those.

对于不相等的组大小,是否有一种方法可以在r中复制用于单面样本大小计算的过程?

Is there a way to replicate the process in r for the 1-sided sample size calculations for unequal group sizes?

干杯.

推荐答案

pwr.t.test及其衍生物中,d不是零差(假定为零),而是效果大小/假设之间的差两个人口.如果总体均值之间的差异为零,则没有样本量将使您无法检测到不存在的差异.

In pwr.t.test and its derivatives, d is not the null difference (that's assumed to be zero), but the effect size/hypothesized difference between the two populations. If the difference between population means is zero, no sample size will let you detect a nonexistent difference.

如果群体A的比例为15%,群体B的比例为30%,则可以使用函数pwr::ES.h计算效果大小并进行如下比例测试:

If population A has a proportion of 15% and population B has a proportion of 30%, then you use the function pwr::ES.h to calculate the effect size and do a test of proportions like:

> pwr.2p.test(h=ES.h(0.30,0.15),power=0.80,sig.level=0.05)

     Difference of proportion power calculation for binomial distribution (arcsine transformation) 

              h = 0.3638807
              n = 118.5547
      sig.level = 0.05
          power = 0.8
    alternative = two.sided

NOTE: same sample sizes

> pwr.chisq.test(w=ES.w1(0.3,0.15),df=1,sig.level=0.05,power=0.80)

     Chi squared power calculation 

              w = 0.2738613
              N = 104.6515
             df = 1
      sig.level = 0.05
          power = 0.8

NOTE: N is the number of observations

这篇关于r中的样本大小和功率计算是否可以替代SAS中的处理能力?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆