Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
pdf012_tStudent.py File Reference

Detailed Description

View in nbviewer Open in SWAN
Example macro describing the student t distribution

It draws the pdf, the cdf and then 10 quantiles of the t Student distribution

based on Magdalena Slawinska's tStudent.C

from ROOT import TH1D, TF1, TCanvas, kRed, kBlue
import ROOT
import numpy as np
# This is the way to force load of MathMore in Cling
# Create the pdf and the cumulative distributions
n = 100
a = -5.
b = 5.
pdf = TF1("pdf", "ROOT::Math::tdistribution_pdf(x,3.0)", a, b)
cum = TF1("cum", "ROOT::Math::tdistribution_cdf(x,3.0)", a, b)
# Create the histogram and fill it with the quantiles
quant = TH1D("quant", "", 9, 0, 0.9)
np.array([(i - 0.5) / 10.0 for i in range(1, 10)]),
np.array([ROOT.Math.tdistribution_quantile(0.1 * i, 3.0) for i in range(1, 10)]),
)
# For each quantile fill with the pdf
xx = []
xx.append(-1.5)
for i in range(1, 9):
pdfq = []
for i in range(9):
nbin = int(n * (xx[i+1] - xx[i]) / 3.0 + 1.0)
name = "pdf%d" % i
pdfq.append(TH1D(name, "", nbin, xx[i], xx[i+1]))
for j in range(1, nbin):
x = j * (xx[i+1] - xx[i]) / nbin + xx[i]
pdfq[i].SetBinContent(j, ROOT.Math.tdistribution_pdf(x, 3))
# Create the Canvas and divide in four draws, for every draw set the line width
# the title, and the line color.
Canvas = TCanvas("DistCanvas", "Student Distribution graphs", 10, 10, 800, 700)
pdf.SetTitle("Student t distribution function")
cum.SetTitle("Cumulative for Student t")
quant.SetTitle("10-quantiles for Student t")
pdfq[0].SetTitle("Student t & its quantiles")
pdfq[0].SetTitle("Student t & its quantiles")
# Set the colors in every quantile.
i = 1
for pd in pdfq[1:]:
i += 1
pd.Draw("same")
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
The Canvas class.
Definition TCanvas.h:23
1-Dim function class
Definition TF1.h:233
1-D histogram with a double per channel (see TH1 documentation)
Definition TH1.h:693
Author
Juan Fernando Jaramillo Botero

Definition in file pdf012_tStudent.py.