Logo ROOT   6.16/01
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
19from ROOT import TH1D, TF1, TCanvas, kRed, kBlue
20import ROOT
21
22
23# This is the way to force load of MathMore in Cling
24ROOT.Math.MathMoreLibrary.Load()
25
26# Create the pdf and the cumulative distributions
27n = 100
28a = -5.
29b = 5.
30pdf = TF1("pdf", "ROOT::Math::tdistribution_pdf(x,3.0)", a, b)
31cum = TF1("cum", "ROOT::Math::tdistribution_cdf(x,3.0)", a, b)
32
33# Create the histogram and fill it with the quantiles
34quant = TH1D("quant", "", 9, 0, 0.9)
35
36for 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
41xx = [-1.5] + [quant.GetBinContent(i)for i in range(1, 9)] + [1.5]
42pdfq = []
43for 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.
53Canvas = TCanvas("DistCanvas", "Student Distribution graphs", 10, 10, 800, 700)
54pdf.SetTitle("Student t distribution function")
55cum.SetTitle("Cumulative for Student t")
56quant.SetTitle("10-quantiles for Student t")
57Canvas.Divide(2, 2)
58Canvas.cd(1)
59pdf.SetLineWidth(2)
60pdf.DrawCopy()
61Canvas.cd(2)
62cum.SetLineWidth(2)
63cum.SetLineColor(kRed)
64cum.Draw()
65Canvas.cd(3)
66quant.Draw()
67quant.SetLineWidth(2)
68quant.SetLineColor(kBlue)
69quant.SetStats(0)
70Canvas.cd(4)
71pdfq[0].SetTitle("Student t & its quantiles")
72pdf.SetTitle("")
73pdf.Draw()
74pdfq[0].SetTitle("Student t & its quantiles")
75
76# Set the colors in every quantile.
77i = 1
78for pd in pdfq[1:]:
79 pd.SetStats(0)
80 i += 1
81 pd.SetFillColor(i)
82 pd.Draw("same")
83Canvas.Modified()
The Canvas class.
Definition: TCanvas.h:31
1-Dim function class
Definition: TF1.h:211
1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:614
double tdistribution_pdf(double x, double r, double x0=0)
Probability density function of Student's t-distribution.
double tdistribution_quantile(double z, double r)
Inverse ( ) of the cumulative distribution function of the lower tail of Student's t-distribution (td...