Excel Formula T.INV Calculation wrong using C#

走远了吗. 提交于 2021-02-10 13:17:05

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/53932658/excel-formula-t-inv-calculation-wrong-using-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!