Skip to contents

Based on Lenth (2007) Post Hoc Power: Tables and Commentary. php.guf() give's Lenth's grand unified formula for post hoc power.

Usage

php.t(tval, p, df = Inf, alpha = 0.05, one.tailed = FALSE)

php.F(Fval, p, df1, df2 = Inf, alpha = 0.05)

php.z(zval, p, alpha = 0.05, one.tailed = FALSE)

php.chisq(chisqval, p, df, alpha = 0.05)

php.guf(p, alpha = 0.05)

Arguments

tval, zval, Fval, chisqval

Observed test statistic

p

Observed p-value (used if test statistic not supplied)

df, df1, df2

Test statistics' degrees of freedom

alpha

Confidence level of the test.

one.tailed

Is the p-value from a one-tailed test?

Examples


lm(hp ~ am, mtcars) |> summary()
#> 
#> Call:
#> lm(formula = hp ~ am, data = mtcars)
#> 
#> Residuals:
#>    Min     1Q Median     3Q    Max 
#> -98.26 -51.51 -15.35  25.99 208.15 
#> 
#> Coefficients:
#>             Estimate Std. Error t value Pr(>|t|)    
#> (Intercept)   160.26      15.51  10.333 2.12e-11 ***
#> am            -33.42      24.33  -1.373     0.18    
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> Residual standard error: 67.6 on 30 degrees of freedom
#> Multiple R-squared:  0.05915,	Adjusted R-squared:  0.02779 
#> F-statistic: 1.886 on 1 and 30 DF,  p-value: 0.1798
#> 

php.t(p = 0.18, df = 30)
#> [1] 0.2645363

php.guf(p = 0.18)
#> [1] 0



# Table 1 - one tailed
expand.grid(
  p = c(.001, .01, .05, .1, .25, .5, .75),
  df = c(1, 2, 5, 10, 20, 50, 200, 1000, Inf)
) |>
  transform(PHP = php.t(p = p, df = df, one.tailed = TRUE)) |>
  stats::reshape(
    direction = "wide",
    idvar = "df", timevar = "p"
  )
#>      df PHP.0.001  PHP.0.01  PHP.0.05   PHP.0.1  PHP.0.25 PHP.0.5   PHP.0.75
#> 1     1 1.0000000 0.9999994 0.6766947 0.3698439 0.1347904    0.05 0.01048100
#> 8     2 1.0000000 0.9910253 0.5995969 0.3570984 0.1434485    0.05 0.01178402
#> 15    5 0.9995122 0.8898963 0.5365274 0.3565384 0.1556676    0.05 0.01117923
#> 22   10 0.9860350 0.8225320 0.5173531 0.3573495 0.1607017    0.05 0.01072806
#> 29   20 0.9627161 0.7870282 0.5084397 0.3577849 0.1633066    0.05 0.01046688
#> 36   50 0.9420174 0.7659860 0.5033189 0.3580337 0.1648815    0.05 0.01030144
#> 43  200 0.9300290 0.7556379 0.5008226 0.3581515 0.1656698    0.05 0.01021671
#> 50 1000 0.9266729 0.7529027 0.5001641 0.3581821 0.1658800    0.05 0.01019392
#> 57  Inf 0.9258242 0.7522206 0.5000000 0.3581896 0.1659326    0.05 0.01018821


# Table 1 - two tailed
expand.grid(
  p = c(.001, .01, .05, .1, .25, .5, .75),
  df = c(1, 2, 5, 10, 20, 50, 200, 1000, Inf)
) |>
  transform(PHP = php.t(p = p, df = df)) |>
  stats::reshape(
    direction = "wide",
    idvar = "df", timevar = "p"
  )
#>      df PHP.0.001  PHP.0.01  PHP.0.05   PHP.0.1  PHP.0.25    PHP.0.5   PHP.0.75
#> 1     1 1.0000000 1.0000000 0.6811954 0.3796619 0.1505611 0.07298889 0.05421092
#> 8     2 1.0000000 0.9921973 0.6147232 0.3730893 0.1619273 0.08037867 0.05615497
#> 15    5 0.9995752 0.8918535 0.5445532 0.3726519 0.1864002 0.09182502 0.05887572
#> 22   10 0.9843683 0.8144798 0.5210432 0.3743778 0.1977828 0.09730577 0.06018982
#> 29   20 0.9553336 0.7723470 0.5101846 0.3754240 0.2038380 0.10033499 0.06092576
#> 36   50 0.9289676 0.7473245 0.5040117 0.3760684 0.2075359 0.10223244 0.06139096
#> 43  200 0.9136834 0.7350546 0.5010250 0.3763890 0.2093948 0.10320124 0.06162983
#> 50 1000 0.9094128 0.7318178 0.5002398 0.3764739 0.2098912 0.10346170 0.06169421
#> 57  Inf 0.9083336 0.7310112 0.5000443 0.3764951 0.2100153 0.10352695 0.06171035


# Table 2
expand.grid(
  p = c(.001, .01, .05, .1, .25, .5, .75),
  df2 = c(1, 2, 5, 10, 20, 50, 200, 1000, Inf),
  df1 = c(2, 3, 4, 10)
) |>
  transform(PHP = php.F(p = p, df1 = df1, df2 = df2)) |>
  stats::reshape(
    direction = "wide",
    idvar = c("df1", "df2"), timevar = "p"
  )
#>      df2 df1 PHP.0.001  PHP.0.01  PHP.0.05   PHP.0.1  PHP.0.25    PHP.0.5
#> 1      1   2 1.0000000 0.9999994 0.6826910 0.3829361 0.1587031 0.08176220
#> 8      2   2 1.0000000 0.9932708 0.6325960 0.3942533 0.1823274 0.09633205
#> 15     5   2 0.9997970 0.9157359 0.5951373 0.4248532 0.2320135 0.12476697
#> 22    10   2 0.9899075 0.8526756 0.5865499 0.4443952 0.2614640 0.14267526
#> 29    20   2 0.9668058 0.8166045 0.5841959 0.4563401 0.2794409 0.15419082
#> 36    50   2 0.9436186 0.7949064 0.5835206 0.4641810 0.2913307 0.16208294
#> 43   200   2 0.9296226 0.7842643 0.5833992 0.4682801 0.2975878 0.16633041
#> 50  1000   2 0.9256607 0.7814617 0.5833914 0.4693924 0.2992914 0.16749843
#> 57   Inf   2 0.9246565 0.7807637 0.5833911 0.4696717 0.2997195 0.16779280
#> 64     1   3 1.0000000 0.9999994 0.6830637 0.3837461 0.1606670 0.08459055
#> 71     2   3 1.0000000 0.9936026 0.6385660 0.4014754 0.1896638 0.10284278
#> 78     5   3 0.9998634 0.9265754 0.6205251 0.4513766 0.2555210 0.14313502
#> 85    10   3 0.9926192 0.8746581 0.6256030 0.4864480 0.3006447 0.17300882
#> 92    20   3 0.9741348 0.8453681 0.6324077 0.5094815 0.3308774 0.19438033
#> 99    50   3 0.9545235 0.8281026 0.6381470 0.5252872 0.3520522 0.21007115
#> 106  200   3 0.9424008 0.8198082 0.6415127 0.5337638 0.3635749 0.21887644
#> 113 1000   3 0.9389439 0.8176491 0.6424672 0.5360888 0.3667570 0.22134244
#> 120  Inf   3 0.9380663 0.8171132 0.6427096 0.5366743 0.3675598 0.22196697
#> 127    1   4 1.0000000 0.9999994 0.6832279 0.3841023 0.1615214 0.08590456
#> 134    2   4 1.0000000 0.9937639 0.6415524 0.4051169 0.1934328 0.10633344
#> 141    5   4 0.9998941 0.9328804 0.6362907 0.4680605 0.2704904 0.15516125
#> 148   10   4 0.9942046 0.8893260 0.6528346 0.5161525 0.3289019 0.19570641
#> 155   20   4 0.9791553 0.8661605 0.6682758 0.5496167 0.3709345 0.22722036
#> 162   50   4 0.9627373 0.8533009 0.6804461 0.5734141 0.4017635 0.25171533
#> 169  200   4 0.9524757 0.8474523 0.6874205 0.5864360 0.4190025 0.26595886
#> 176 1000   4 0.9495426 0.8459757 0.6893832 0.5900372 0.4238183 0.27001090
#> 183  Inf   4 0.9487978 0.8456125 0.6898807 0.5909460 0.4250369 0.27104144
#> 190    1  10 1.0000000 0.9999994 0.6834885 0.3846668 0.1628646 0.08804004
#> 197    2  10 1.0000000 0.9940463 0.6469293 0.4117219 0.2003860 0.11301779
#> 204    5  10 0.9999431 0.9463167 0.6731161 0.5079007 0.3070554 0.18551251
#> 211   10  10 0.9973793 0.9265814 0.7289848 0.6018477 0.4140200 0.26793239
#> 218   20  10 0.9914645 0.9256232 0.7806107 0.6806704 0.5111326 0.35242534
#> 225   50  10 0.9859084 0.9310042 0.8225208 0.7434504 0.5946947 0.43358659
#> 232  200  10 0.9829889 0.9358578 0.8466730 0.7795634 0.6456645 0.48751559
#> 239 1000  10 0.9822496 0.9374121 0.8534301 0.7896737 0.6603487 0.50374349
#> 246  Inf  10 0.9820693 0.9378178 0.8551378 0.7922294 0.6640905 0.50793080
#>       PHP.0.75
#> 1   0.05925190
#> 8   0.06570212
#> 15  0.07744732
#> 22  0.08497148
#> 29  0.08991580
#> 36  0.09336124
#> 43  0.09523634
#> 50  0.09575463
#> 57  0.09588544
#> 64  0.06149594
#> 71  0.07078241
#> 78  0.09041739
#> 85  0.10538955
#> 92  0.11643991
#> 99  0.12476283
#> 106 0.12951812
#> 113 0.13086130
#> 120 0.13120228
#> 127 0.06268129
#> 134 0.07375255
#> 141 0.09954108
#> 148 0.12178921
#> 155 0.13979918
#> 162 0.15429556
#> 169 0.16294326
#> 176 0.16543420
#> 183 0.16606993
#> 190 0.06483326
#> 197 0.07986681
#> 204 0.12415628
#> 211 0.17833497
#> 218 0.23858442
#> 225 0.30153282
#> 232 0.34647984
#> 239 0.36054167
#> 246 0.36421246