我试图在 R 中创建 t 临界值表。我使用了以下代码,但出了点问题,因为我无法获得正确的值:

t.power <- function(n) {

    alpha=c(0.50,0.75,0.80,0.85,0.90,0.95,
            0.975,0.99,0.995,0.999,0.9995,1.0)
    power=qt(alpha, df=1:n)
    return(power)
}

然后我尝试测试它的 n=15
 t.power(15)

我得到了
[1] 0.0000000 0.8164966 0.9784723 1.1895669 1.4758840 1.9431803 2.3646243
[8] 2.8964594 3.2498355 4.1437005 4.4369793       Inf 0.0000000 0.6924171
[15] 0.8662450

谁能告诉我我做错了什么?

最佳答案

如果我没有误会你,你想在 qtalpha 跨越的“网格”上评估 1:n 。那么,outer 可以提供帮助:

t.power<-function(n){
  alpha <- c(0.50,0.75,0.80,0.85,0.90,0.95,0.975,0.99,0.995,0.999,0.9995,1.0)
  "dimnames<-"(outer(alpha, 1:n, FUN = qt), list(quantile = alpha, df = 1:n))
  }

t.power(5)
#        df
#quantile          1          2          3         4         5
#  0.5      0.000000  0.0000000  0.0000000 0.0000000 0.0000000
#  0.75     1.000000  0.8164966  0.7648923 0.7406971 0.7266868
#  0.8      1.376382  1.0606602  0.9784723 0.9409646 0.9195438
#  0.85     1.962611  1.3862066  1.2497781 1.1895669 1.1557673
#  0.9      3.077684  1.8856181  1.6377444 1.5332063 1.4758840
#  0.95     6.313752  2.9199856  2.3533634 2.1318468 2.0150484
#  0.975   12.706205  4.3026527  3.1824463 2.7764451 2.5705818
#  0.99    31.820516  6.9645567  4.5407029 3.7469474 3.3649300
#  0.995   63.656741  9.9248432  5.8409093 4.6040949 4.0321430
#  0.999  318.308839 22.3271248 10.2145319 7.1731822 5.8934295
#  0.9995 636.619249 31.5990546 12.9239786 8.6103016 6.8688266
#  1             Inf        Inf        Inf       Inf       Inf

关于r - T临界值表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40335545/

10-12 20:16