Learn R Programming

moveHMM (version 1.11)

nLogLike: Negative log-likelihood function

Description

Negative log-likelihood function

Usage

nLogLike(
  wpar,
  nbStates,
  bounds,
  parSize,
  data,
  covs,
  stepDist = c("gamma", "weibull", "lnorm", "exp"),
  angleDist = c("vm", "wrpcauchy", "none"),
  angleMean = NULL,
  zeroInflation = FALSE,
  stationary = FALSE,
  knownStates = NULL
)

Value

The negative log-likelihood of the parameters given the data.

Arguments

wpar

Vector of working parameters.

nbStates

Number of states of the HMM.

bounds

Matrix with 2 columns and as many rows as there are elements in wpar. Each row contains the lower and upper bound for the correponding parameter.

parSize

Vector of two values: number of parameters of the step length distribution, number of parameters of the turning angle distribution.

data

An object moveData.

covs

Model matrix for transition probabilities

stepDist

Name of the distribution of the step lengths (as a character string). Supported distributions are: gamma, weibull, lnorm, exp. Default: gamma.

angleDist

Name of the distribution of the turning angles (as a character string). Supported distributions are: vm, wrpcauchy. Set to "none" if the angle distribution should not be estimated. Default: vm.

angleMean

Vector of means of turning angles if not estimated (one for each state). Default: NULL (the angle mean is estimated).

zeroInflation

TRUE if the step length distribution is inflated in zero. Default: FALSE. If TRUE, initial values for the zero-mass parameters should be included in stepPar0.

stationary

FALSE if there are covariates. If TRUE, the initial distribution is considered equal to the stationary distribution. Default: FALSE.

knownStates

Vector of values of the state process which are known prior to fitting the model (if any). Default: NULL (states are not known). This should be a vector with length the number of rows of 'data'; each element should either be an integer (the value of the known states) or NA if the state is not known.

Examples

Run this code
if (FALSE) {
# data is a moveData object (as returned by prepData), automatically loaded with the package
simPar <- example$simPar
par0 <- example$par0

estAngleMean <- is.null(simPar$angleMean)
bounds <- moveHMM:::parDef(simPar$stepDist,simPar$angleDist,simPar$nbStates,
                           estAngleMean,simPar$zeroInflation)$bounds
parSize <- moveHMM:::parDef(simPar$stepDist,simPar$angleDist,simPar$nbStates,
                            estAngleMean,simPar$zeroInflation)$parSize

par <- c(par0$stepPar0,par0$anglePar0)
wpar <- moveHMM:::n2w(par,bounds,par0$beta0,par0$delta0,simPar$nbStates,FALSE)

covs <- model.matrix(example$m$conditions$formula, example$data)

l <- nLogLike(wpar=wpar,nbStates=simPar$nbStates,bounds=bounds,parSize=parSize,
              data=data,covs=covs, stepDist=simPar$stepDist,
              angleDist=simPar$angleDist,
              zeroInflation=simPar$zeroInflation)
}

Run the code above in your browser using DataLab