Learn R Programming

Rdistance (version 1.3.2)

uniform.like: Standard likelihood functions for distance analyses.

Description

These functions compute likelihood contributions for off-transect sighting distances, scaled appropriately, for use as a distance likelihood.

Usage

uniform.like(a, dist, w.lo = 0, w.hi = max(dist),
series = "cosine", expansions = 0, scale = TRUE)
halfnorm.like(a, dist, w.lo = 0, w.hi = max(dist),
series = "cosine", expansions = 0, scale = TRUE)
negexp.like(a, dist, w.lo = 0, w.hi = max(dist),
series = "cosine", expansions = 0, scale = TRUE)
hazrate.like(a, dist, w.lo = 0, w.hi = max(dist),
series = "cosine", expansions = 0, scale = TRUE)

Arguments

a

A vector of likelihood parameter values. Length and meaning depend on series and expansions. If no expansion terms were called for (i.e., expansions = 0), the distance likelihoods contain one or two canonical parameters (see Details). If one or more expansions are called for, coefficients for the expansion terms follow coefficients for the canonical parameters. If p is the number of canonical parameters, coefficients for the expansion terms are a[(p+1):length(a)].

dist

A numeric vector containing the observed distances.

w.lo

Scalar value of the lowest observable distance. This is the left truncation of sighting distances in dist. Same units as dist. Values less than w.lo are allowed in dist, but are ignored and their contribution to the likelihood is set to NA in the output.

w.hi

Scalar value of the largest observable distance. This is the right truncation of sighting distances in dist. Same units as dist. Values greater than w.hi are allowed in dist, but are ignored and their contribution to the likelihood is set to NA in the output.

series

A string specifying the type of expansion to use. Currently, valid values are 'simple', 'hermite', and 'cosine'; but, see F.dfunc.estim about defining other series.

expansions

A scalar specifying the number of terms in series. Depending on the series, this could be 0 through 5. The default of 0 equates to no expansion terms of any type.

scale

Logical scaler indicating whether or not to scale the likelihood so it integrates to 1. This parameter is used to stop recursion in other functions. If scale equals TRUE, a numerical integration routine (integration.constant) is called, which in turn calls this likelihood function again with scale = FALSE. Thus, this routine knows when its values are being used to compute the likelihood and when its value is being used to compute the constant of integration. All user defined likelihoods must have and use this parameter.

Value

All likelihood functions return a numeric vector the same length and order as dist containing the likelihood contribution for corresponding distances in dist. Assuming L is the returned vector from one of these functions, the full log likelihood of all the data is -sum(log(L), na.rm=T). Note that the returned likelihood value for distances less than w.lo or greater than w.hi is NA, and thus it is prudent to use na.rm=TRUE in the sum.

If scale = TRUE, the integral of the likelihood from w.lo to w.hi is 1.0. If scale = FALSE, the integral of the likelihood is an arbitrary.

Details

Uniform: The uniform likelihood is not technically uniform, but can look similar to a uniform if the data warrant. The uniform likelihood is actually the heavy side or logistic function of the form, $$f(x|a,b) = 1 - \frac{1}{1 + \exp(-b(x-a))} = \frac{\exp( -b(x-a) )}{1 + exp( -b(x-a) )},$$ where \(a\) and \(b\) are the parameters to be estimated. Parameter \(a\) can be thought of as the location of the "approximate upper limit" of an uniform distribution's support by noting that that the inverse likelihood of 0.5 is a before scaling (i.e., uniform.like(c(a,b),a,scale=FALSE) equals 0.5). Parameter b is the "knee" or sharpness of the bend at a and estimates the degree to which observations decline at the outer limit of sightability. Note that, prior to scaling for g.x.scl, the slope of the likelihood at \(a\) is \(-b/4\). After scaling for g.x.scl, the inverse of g.x.scl/2 is close to a/f(0). If \(b\) is large, the "knee" is sharp and the density of observations declines rapidly at \(a/f(0)\). In this case, the likelihood can look like a uniform distribution with support from w.lo to \(a/f(0)\). If \(b\) is small, the "knee" is shallow and the density of observations declines in an elongated "S" shape pivoting at a/f(0). As b grows large and assuming f(0) = 1, the effective strip width approaches a from above. See Examples for plots using large and small values of \(b\).

Half Normal: The half-normal likelihood is $$f(x|a) = \exp(-x^2 / a^2)$$ where \(a\) is the standard error parameter to be estimated. If \(a\) is small, width of the half-normal is small and sightability declines rapidly as distance increases. If \(a\) is large, width of the half-hormal is large and sightability may not decline much between \(w.lo\) and \(w.hi\).

Negative Exponential: The negative exponential likelihood is $$f(x|a) = \exp(-ax)$$ where \(a\) is a slope parameter to be estimated.

Hazard Rate: The hazard rate likelihood is $$f(x|a,b) = 1 - \exp(-(x/a)^(-b))$$ where \(a\) is a variance parameter, and \(b\) is a slope parameter to be estimated.

Expansion Terms: If expansions = k (k > 0), the expansion function specified by series is called (see for example cosine.expansion). Assuming \(h_{ij}(x)\) is the \(j^{th}\) expansion term for the \(i^{th}\) distance and that \(c_1, c_2, \dots, c_k\) are (estimated) coefficients for the expansion terms, the likelihood contribution for the \(i^{th}\) distance is, $$f(x|a,b,c_1,c_2,\dots,c_k) = f(x|a,b)(1 + \sum_{j=1}^{k} c_j h_{ij}(x)).$$

See Also

F.dfunc.estim, Gamma.like

Examples

Run this code
# NOT RUN {
# }
# NOT RUN {
x <- seq( 0, 100, length=100)

#   ------ UNIFORM     
#   Plots showing effects of parameter a
plot(x, uniform.like(c(25,15), x))
plot(x, uniform.like(c(75,15), x))

#   Plots showing effects of parameter b
plot(x, uniform.like(c(50,20), x))
plot(x, uniform.like(c(50,0.5), x))

#   Plots showing effects of expansion terms
plot(x, uniform.like(c(50,20,3), x, expansions=1))
plot(x, uniform.like(c(50,20,3,-3), x, expansions=2))
plot(x, uniform.like(c(50,20,3), x, expansions=1, series="hermite"))

#   ------ HALF-NORMAL     
#   Plots showing effects of parameter a
plot(x, halfnorm.like(c(25), x))
plot(x, halfnorm.like(c(75), x))

#   Plots showing effects of expansion terms
plot(x, halfnorm.like(c(50,3), x, expansions=1))
plot(x, halfnorm.like(c(50,3,-3), x, expansions=2))
plot(x, halfnorm.like(c(50,3), x, expansions=1, series="hermite"))

#   ------ NEGATIVE EXPONENTIAL     
#   Plots showing effects of parameter a
plot(x, negexp.like(c(25), x))
plot(x, negexp.like(c(75), x))

#   Plots showing effects of expansion terms
plot(x, negexp.like(c(50,3), x, expansions=1))
plot(x, negexp.like(c(50,3,-3), x, expansions=2))
plot(x, negexp.like(c(50,3), x, expansions=1, series="hermite"))


#   ------ HAZARD RATE     
#   Plots showing effects of parameter a
plot(x, hazrate.like(c(25,25), x))
plot(x, hazrate.like(c(75,25), x))

#   Plots showing effects of parameter b
plot(x, hazrate.like(c(50,20), x))
plot(x, hazrate.like(c(50,0.5), x))

#   Plots showing effects of expansion terms
plot(x, hazrate.like(c(50,25,3), x, expansions=1))
plot(x, hazrate.like(c(50,25,3,-3), x, expansions=2))
plot(x, hazrate.like(c(50,25,3), x, expansions=1, series="hermite"))


#   ------ Estimate distance functions and plot
#   Generate half-norm data
set.seed(8383838)
x <- rnorm(1000) * 100
x <- x[ 0 < x & x < 100 ]
un.dfunc <- F.dfunc.estim( x, likelihood="uniform", w.hi = 100)
hn.dfunc <- F.dfunc.estim( x, likelihood="halfnorm", w.hi = 100)
ne.dfunc <- F.dfunc.estim( x, likelihood="negexp", w.hi = 100)
hz.dfunc <- F.dfunc.estim( x, likelihood="hazrate", w.hi = 100)

par(mfrow=c(2,2))
plot(un.dfunc)
plot(hn.dfunc)
plot(ne.dfunc)
plot(hz.dfunc)
# }

Run the code above in your browser using DataLab