Venables and B.D. Ripley Chapter 9: Smooth Regression, Figure 9.1
Example is a set of data on 133 observations of acceleration against time for a simulated motorcycle accident, taken from Silverman (1985). The data are read from motorcycle.dat (2 columns of floats)
#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 gr015_smooth()
{
dir.
Append(
"/visualisation/graphs/");
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);
grout = gs->SmoothKern(grin,"normal",2.0);
DrawSmooth(1,"Kernel Smoother: bandwidth = 2.0","times","accel");
grout = gs->SmoothKern(grin,"normal",5.0);
DrawSmooth(2,"Kernel Smoother: bandwidth = 5.0","","");
grout = gs->SmoothLowess(grin,"",0.67);
DrawSmooth(3,"Lowess: f = 2/3","","");
grout = gs->SmoothLowess(grin,"",0.2);
DrawSmooth(4,"Lowess: f = 0.2","","");
grout = gs->SmoothSuper(grin,"",0,0);
DrawSmooth(5,"Super Smoother: bass = 0","","");
grout = gs->SmoothSuper(grin,"",3);
DrawSmooth(6,"Super Smoother: bass = 3","","");
delete gs;
}
int Int_t
Signed integer 4 bytes (int).
double Double_t
Double 8 bytes.
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.
void Draw(Option_t *chopt="") override
Default Draw method for all objects.
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)