nLogLike: Negative log-likelihood function

View source: R/nLogLike.R

nLogLikeR Documentation

Negative log-likelihood function

Description

Negative log-likelihood function

Usage

nLogLike(
  optPar,
  nbStates,
  formula,
  bounds,
  parSize,
  data,
  dist,
  covs,
  estAngleMean,
  circularAngleMean,
  consensus,
  zeroInflation,
  oneInflation,
  stationary = FALSE,
  fullDM,
  DMind,
  Bndind,
  knownStates,
  fixPar,
  wparIndex,
  nc,
  meanind,
  covsDelta,
  workBounds,
  prior = NULL,
  betaCons = NULL,
  betaRef,
  deltaCons = NULL,
  optInd = NULL,
  recovs = NULL,
  g0covs = NULL,
  mixtures = 1,
  covsPi,
  recharge = NULL,
  aInd
)

Arguments

optPar

Vector of working parameters.

nbStates

Number of states of the HMM.

formula

Regression formula for the transition probability covariates.

bounds

Named list of 2-column matrices specifying bounds on the natural (i.e, real) scale of the probability distribution parameters for each data stream.

parSize

Named list indicating the number of natural parameters of the data stream probability distributions

data

An object momentuHMMData.

dist

Named list indicating the probability distributions of the data streams.

covs

data frame containing the beta model covariates (if any)

estAngleMean

Named list indicating whether or not to estimate the angle mean for data streams with angular distributions ('vm' and 'wrpcauchy').

circularAngleMean

Named list indicating whether to use circular-linear or circular-circular regression on the mean of circular distributions ('vm' and 'wrpcauchy') for turning angles. See fitHMM.

consensus

Named list indicating whether to use the circular-circular regression consensus model

zeroInflation

Named list of logicals indicating whether the probability distributions of the data streams are zero-inflated.

oneInflation

Named list of logicals indicating whether the probability distributions of the data streams are one-inflated.

stationary

FALSE if there are time-varying covariates in formula or any covariates in formulaDelta. If TRUE, the initial distribution is considered equal to the stationary distribution. Default: FALSE.

fullDM

Named list containing the full (i.e. not shorthand) design matrix for each data stream.

DMind

Named list indicating whether fullDM includes individual- and/or temporal-covariates for each data stream specifies (-1,1) bounds for the concentration parameters instead of the default [0,1) bounds.

Bndind

Named list indicating whether DM is NULL with default parameter bounds for each data stream.

knownStates

Vector of values of the state process which are known prior to fitting the model (if any).

fixPar

Vector of working parameters which are assumed known prior to fitting the model (NA indicates parameters is to be estimated).

wparIndex

Vector of indices for the elements of fixPar that are not NA.

nc

indicator for zeros in fullDM

meanind

index for circular-circular regression mean angles with at least one non-zero entry in fullDM

covsDelta

data frame containing the delta model covariates (if any)

workBounds

named list of 2-column matrices specifying bounds on the working scale of the probability distribution, transition probability, and initial distribution parameters

prior

A function that returns the log-density of the working scale parameter prior distribution(s)

betaCons

Matrix of the same dimension as beta0 composed of integers identifying any equality constraints among the t.p.m. parameters.

betaRef

Indices of reference elements for t.p.m. multinomial logit link.

deltaCons

Matrix of the same dimension as delta0 composed of integers identifying any equality constraints among the initial distribution working scale parameters.

optInd

indices of constrained parameters

recovs

data frame containing the recharge model theta covariates (if any)

g0covs

data frame containing the recharge model g0 covariates (if any)

mixtures

Number of mixtures for the state transition probabilities

covsPi

data frame containing the pi model covariates

recharge

recharge model specification (only used for hierarchical models)

aInd

vector of indices of first observation for each animal

Value

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

Examples

## Not run: 
# data is a momentuHMMData object (as returned by prepData), automatically loaded with the package
data <- example$m$data
m<-example$m
Par <- getPar(m)
nbStates <- length(m$stateNames)

inputs <- momentuHMM:::checkInputs(nbStates,m$conditions$dist,Par$Par,m$conditions$estAngleMean,
          m$conditions$circularAngleMean,m$conditions$zeroInflation,m$conditions$oneInflation,
          m$conditions$DM,m$conditions$userBounds,
          m$stateNames)

wpar <- momentuHMM:::n2w(Par$Par,m$conditions$bounds,list(beta=Par$beta),
        log(Par$delta[-1]/Par$delta[1]),nbStates,m$conditions$estAngleMean,
        m$conditions$DM,m$conditions$Bndind,
        m$conditions$dist)

l <- momentuHMM:::nLogLike(wpar,nbStates,m$conditions$formula,m$conditions$bounds,
     inputs$p$parSize,data,inputs$dist,model.matrix(m$conditions$formula,data),
     m$conditions$estAngleMean,m$conditions$circularAngleMean,inputs$consensus,
     m$conditions$zeroInflation,m$conditions$oneInflation,m$conditions$stationary,
     m$conditions$fullDM,m$conditions$DMind,
     m$conditions$Bndind,m$knownStates,unlist(m$conditions$fixPar),
     m$conditions$wparIndex,covsDelta=m$covsDelta,workBounds=m$conditions$workBounds,
     betaRef=m$conditions$betaRef,covsPi=m$covsPi)

## End(Not run)


bmcclintock/momentuHMM documentation built on Oct. 26, 2022, 1 a.m.