ROOT
6.10/09
Reference Guide
ROOT Home Page
Main Page
Tutorials
User's Classes
+
Namespaces
Namespace List
+
Namespace Members
+
All
<
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
+
Functions
<
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
+
Variables
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
x
y
z
+
Typedefs
a
b
c
d
e
f
g
h
i
l
m
n
o
p
q
r
s
u
w
x
+
Enumerations
a
e
f
g
m
p
t
w
y
+
Enumerator
b
c
d
e
f
g
h
i
k
l
m
n
o
p
r
s
w
+
All Classes
Class List
Class Index
Class Hierarchy
+
Class Members
+
All
:
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
+
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
+
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
+
Typedefs
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
r
s
t
v
w
x
y
+
Enumerations
a
b
c
d
e
f
g
h
i
l
m
o
p
r
s
w
y
+
Enumerator
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
+
Properties
f
+
Related Functions
:
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
+
Files
File List
+
File Members
+
All
1
2
3
4
5
6
7
8
9
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
+
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
+
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
+
Typedefs
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
+
Enumerations
c
e
f
i
l
m
p
r
u
x
+
Enumerator
a
c
d
e
f
g
h
i
k
l
m
n
o
p
r
s
v
w
x
y
z
+
Macros
1
2
3
4
5
6
7
8
9
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Release Notes
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
tutorials
r
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() );
}
}
Author
Definition in file
Function.C
.