safeIntegrate  R Documentation 
Adaptive quadrature of functions of one variable over a finite or infinite interval.
safeIntegrate(f, lower, upper, subdivisions=100, rel.tol = .Machine$double.eps^0.25, abs.tol = rel.tol, stop.on.error = TRUE, keep.xy = FALSE, aux = NULL, ...)
f 
An R function taking a numeric first argument and returning a numeric vector of the same length. Returning a nonfinite element will generate an error. 
lower, upper 
The limits of integration. Can be infinite. 
subdivisions 
The maximum number of subintervals. 
rel.tol 
Relative accuracy requested. 
abs.tol 
Absolute accuracy requested. 
stop.on.error 
Logical. If true (the default) an error stops the
function. If false some errors will give a result with a warning in
the 
keep.xy 
Unused. For compatibility with S. 
aux 
Unused. For compatibility with S. 
... 
Additional arguments to be passed to 
This function is just a wrapper around
integrate
to check for equality of
upper
and lower
. A check is made using
all.equal
. When numerical equality is
detected, if lower
(and hence upper
) is infinite, the
value of the integral and the absolute error are both set to 0. When
lower
is finite, the value of the integral is set to 0, and the
absolute error to the average of the function values at upper
and
lower
times the difference between upper
and lower
.
When upper
and lower
are determined to be different, the
result is exactly as given by integrate
.
A list of class "integrate"
with components:
value 
The final estimate of the integral. 
abs.error 
Estimate of the modulus of the absolute error. 
subdivisions 
The number of subintervals produced in the subdivision process. 
message 

call 
The matched call. 
The function integrate
and
all.equal
.
integrate(dnorm, 1.96, 1.96) safeIntegrate(dnorm, 1.96, 1.96) # Same as for integrate() integrate(dnorm, Inf, Inf) safeIntegrate(dnorm, Inf, Inf) # Same as for integrate() integrate(dnorm, 1.96, 1.96) # OK here but can give an error safeIntegrate(dnorm, 1.96, 1.96) integrate(dnorm, Inf, Inf) safeIntegrate(dnorm, Inf, Inf) # Avoids nonsense answer integrate(dnorm, Inf, Inf) safeIntegrate(dnorm, Inf, Inf) # Avoids nonsense answer
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.