View source: R/integrateNumeric.R
| integrateNumeric | R Documentation |
Numerically integrate under a distance function.
integrateNumeric(
object,
newdata = NULL,
w.lo = NULL,
w.hi = NULL,
Units = NULL,
expansions = NULL,
series = NULL,
isPoints = NULL,
likelihood = NULL
)
object |
Either an Rdistance fitted distance function
(an object that inherits from class "dfunc"; usually produced
by a call to |
newdata |
A data frame containing new values for
the distance function covariates. If NULL and
|
w.lo |
Minimum sighting distance or left-truncation value
if |
w.hi |
Maximum sighting distance or right-truncation value
if |
Units |
Physical units of sighting distances if
|
expansions |
A scalar specifying the number of terms
in |
series |
If |
isPoints |
Boolean. TRUE if integration is for point surveys. FALSE for line-transect surveys. Line-transect surveys integrate under the distance function, g(x), while point surveys integrate under the distance function times distances, xg(x). |
likelihood |
String specifying the likelihood to fit. Built-in likelihoods at present are "halfnorm", "hazrate", and "negexp". |
A vector of areas under the distance functions represented in
object.
If object is a distance function and
newdata is specified, the returned vector's length is
nrow(newdata). If object is a distance function and
newdata is NULL,
returned vector's length is length(distances(object)). If
object is a matrix, return's length is
nrow(object).
Rdistance uses Simpson's composite 1/3 rule to numerically
integrate distance functions from 0 to the maximum sighting distance
(w.hi - w.lo). The number of points evaluated
during numerical integration is controlled by
options(Rdistance_intEvalPts) (default 101).
Option 'Rdistance_intEvalPts' must be odd because Simpson's rule
requires an even number of intervals.
Lower values of 'Rdistance_intEvalPts' increase calculation speeds;
but, decrease accuracy.
'Rdistance_intEvalPts' must be >= 5. A warning is thrown if
'Rdistance_intEvalPts' < 29. Empirical tests by the author
suggest 'Rdistance_intEvalPts' values >= 30 are accurate
to several decimal points for smooth distance functions
(e.g., hazrate, halfnorm, negexp)
and that all 'Rdistance_intEvalPts' >= 101 produce
identical results if the distance function is not smooth.
Details: Let n = options(Rdistance_intEvalPts).
Evaluate the distance function at n equal-spaced
locations {f(x0), f(x1), ..., f(xn)} between 0 and (w.hi - w.lo).
Simpson's composite approximation to the area under the curve is
\frac{1}{3}h(f(x_0) + 4f(x_1) + 2f(x_2) +
4f(x_3) + 2f(x_4) + ... + 2f(x_{n-2}) +
4f(x_{n-1}) + f(x_{n}))
where h is the interval size (w.hi - w.lo) / n.
Physical units on the return values
are the original (linear) units if object contains line-transect data
(e.g., [m]), or square of the original units if object contains
point-transect data (e.g., [m^2]). Point-transect units are squared because
the likelihood is the product of the detection function (which is unitless)
and distances (which have units).
Users will not normally call this function. It is called
internally by nLL and effectiveDistance.
# A halfnorm distance function
fit <- dfuncEstim(sparrowDf, dist~1, likelihood = "halfnorm")
exact <- integrateHalfnormLines(fit)[1,] # exact area
apprx <- integrateNumeric(fit)[1] # Numeric approx
pd <- options(digits = 20)
cbind(exact, apprx)
absDiff <- abs(apprx - exact)
absDiff
options(pd)
# halfnorm approx good to this number of digits
round(log10(absDiff),1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.