Using numerical integration, this function computes
the area under a distance function between two limits (w.lo
and w.hi
).
integration.constant(dist, density, a, covars, w.lo, w.hi, series,
expansions, pointSurvey)
Vector of detection distance values.
A likelihood function for which the
integration constant is sought. This function
must be capable of evaluating values between w.lo
and w.hi
and have the following parameters:
a = Parameter vector.
dist = Vector of distances.
covars = If the density allows covariates, the covariate matrix.
w.lo = Lower limit or left truncation value.
w.hi = Upper limit or right truncation value.
series = Form of the series expansions, if any.
expansions = Number of expansion terms.
scale = Whether to scale function to integrate to 1.
Vector of parameters to pass to density
.
Matrix of covariate values.
The lower limit of integration, or the left truncation value for perpendicular distances.
The upper limit of integration, or the right truncation value for perpendicular distances.
The series to use for expansions.
If expansions
> 0, this string
specifies the type of expansion. Valid values at
present are 'simple', 'hermite', and 'cosine'.
Number of expansions in density
.
Boolean. TRUE if point transect data, FALSE if line transect data.
A scalar (or vector of scalars if covariates are present)
that is the area under density
between w.lo
and w.hi
.
This scalar can be used as a divisor to scale density such that
it integrates to 1.0. If x = density(…), then
x / integration.constant(density, …)
will integrate to 1.0.
The trapezoid rule is used to numerically integrate
density
from w.lo
to w.hi
. Two-hundred
(200) equal-sized trapezoids are used in the integration. The number
of trapezoids to use is fixed and cannot be changed without
re-writing this routine.
# NOT RUN {
# Can put any number for first argument (1 used here)
scl <- integration.constant(dist=1, density=uniform.like, covars = NULL,
pointSurvey = FALSE, w.lo=0, w.hi = 100,
expansions = 0, a=c(75,25))
print(scl) # Should be 75.1
x <- seq(0,100,length=200)
y <- uniform.like( c(75,25), x, scale=FALSE ) / scl
int.y <- (x[2]-x[1]) * sum(y[-length(y)]+y[-1]) / 2 # the trapezoid rule, should be 1.0
print(int.y) # Should be 1
# }
Run the code above in your browser using DataLab