Logo ROOT   6.14/05
Reference Guide
tStudent.py
Go to the documentation of this file.
1 ## \file
2 ## \ingroup tutorial_math
3 ## \notebook
4 ## Example macro describing the student t distribution
5 ##
6 ## ~~~{.cpp}
7 ## root[0]: .x tStudent.C
8 ## ~~~
9 ##
10 ## It draws the pdf, the cdf and then 10 quantiles of the t Student distribution
11 ##
12 ## based on Magdalena Slawinska's tStudent.C
13 ##
14 ## \macro_image
15 ## \macro_code
16 ##
17 ## \author Juan Fernando Jaramillo Botero
18 
19 from ROOT import TH1D, TF1, TCanvas, kRed, kBlue
20 import ROOT
21 
22 
23 # This is the way to force load of MathMore in Cling
24 ROOT.Math.MathMoreLibrary.Load()
25 
26 # Create the pdf and the cumulative distributions
27 n = 100
28 a = -5.
29 b = 5.
30 pdf = TF1("pdf", "ROOT::Math::tdistribution_pdf(x,3.0)", a, b)
31 cum = TF1("cum", "ROOT::Math::tdistribution_cdf(x,3.0)", a, b)
32 
33 # Create the histogram and fill it with the quantiles
34 quant = TH1D("quant", "", 9, 0, 0.9)
35 
36 for i in range(1, 10):
37  quant.Fill((i-0.5)/10.0, ROOT.Math.tdistribution_quantile(0.1 * i,
38  3.0))
39 
40 # For each quantile fill with the pdf
41 xx = [-1.5] + [quant.GetBinContent(i)for i in range(1, 9)] + [1.5]
42 pdfq = []
43 for i in range(9):
44  nbin = int(n * (xx[i+1] - xx[i]) / 3.0 + 1.0)
45  name = "pdf%d" % i
46  pdfq.append(TH1D(name, "", nbin, xx[i], xx[i+1]))
47  for j in range(1, nbin):
48  x = j * (xx[i+1] - xx[i]) / nbin + xx[i]
49  pdfq[i].SetBinContent(j, ROOT.Math.tdistribution_pdf(x, 3))
50 
51 # Create the Canvas and divide in four draws, for every draw set the line width
52 # the title, and the line color.
53 Canvas = TCanvas("DistCanvas", "Student Distribution graphs", 10, 10, 800, 700)
54 pdf.SetTitle("Student t distribution function")
55 cum.SetTitle("Cumulative for Student t")
56 quant.SetTitle("10-quantiles for Student t")
57 Canvas.Divide(2, 2)
58 Canvas.cd(1)
59 pdf.SetLineWidth(2)
60 pdf.DrawCopy()
61 Canvas.cd(2)
62 cum.SetLineWidth(2)
63 cum.SetLineColor(kRed)
64 cum.Draw()
65 Canvas.cd(3)
66 quant.Draw()
67 quant.SetLineWidth(2)
68 quant.SetLineColor(kBlue)
69 quant.SetStats(0)
70 Canvas.cd(4)
71 pdfq[0].SetTitle("Student t & its quantiles")
72 pdf.SetTitle("")
73 pdf.Draw()
74 pdfq[0].SetTitle("Student t & its quantiles")
75 
76 # Set the colors in every quantile.
77 i = 1
78 for pd in pdfq[1:]:
79  pd.SetStats(0)
80  i += 1
81  pd.SetFillColor(i)
82  pd.Draw("same")
83 Canvas.Modified()
double tdistribution_pdf(double x, double r, double x0=0)
Probability density function of Student's t-distribution.
1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:610
The Canvas class.
Definition: TCanvas.h:31
double tdistribution_quantile(double z, double r)
Inverse ( ) of the cumulative distribution function of the lower tail of Student's t-distribution (td...
1-Dim function class
Definition: TF1.h:211