ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Function.C
Go to the documentation of this file.
1 #include<TRInterface.h>
2 
3 using namespace ROOT::R;
4 void Function()
5 {
7  r.SetVerbose(1);
8  ////////////////////////////////////////
9  //defining functions to be used from R//
10  ////////////////////////////////////////
11  TRFunctionImport c("c");
12  TRFunctionImport list("list");
13  TRFunctionImport asformula("as.formula");
14  TRFunctionImport nls("nls");
15  TRFunctionImport confint("confint");
16  TRFunctionImport summary("summary");
17  TRFunctionImport print("print");
18  TRFunctionImport plot("plot");
19  TRFunctionImport lines("lines");
20  TRFunctionImport devnew("dev.new");
21  TRFunctionImport devoff("dev.off");
22  TRFunctionImport devcur("dev.cur");
23  TRFunctionImport min("min");
24  TRFunctionImport max("max");
25  TRFunctionImport seq("seq");
26  TRFunctionImport predict("predict");
27 
28  r<<"options(device='pdf')";
29 
30  ////////////////////////
31  //doing the procedure //
32  ////////////////////////
33  TRObject xdata = c(-2,-1.64,-1.33,-0.7,0,0.45,1.2,1.64,2.32,2.9);
34  TRObject ydata = c(0.699369,0.700462,0.695354,1.03905,1.97389,2.41143,1.91091,0.919576,-0.730975,-1.42001);
35 
36  TRDataFrame data;
37  data["xdata"]=xdata;
38  data["ydata"]=ydata;
39 
40  // fit = nls(ydata ~ p1*cos(p2*xdata) + p2*sin(p1*xdata), start=list(p1=1,p2=0.2))
41  TRObject fit = nls(asformula("ydata ~ p1*cos(p2*xdata) + p2*sin(p1*xdata)"),Label["data"]=data, Label["start"]=list(Label["p1"]=1,Label["p2"]=0.2));
42  print(summary(fit));
43 
44  print(confint(fit));
45 
46  devnew("Fitting Regression");
47  plot(xdata,ydata);
48 
49  TRObject xgrid=seq(min(xdata),max(xdata),Label["len"]=10);
50  lines(xgrid,predict(fit,xgrid),Label["col"] = "green");
51  devoff(Label["which"] = devcur() );
52 }
static Vc_ALWAYS_INLINE int_v min(const int_v &x, const int_v &y)
Definition: vector.h:433
return c
tuple lines
Definition: mrt.py:16
void plot(TString fname="data.root", TString var0="var0", TString var1="var1")
Definition: createData.C:17
This is a class to get ROOT's objects from R's objects
Definition: TRObject.h:73
ROOT::R::TRInterface & r
Definition: Object.C:4
This is a class to pass functions from ROOT to R.
void SetVerbose(Bool_t status)
Method to set verbose mode, that produce extra output.
static TRInterface & Instance()
static method to get an TRInterface instance reference
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
Definition: vector.h:440
void Function()
Definition: Function.C:4
Rcpp::internal::NamedPlaceHolder Label
Definition: RExports.cxx:14
TRandom3 R
a TMatrixD.
Definition: testIO.cxx:28
This is a class to create DataFrames from ROOT to R
Definition: TRDataFrame.h:183