幂二均值:均值必须包含数字

时间:2018-09-08 14:41:42

标签: stata

我正在尝试使用ttest命令存储的结果在Stata中进行功率分析。

我所做的确切如下:

. ttest r, by(predictor)
Two-sample t test with equal variances
------------------------------------------------------------------------------
   Group |     Obs        Mean    Std. Err.   Std. Dev.   [95% Conf. Interval]
---------+--------------------------------------------------------------------
       0 |       8         .49    .0368394    .1041976    .4028886    .5771114
       1 |       8        .595    .0547396    .1548271    .4655613    .7244387
---------+--------------------------------------------------------------------
combined |      16       .5425     .034635      .13854    .4686772    .6163228
---------+--------------------------------------------------------------------
    diff |               -.105    .0659816               -.2465165    .0365165
------------------------------------------------------------------------------
    diff = mean(0) - mean(1)                                      t =  -1.5914
Ho: diff = 0                                     degrees of freedom =       14

    Ha: diff < 0                 Ha: diff != 0                 Ha: diff > 0
 Pr(T < t) = 0.0669         Pr(|T| > |t|) = 0.1339          Pr(T > t) = 0.9331

. display r(mu_1),r(mu_2),r(sd_1),r(sd_2),r(p_l)
.49 .595 .10419762 .1548271 .06692561

但是,当我运行以下命令时:

power twomeans r(mu_1) r(mu_2), sd1(r(sd_1)) sd2(r(sd_2))

我总是收到以下错误:

  

手段必须包含数字

我认为存储的结果r(mu_1)等是数字吗?

1 个答案:

答案 0 :(得分:1)

使用auto数据集作为玩具示例:

sysuse auto, clear
ttest mpg, by(foreign)

Two-sample t test with equal variances
------------------------------------------------------------------------------
   Group |     Obs        Mean    Std. Err.   Std. Dev.   [95% Conf. Interval]
---------+--------------------------------------------------------------------
Domestic |      52    19.82692     .657777    4.743297    18.50638    21.14747
 Foreign |      22    24.77273     1.40951    6.611187    21.84149    27.70396
---------+--------------------------------------------------------------------
combined |      74     21.2973    .6725511    5.785503     19.9569    22.63769
---------+--------------------------------------------------------------------
    diff |           -4.945804    1.362162               -7.661225   -2.230384
------------------------------------------------------------------------------
    diff = mean(Domestic) - mean(Foreign)                         t =  -3.6308
Ho: diff = 0                                     degrees of freedom =       72

    Ha: diff < 0                 Ha: diff != 0                 Ha: diff > 0
 Pr(T < t) = 0.0003         Pr(|T| > |t|) = 0.0005          Pr(T > t) = 0.9997

您需要明确告诉powerttest返回的项是本地宏:

power twomeans `r(mu_1)' `r(mu_2)', sd1(`r(sd_1)') sd2(`r(sd_2)')

Performing iteration ...

Estimated sample sizes for a two-sample means test
Satterthwaite's t test assuming unequal variances
Ho: m2 = m1  versus  Ha: m2 != m1

Study parameters:

        alpha =    0.0500
        power =    0.8000
        delta =    4.9458
           m1 =   19.8269
           m2 =   24.7727
          sd1 =    4.7433
          sd2 =    6.6112

Estimated sample sizes:

            N =        46
  N per group =        23