Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Function.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_r
3/// \notebook -nodraw
4///
5/// \macro_code
6///
7/// \author
8
9using namespace ROOT::R;
10void Function()
11{
13 r.SetVerbose(1);
14
15 // Defining functions to be used from R
17 TRFunctionImport rlist("list");
18 TRFunctionImport asformula("as.formula");
19 TRFunctionImport nls("nls");
20 TRFunctionImport confint("confint");
21 TRFunctionImport summary("summary");
22 TRFunctionImport print("print");
23 TRFunctionImport plot("plot");
24 TRFunctionImport lines("lines");
25 TRFunctionImport devnew("dev.new");
26 TRFunctionImport devoff("dev.off");
27 TRFunctionImport devcur("dev.cur");
28 TRFunctionImport rmin("min");
29 TRFunctionImport rmax("max");
30 TRFunctionImport seq("seq");
31 TRFunctionImport predict("predict");
32
33 r<<"options(device='pdf')";
34
35 // doing the procedure
36 TRObject xdata = c(-2,-1.64,-1.33,-0.7,0,0.45,1.2,1.64,2.32,2.9);
37 TRObject ydata = c(0.699369,0.700462,0.695354,1.03905,1.97389,2.41143,1.91091,0.919576,-0.730975,-1.42001);
38
39 TRDataFrame data;
40 data["xdata"]=xdata;
41 data["ydata"]=ydata;
42
43 // fit = nls(ydata ~ p1*cos(p2*xdata) + p2*sin(p1*xdata), start=list(p1=1,p2=0.2))
44 TRObject fit = nls(asformula("ydata ~ p1*cos(p2*xdata) + p2*sin(p1*xdata)"),Label["data"]=data, Label["start"]=rlist(Label["p1"]=1,Label["p2"]=0.2));
45 print(summary(fit));
46
47 print(confint(fit));
48
49 if (!gROOT->IsBatch()) {
50 devnew("Fitting Regression");
51 plot(xdata,ydata);
52
53 TRObject xgrid=seq(rmin(xdata),rmax(xdata),Label["len"]=10);
54 lines(xgrid,predict(fit,xgrid),Label["col"] = "green");
55 devoff(Label["which"] = devcur() );
56 }
57}
ROOT::R::TRInterface & r
Definition Object.C:4
#define c(i)
Definition RSha256.hxx:101
#define gROOT
Definition TROOT.h:404
Double_t(* Function)(Double_t)
Definition Functor.C:4
This is a class to create DataFrames from ROOT to R.
This is a class to pass functions from ROOT to R.
static TRInterface & Instance()
static method to get an TRInterface instance reference
void SetVerbose(Bool_t status)
Method to set verbose mode, that produce extra output.
This is a class to get ROOT's objects from R's objects.
Definition TRObject.h:70
predict(model, test_X, batch_size=100)
fit(model, train_loader, val_loader, num_epochs, batch_size, optimizer, criterion, save_best, scheduler)
namespace associated R package for ROOT.
Definition RExports.h:53