0

Is there a method to get the ttest-value and P-Value from the StudentT class. I am trying to calculate those values from this library : https://numerics.mathdotnet.com/api/MathNet.Numerics.Distributions/StudentT.htm

The excel equivalent function is T-Test. But I do not have this method in math.net numerics excel function. Below link shows all the excel methods: https://numerics.mathdotnet.com/api/MathNet.Numerics/ExcelFunctions.htm

Any pointers to get this done from the above library would be of great help.

Thank you...

Skanda
  • 131
  • 4
  • 14

2 Answers2

1

I don't know how to do this in Math.Net, but I do know how to do it in Meta.Numerics:

        Sample sample1 = new Sample(1.0, 2.0, 3.0, 4.0);
        Sample sample2 = new Sample(3.0, 4.0, 5.0, 6.0);
        TestResult tTest = Sample.StudentTTest(sample1, sample2);
        Console.WriteLine("t = {0}", tTest.Statistic);
        Console.WriteLine("P = {0} ({1})", tTest.Probability, tTest.Type);

I understand if you aren't interested in changing math libraries, but since your question had gone a while with no answer, I thought I'd chime in.

David Wright
  • 765
  • 6
  • 15
  • How would you do this same code for the full population instead of just a sample? – DarthVegan Oct 28 '17 at 18:07
  • @user3610374 If both samples contain the full population, then there is no test to do. The null hypothesis of the t-test is that the two populations are identical. If you have both populations, then they are identical trivially with either P=0 or P=1. If just one sample is the full population and has mean m, then it can be compared to a subsample s using s.StudentTTest(m), which computes $t = (\mu - m) / (\sigma / \sqrt{n})$. This is usually called a one-sample t-test (https://en.wikipedia.org/wiki/Student%27s_t-test#One-sample_t-test). – David Wright Oct 30 '17 at 21:47
0

Here is how to perform a left-tailed t test using the MathNet.Numerics set of libraries.

Assume you have some data in an array and you have already calculated all the required preliminary statistics, as shown below.

    int n = 5;    //size of sample
    double hypotheziedMean = 50.0;   
    double sampleMean = 50.03;
    double sampleSD = 1.5;    //sample standard deviation (n-1)

    double stdErr = sampleSD / Math.Sqrt(n);    //standard error of the mean
    double t = (sampleMean - hypotheziedMean) / stdErr;   //convert to a standard mean of 0 and SD of 1

    StudentT st = new StudentT(0, 1, n-1); //create a standard StudentT object with n-1 DOF

    double pVal = st.CumulativeDistribution(t);  //left tail pval
robert5722
  • 11
  • 1