Macro to test scatterplot smoothers: ksmooth, lowess, supsmu as described in:
Modern Applied Statistics with S-Plus, 3rd Edition W.N. 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).
#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;
x[vNData] = vX;
y[vNData] = vY;
vNData++;
}
vInput.close();
grin =
new TGraph(vNData,x,y);
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;
}
- Author
- Christian Stratowa, Vienna, Austria
Definition in file motorcycle.C.