ROOT
master
Reference Guide
Loading...
Searching...
No Matches
Function.C File Reference
Tutorials
»
R tutorials
Detailed Description
using namespace
ROOT::R
;
void
Function
()
{
auto
&
r
=
ROOT::R::TRInterface::Instance
();
r
.SetVerbose(1);
// Defining functions to be used from R
TRFunctionImport
c
(
"c"
);
TRFunctionImport
rlist(
"list"
);
TRFunctionImport
asformula(
"as.formula"
);
TRFunctionImport
nls(
"nls"
);
TRFunctionImport
confint(
"confint"
);
TRFunctionImport
summary(
"summary"
);
TRFunctionImport
print(
"print"
);
TRFunctionImport
plot
(
"plot"
);
TRFunctionImport
lines(
"lines"
);
TRFunctionImport
devnew(
"dev.new"
);
TRFunctionImport
devoff(
"dev.off"
);
TRFunctionImport
devcur(
"dev.cur"
);
TRFunctionImport
rmin(
"min"
);
TRFunctionImport
rmax(
"max"
);
TRFunctionImport
seq(
"seq"
);
TRFunctionImport
predict(
"predict"
);
r
<<
"options(device='pdf')"
;
// doing the procedure
TRObject
xdata =
c
(-2,-1.64,-1.33,-0.7,0,0.45,1.2,1.64,2.32,2.9);
TRObject
ydata =
c
(0.699369,0.700462,0.695354,1.03905,1.97389,2.41143,1.91091,0.919576,-0.730975,-1.42001);
TRDataFrame
data
;
data
[
"xdata"
]=xdata;
data
[
"ydata"
]=ydata;
// fit = nls(ydata ~ p1*cos(p2*xdata) + p2*sin(p1*xdata), start=list(p1=1,p2=0.2))
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));
print(summary(fit));
print(confint(fit));
if
(!
gROOT
->IsBatch()) {
devnew(
"Fitting Regression"
);
plot
(xdata,ydata);
TRObject
xgrid=seq(rmin(xdata),rmax(xdata),Label[
"len"
]=10);
lines(xgrid,predict(fit,xgrid),Label[
"col"
] =
"green"
);
devoff(Label[
"which"
] = devcur() );
}
}
c
#define c(i)
Definition
RSha256.hxx:101
plot
winID h TVirtualViewer3D TVirtualGLPainter char TVirtualGLPainter plot
Definition
TGWin32VirtualGLProxy.cxx:53
data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Definition
TGWin32VirtualXProxy.cxx:104
r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Definition
TGWin32VirtualXProxy.cxx:168
gROOT
#define gROOT
Definition
TROOT.h:406
Function
Double_t(* Function)(Double_t)
Definition
Functor.C:4
ROOT::R::TRDataFrame
This is a class to create DataFrames from ROOT to R.
Definition
TRDataFrame.h:176
ROOT::R::TRFunctionImport
This is a class to pass functions from ROOT to R.
Definition
TRFunctionImport.h:114
ROOT::R::TRInterface::Instance
static TRInterface & Instance()
static method to get an TRInterface instance reference
Definition
TRInterface.cxx:187
ROOT::R::TRObject
This is a class to get ROOT's objects from R's objects.
Definition
TRObject.h:70
ROOT::R
namespace associated R package for ROOT.
Definition
RExports.h:71
Author
Definition in file
Function.C
.
tutorials
r
Function.C
ROOT master - Reference Guide Generated on Sat Nov 16 2024 09:39:48 (GVA Time) using Doxygen 1.9.8