huber.like: Huber distance function

View source: R/huber.like.R

huber.likeR Documentation

Huber distance function

Description

Computes the Huber likelihood for use as a distance function. The Huber likelihood is a mixture of an inverted Huber loss and a uniform distribution. The distance function is quadratic from the lowest distance to its first parameter, linear from the first parameter to the sum of its first and second parameter, and constant after that.

Usage

huber.like(a, dist, covars, w.hi = NULL)

Arguments

a

A vector or matrix of covariate and expansion term coefficients. If matrix, dimension is k X p, where k = nrow(a)) is the number of coefficient vectors to evaluate (cases) and p = ncol(a)) is the number of covariate and expansion coefficients in the likelihood (i.e., rows are cases and columns are covariates). If a is a dimensionless vector, it is interpreted as a single row with k = 1. Covariate coefficients in a are the first q values (q <= p), and must be on a log scale.

dist

A numeric vector of length n or a single-column matrix (dimension nX1) containing detection distances at which to evaluate the likelihood.

covars

A numeric vector of length q or a matrix of dimension nXq containing covariate values associated with distances in argument dist.

w.hi

A numeric scalar containing maximum distance. The right-hand cutoff or upper limit. Ignored by some likelihoods (such as halfnorm, negexp, and hazrate), but is a fixed parameter in other likelihoods (such as oneStep and uniform).

Details

The 'huber' likelihood is an inverted version of the Huber loss function, mixed with a uniform at the upper end, and contains three canonical parameters. The 'huber' distance function is a negative quadratic between 0 and its first parameter \theta_1, linear between \theta_1 and \theta_1 + \theta_2, and constant after \theta_1 + \theta_2. Specifically, the 'huber' likelihood is,

f(d|\theta_1,\theta_2, p) = \left(1 - \frac{(1-p)h(d)}{m}\right) \, I(0 \leq d \leq \Theta) \ + \ p \, I(\Theta < d \leq w)

where \Theta = \theta_1 + \theta_2, w = w.hi - w.lo, m = \theta_1(\Theta - 0.5\theta_1) and h(d) is Huber loss between 0 and \Theta, i.e.,

h(d) = 0.5d^2\, I(0 \leq d \leq \theta_1) \ + \ \theta_1(d - 0.5\theta_1)\, I(\theta_1 < d \leq \Theta).

The first parameter, \theta_1, is related to covariates, i.e., log(\theta_1) = \beta_0 + \beta_1x_1 + \ldots + \beta_qx_q. \theta_2 and p are constant across covariate values.

Value

A list containing the following two components:

  • L.unscaled: A matrix of size nXk (n = length dist; k = number of cases = nrow(a)) containing likelihood values evaluated at distances in dist. Each row is associated with a single distance, and each column is associated with a single case (row of a). Values in this matrix are the distance function g(d) which generally have g(0) = 1. These values are "unscaled" likelihood values; they must be scaled (divided by) with the area under g(x) between w.lo and w.hi to form proper likelihood values.

  • params: A nXbXk array of the likelihood's (canonical) parameters in link space (i.e., on log scale; b = number of canonical parameters in the likelihood; k = number of cases). Rows correspond to distances in dist. Columns correspond to parameters (columns of a), and pages correspond to cases (rows of a).

See Also

See Rdistance tutorials for a method to generate random observations from the Huber likelihood.

Examples


t1 <- c(65,80,120)
t2 <- 60
p  <- 0.05
a <- matrix(c(log(t1)
       , rep(t2,3)
       , rep(p,3))
       , 3,3)
d <- seq(0, 200, length=201)
X <- matrix(1,length(d),1)
y <- huber.like(a, d, X)

# Plot showing covariate effects 
plot(range(d), range(y$L.unscaled)
  , type = "n", xlab = "d", ylab = "Huber(d)")
for(i in 1:3){
  # Distance functions
  lines(d
    , y$L.unscaled[,i]
    , col = i
    , lwd= 2)
  # Quadradic to linear transitions
  points(exp(a[i,1])
    , y$L.unscaled[(t1[i]-0.1) < d & d < (t1[i]+0.01),i]
    , pch = 16
    , col = i )
  # Linear to constant transition
  Theta <- exp(a[i,1]) + a[i,2]
  points(Theta
    , y$L.unscaled[(Theta-0.1) < d & d < (Theta+0.1),i]
    , pch = 15
    , col = i )
}


Rdistance documentation built on April 23, 2026, 1:06 a.m.