bouts2MLE {diveMove} | R Documentation |
Functions to model a mixture of 2 random Poisson processes to identify bouts of behaviour. This follows Langton et al. (1995).
bouts2.mleFUN(x, p, lambda1, lambda2) bouts2.ll(x) bouts2.LL(x) bouts.mle(ll.fun, start, x, ...) bouts2.mleBEC(fit) plotBouts2.mle(fit, x, xlab="x", ylab="Log Frequency", bec.lty=2, ...) plotBouts2.cdf(fit, x, draw.bec=FALSE, bec.lty=2, ...)
x |
Numeric vector with values to model. |
p, lambda1, lambda2 |
Parameters of the mixture of Poisson processes. |
ll.fun |
function returning the negative of the maximum
likelihood function that should be maximized. This should be a
valid minuslogl argument to mle . |
start, ... |
Arguments passed to mle .
For plotBouts2.cdf , arguments passed to
plot.ecdf . For plotBouts2.mle , arguments passed
to curve . |
fit |
mle object. |
xlab, ylab |
Titles for the x and y axes. |
bec.lty |
Line type specification for drawing the BEC reference line. |
draw.bec |
Logical; do we draw the BEC? |
For now only a mixture of 2 Poisson processes is supported. Even in this relatively simple case, it is very important to provide good starting values for the parameters.
One useful strategy to get good starting parameter values is to
proceed in 4 steps. First, fit a broken stick model to the log
frequencies of binned data (see boutinit
), to obtain
estimates of 4 parameters corresponding to a 2-process model (Sibly et
al. 1990). Second, calculate parameter p from the 2 alpha
parameters obtained from the broken stick model, to get 3 tentative
initial values for the 2-process model from Langton et al. (1995).
Third, obtain MLE estimates for these 3 parameters, but using a
reparameterized version of the -log L2 function. Lastly, obtain the
final MLE estimates for the 3 parameters by using the estimates from
step 3, un-transformed back to their original scales, maximizing the
original parameterization of the -log L2 function.
boutinit
can be used to perform step 1. Calculation of
the mixing parameter p in step 2 is trivial from these
estimates. Function bouts2.LL
is a reparameterized
version of the -log L2 function given by Langton et al. (1995), so can
be used for step 3. This uses a logit (see logit
)
transformation of the mixing parameter p, and log
transformations for both density parameters lambda1 and
lambda2. Function bouts2.ll
is the -log L2
function corresponding to the un-transformed model, hence can be used
for step 4.
bouts.mle is the function performing the main job of maximizing the
-log L2 functions, and is essentially a wrapper around
mle
. It only takes the -log L2 function, a list
of starting values, and the variable to be modelled, all of which are
passed to mle
for optimization. Additionally,
any other arguments are also passed to mle
,
hence great control is provided for fitting any of the -log L2
functions.
In practice, step 3 does not pose major problems using the
reparameterized -log L2 function, but it might be useful to use method
“L-BFGS-B” with appropriate lower and upper bounds. Step 4 can
be a bit more problematic, because the parameters are usually on very
different scales. Therefore, it is almost always the rule to use
method “L-BFGS-B”, again bounding the parameter search, as well
as passing a control
list with proper parscale
for
controlling the optimization. See Note
below for useful
constraints which can be tried.
bouts.mle
returns an object of class mle
.
bouts2.mleBEC
and bouts2.mleFUN
return a numeric vector.
bouts2.LL
and bouts2.ll
return a function.
plotBouts2.mle
and plotBouts2.cdf
return nothing, but
produce a plot as side effect.
In the case of a mixture of 2 Poisson processes, useful values for
lower bounds for the bouts.LL
reparameterization are
c(-2, -5, -10)
. For bouts2.ll
, useful lower bounds are
rep(1e-08, 3)
. A useful parscale argument for the latter is
c(1, 0.1, 0.01)
. However, I have only tested this for cases of
diving behaviour in pinnipeds, so these suggested values may not be
useful in other cases.
Sebastian P. Luque spluque@gmail.com
Langton, S.; Collett, D. and Sibly, R. (1995) Splitting behaviour into bouts; a maximum likelihood approach. Behaviour 132, 9-10.
Luque, S.P. and Guinet, C. (2007) A maximum likelihood approach for identifying dive bouts improves accuracy, precision, and objectivity. Behaviour, 144, 1315-1332.
Sibly, R.; Nott, H. and Fletcher, D. (1990) Splitting behaviour into bouts. Animal Behaviour 39, 63-69.
mle
, optim
,
logit
, unLogit
for transforming and
fitting a reparameterized model.
data(divesSummary) postdives <- divesSummary$postdive.dur[divesSummary$trip.no == 2] postdives.diff <- abs(diff(postdives)) ## Remove isolated dives postdives.diff <- postdives.diff[postdives.diff < 2000] lnfreq <- boutfreqs(postdives.diff, bw=0.1, plot=FALSE) startval <- boutinit(lnfreq, 50) p <- startval$a1 / (startval$a1 + startval$a2) ## Fit the reparameterized (transformed parameters) model init.parms <- list(p=logit(p), lambda1=log(startval$lambda1), lambda2=log(startval$lambda2)) bout.fit1 <- bouts.mle(bouts2.LL, start=init.parms, x=postdives.diff, method="L-BFGS-B", lower=c(-2, -5, -10)) coefs <- as.vector(coef(bout.fit1)) ## Un-transform and fit the original parameterization init.parms <- list(p=unLogit(coefs[1]), lambda1=exp(coefs[2]), lambda2=exp(coefs[3])) bout.fit2 <- bouts.mle(bouts2.ll, x=postdives.diff, start=init.parms, method="L-BFGS-B", lower=rep(1e-08, 3), control=list(parscale=c(1, 0.1, 0.01))) plotBouts(bout.fit2, postdives.diff) ## Plot cumulative frequency distribution plotBouts2.cdf(bout.fit2, postdives.diff) ## Estimated BEC bec2(bout.fit2)