Example is a set of data on 133 observations of acceleration against time for a simulated motorcycle accident, taken from Silverman (1985).
#include <fstream>
void DrawSmooth(
Int_t pad,
const char *title,
const char *xt,
const char *yt)
{
TH1F *vFrame =
gPad->DrawFrame(0,-130,60,70);
}
void motorcycle()
{
ifstream vInput;
vInput.open(
Form(
"%smotorcycle.dat",dir.
Data()));
while (1) {
vInput >> vX >> vY;
if (!vInput.good()) break;
vNData++;
}
vInput.close();
vC1 =
new TCanvas(
"vC1",
"Smooth Regression",200,10,900,700);
DrawSmooth(1,"Kernel Smoother: bandwidth = 2.0","times","accel");
DrawSmooth(2,"Kernel Smoother: bandwidth = 5.0","","");
DrawSmooth(3,"Lowess: f = 2/3","","");
DrawSmooth(4,"Lowess: f = 0.2","","");
DrawSmooth(5,"Super Smoother: bass = 0","","");
DrawSmooth(6,"Super Smoother: bass = 3","","");
delete gs;
}
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
TVirtualPad * cd(Int_t subpadnumber=0) override
Set current canvas & pad.
A helper class to smooth TGraph.
TGraph * SmoothLowess(TGraph *grin, Option_t *option="", Double_t span=0.67, Int_t iter=3, Double_t delta=0)
Smooth data with Lowess smoother.
TGraph * SmoothSuper(TGraph *grin, Option_t *option="", Double_t bass=0, Double_t span=0, Bool_t isPeriodic=kFALSE, Double_t *w=nullptr)
Smooth data with Super smoother.
TGraph * SmoothKern(TGraph *grin, Option_t *option="normal", Double_t bandwidth=0.5, Int_t nout=100, Double_t *xout=nullptr)
Smooth data with Kernel smoother.
A TGraph is an object made of two arrays X and Y with npoints each.
void Draw(Option_t *chopt="") override
Draw this graph with its current attributes.
1-D histogram with a float per channel (see TH1 documentation)
virtual void SetTitleSize(Float_t size=0.02, Option_t *axis="X")
Set the axis' title size.
void SetTitle(const char *title) override
Change/set the title.
virtual void SetXTitle(const char *title)
virtual void SetYTitle(const char *title)
virtual TObject * DrawClone(Option_t *option="") const
Draw a clone of this object in the current selected pad with: gROOT->SetSelectedPad(c1).
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.
const char * Data() const
TString & ReplaceAll(const TString &s1, const TString &s2)
TString & Append(const char *cs)