使用Math.NET计算临界值T分数

问题描述 投票:2回答:1

关于如何使用Math.NET计算t分布中的临界值的任何想法?

更具体地说,我正在寻找如何使用Math.NET计算以下excel函数。

=T.INV.2T(0.05, 8)
c# statistics distribution math.net t-test
1个回答
1
投票

怎么样

var x = MathNet.Numerics.Distributions.StudentT.InvCDF(location:0.0, scale:1.0, freedom: (double)8, p: 0.05);

您应该对照T.INV.2T检查是否返回了双尾值,如果不只是调整概率的话

您也可以与临界值here比较

更新

下面的C#代码(.NET Core 3.1,Math.NET v4.9,Win10 x64)

using System;
using MathNet.Numerics.Distributions;

namespace Tinv
{
    class Program
    {
        public static double T_INV_2T(double p, double nu)
        {
            return StudentT.InvCDF(location:0.0, scale:1.0, freedom: nu, p: 1.0 - p/2.0);
            // same as             return Math.Abs(StudentT.InvCDF(location:0.0, scale:1.0, freedom: nu, p: p/2.0));

        }

        static void Main(string[] args)
        {
            var x = T_INV_2T(0.05, (double)8);
            Console.WriteLine($"Output = {x}");
        }
    }
}

生产的输出

2.306004135204172

其中Excel产生的=T.INV.2T(0.05, 8)值等于2.306004,并且在NIST表中按链接值列出为2.306

似乎很一致

© www.soinside.com 2019 - 2024. All rights reserved.