Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
tStudent.C File Reference

Detailed Description

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

root[0]: .x tStudent.C

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

#include "TH1.h"
#include "TF1.h"
#include "TCanvas.h"
#include "TSystem.h"
#include "TLegend.h"
#include "TLegendEntry.h"
#include "Math/DistFunc.h"
void tStudent()
{
/* gSystem->Load("libMathMore");*/
// this is the way to force load of MathMore in Cling
int n=100;
double a=-5.;
double b=5.;
//double r = 3;
TF1* pdf = new TF1("pdf", "ROOT::Math::tdistribution_pdf(x,3.0)", a,b);
TF1* cum = new TF1("cum", "ROOT::Math::tdistribution_cdf(x,3.0)", a,b);
TH1D* quant = new TH1D("quant", "", 9, 0, 0.9);
for(int i=1; i < 10; i++)
quant->Fill((i-0.5)/10.0, ROOT::Math::tdistribution_quantile((1.0*i)/10, 3.0 ) );
double xx[10];
xx[0] = -1.5;
for(int i=1; i<9; i++)
xx[i]= quant->GetBinContent(i);
xx[9] = 1.5;
TH1D* pdfq[10];
//int nbin = n/10.0;
for(int i=0; i < 9; i++) {
int nbin = n * (xx[i+1]-xx[i])/3.0 + 1.0;
TString name = "pdf";
name += i;
pdfq[i]= new TH1D(name, "", nbin,xx[i],xx[i+1] );
for(int j=1; j<nbin; j++) {
double x= j*(xx[i+1]-xx[i])/nbin + xx[i];
}
}
TCanvas *Canvas = new 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");
Canvas->Divide(2, 2);
Canvas->cd(1);
pdf->SetLineWidth(2);
pdf->DrawCopy();
Canvas->cd(2);
cum->SetLineWidth(2);
cum->Draw();
Canvas->cd(3);
quant->Draw();
quant->SetLineWidth(2);
quant->SetStats(false);
Canvas->cd(4);
pdfq[0]->SetTitle("Student t & its quantiles");
pdf->SetTitle("");
pdf->Draw();
//pdfq[0]->SetAxisRange(-1.5, 0, 1.5,1.0);
pdfq[0]->SetTitle("Student t & its quantiles");
for(int i=0; i < 9; i++) {
pdfq[i]->SetStats(false);
pdfq[i]->SetFillColor(i+1);
pdfq[i]->Draw("same");
}
Canvas->Modified();
Canvas->cd();
}
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
@ kRed
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
char name[80]
Definition TGX11.cxx:110
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:37
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:43
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:40
The Canvas class.
Definition TCanvas.h:23
TVirtualPad * cd(Int_t subpadnumber=0) override
Set current canvas & pad.
Definition TCanvas.cxx:716
1-Dim function class
Definition TF1.h:233
void SetTitle(const char *title="") override
Set function title if title has the form "fffffff;xxxx;yyyy", it is assumed that the function title i...
Definition TF1.cxx:3558
void Draw(Option_t *option="") override
Draw this function with its current attributes.
Definition TF1.cxx:1335
virtual TF1 * DrawCopy(Option_t *option="") const
Draw a copy of this function with its current attributes.
Definition TF1.cxx:1365
1-D histogram with a double per channel (see TH1 documentation)
Definition TH1.h:664
void SetTitle(const char *title) override
Change/set the title.
Definition TH1.cxx:6682
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3340
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3062
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
Definition TH1.cxx:9186
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition TH1.cxx:5025
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition TH1.cxx:8954
void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0) override
Automatic pad generation by division.
Definition TPad.cxx:1153
void Modified(Bool_t flag=true) override
Mark pad modified Will be repainted when TCanvas::Update() will be called next time.
Definition TPad.cxx:7255
Basic string class.
Definition TString.h:139
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...
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Author
Magdalena Slawinska

Definition in file tStudent.C.