12#ifndef ROOT_R_TRFunctionImport
13#define ROOT_R_TRFunctionImport
46 //defining functions to be used from R//
48 TRFunctionImport c("c");
49 TRFunctionImport list("list");
50 TRFunctionImport asformula("as.formula");
51 TRFunctionImport nls("nls");
52 TRFunctionImport confint("confint");
53 TRFunctionImport summary("summary");
54 TRFunctionImport print("print");
55 TRFunctionImport plot("plot");
56 TRFunctionImport lines("lines");
57 TRFunctionImport devnew("dev.new");
58 TRFunctionImport devoff("dev.off");
59 TRFunctionImport min("min");
60 TRFunctionImport max("max");
61 TRFunctionImport seq("seq");
62 TRFunctionImport predict("predict");
64 r<<"options(device='png')";//enable plot in png file
67 //doing the procedure //
69 TRObject xdata = c(-2,-1.64,-1.33,-0.7,0,0.45,1.2,1.64,2.32,2.9);
70 TRObject ydata = c(0.699369,0.700462,0.695354,1.03905,1.97389,2.41143,1.91091,0.919576,-0.730975,-1.42001);
76 //fit = nls(ydata ~ p1*cos(p2*xdata) + p2*sin(p1*xdata), start=list(p1=1,p2=0.2)) <- R code
77 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));
82 devnew("Fitting Regression");
85 TRObject xgrid=seq(min(xdata),max(xdata),Label["len"]=10);
86 lines(xgrid,predict(fit,xgrid),Label["col"] = "green");
93 Formula: ydata ~ p1 * cos(p2 * xdata) + p2 * sin(p1 * xdata)
96 Estimate Std. Error t value Pr(>|t|)
97 p1 1.881851 0.027430 68.61 2.27e-12 ***
98 p2 0.700230 0.009153 76.51 9.50e-13 ***
100 Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
102 Residual standard error: 0.08202 on 8 degrees of freedom
104 Number of iterations to convergence: 7
105 Achieved convergence tolerance: 2.189e-06
107 Waiting for profiling to be done...
109 p1 1.8206081 1.9442365
110 p2 0.6794193 0.7209843
112 <h2>Users Guide </h2>
113 <a href="http://oproject.org/tiki-index.php?page=ROOT+R+Users+Guide"> http://oproject.org/tiki-index.php?page=ROOT+R+Users+Guide</a><br>
114 <a href="https://root.cern.ch/drupal/content/how-use-r-root-root-r-interface"> https://root.cern.ch/drupal/content/how-use-r-root-root-r-interface</a>
177 template<>
inline TRObject::operator TRFunctionImport()
#define R(a, b, c, d, e, f, g, h, i)
#define ClassDef(name, id)
Double_t(* Function)(Double_t)
This is a class to pass functions from ROOT to R.
TRFunctionImport(const Rcpp::Function &fun)
TRFunctionImport constructor for Rcpp::DataFrame.
ROOT R was implemented using the R Project library and the modules Rcpp and RInside
This is a class to get ROOT's objects from R's objects.
Mother of all ROOT objects.
Namespace for new ROOT classes and functions.
static constexpr double ns