且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用C#的Excel公式T.INV计算错误

更新时间:2023-02-09 19:33:52

此代码返回学生t分布的左尾和两个尾部倒数

 静态void Main(string [] args){双精度值= 0.9;整数度= 5;var chart = new System.Web.UI.DataVisualization.Charting.Chart();double resultTest = chart.DataManipulator.Statistics.InverseTDistribution(value,degree);Console.WriteLine(resultTest);//左尾双重结果= alglib.invstudenttdistribution(度,值);Console.WriteLine(result);} 

P.S.我使用了此处可用的invstudenttdistribution函数

In Excel =T.INV(0.9,5) returns the value '1.475884'.

Now I am using the function of WorksheetFunction TINV(0.9,5) in C#. But this gives me result 0.1321751752.

So, in C# TINV result has too much different value than excel.

Microsoft.Office.Interop.Excel.Application xl = new Microsoft.Office.Interop.Excel.Application();

Microsoft.Office.Interop.Excel.WorksheetFunction wsf = xl.WorksheetFunction;
double result = wsf.TInv(0.9, 5);

Using another NuGet DLL also found same value as previous DLL:

var chart = new System.Web.UI.DataVisualization.Charting.Chart();
double resultTest = chart.DataManipulator.Statistics.TDistribution(.9, 5, true);

So, I need the same value as found on Excel Worksheet **T.Inv** function.

How can i get same T.INV value in c#.

can anyone help me to get the same result please?

This code returns both the left-tailed and the two tailed inverse of the Student's t-distribution

static void Main(string[] args)
{
    double value = 0.9;
    int degree = 5;

    var chart = new System.Web.UI.DataVisualization.Charting.Chart();
    double resultTest = chart.DataManipulator.Statistics.InverseTDistribution(value, degree);  
    Console.WriteLine(resultTest);

    //left-tailed 
    double result = alglib.invstudenttdistribution(degree, value);
    Console.WriteLine(result);
}

P.S. I used the invstudenttdistribution function available here alglib.net