首页 > 解决方案 > 使用 Math.NET 计算临界值 T-Score

问题描述

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

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

=T.INV.2T(0.05, 8)

标签: c#statisticsdistributionmath.nett-test

解决方案


怎么样

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

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

您还可以在此处与临界值进行比较

更新

下面的 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

看起来相当一致


推荐阅读