Student's T-distribution

Hello,

I want to write a t-distribution code that will calculate two-tailed one, lower value 0, upper value 1.1 and degrees of freedom 9.

Could anyone help me about this matter please?

Thank you.
@Faruk1

Perhaps you could be more explicit about what you want.

Degrees of freedom 9 is OK, but why 9 specifically?

"Two-tailed one"? Do you mean the critical values? - if so state your confidence level - 90%, 95% etc.

What do you mean by lower value 0, upper value 1.1? Do you mean find the probability that your t statistic lies between these values? If so, either look it up in a table or numerically integrate the PDF between those values.

The t-distribution PDF, CDF and critical points are all given at
https://en.wikipedia.org/wiki/Student%27s_t-distribution
with online calculator at
http://keisan.casio.com/exec/system/1180573203

Thank you for reply sir.

Sorry, i know this is not here for homework but this is not homework, is final exam :(

https://abload.de/img/testzebzb.png

In the picture above, i find those expected values in the code when i enter x values as you mention above "t statistic lies between 0-1.1 and degrees of freedom 9"

So, i need to write a code that give me expected values.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <cmath>
using namespace std;

int nu;                   // degrees of freedom
double cnu;               // main coefficient in t distribution

//======================================================================

// Function prototypes
void setCoefficients();
double pdf( double x );
double trapezium( double a, double b, int n, double f( double ) );

//======================================================================

int main()
{
   const int n = 1000;   // number of intervals for integration; increase if necessary
   double a, b;
   
   cout << "Input lower limit, a: "        ;   cin >> a;
   cout << "Input upper limit, b: "        ;   cin >> b;
   cout << "Input degrees of freedom, nu: ";   cin >> nu;

   setCoefficients();
   cout << "\nProbability: " << trapezium( a, b, n, pdf ) << '\n';
}

//======================================================================

void setCoefficients()
{
   double pi = 4.0 * atan( 1.0 );
   cnu = tgamma( 0.5 * ( nu + 1.0 ) ) / tgamma( 0.5 * nu ) / sqrt( nu * pi );
}

//======================================================================


double pdf( double x )   // pdf of the student's t distribution
{
   return cnu * pow( 1.0 + x * x / nu, -0.5 * ( nu + 1.0 ) );
}

//======================================================================

double trapezium( double a, double b, int n, double f( double ) )     // numerical integration of f(x) from a to b
{
   double dx = ( b - a ) / n;
   double integral = f( a ) + f(b);
   for ( int i = 1; i <= n - 1; i++ ) integral += 2.0 * f( a + i * dx );
   integral *= dx / 2.0;
   return integral;
}

//====================================================================== 


Input lower limit, a: 0
Input upper limit, b: 1.1
Input degrees of freedom, nu: 9

Probability: 0.350059
I am very very pleased, thank you very much sir. How can I pay this goodness :)

I should just make sure that you understand the code.

If you feel like paying then there are plenty of kids around the world who would prefer to be sitting in front of a computer than languishing in a refugee camp.
Topic archived. No new replies allowed.