Skip to contents

Occasionally when fitting an `mrds` model one can run into optimisation issues. In general such problems can be quite complex so these "quick fixes" may not work. If you come up against problems that are not fixed by these tips, or you feel the results are dubious please go ahead and contact the package authors.

Debug mode

One can obtain debug output at each stage of the optimisation using the showit option. This is set via control, so adding control=list(showit=3) gives the highest level of debug output (setting showit to 1 or 2 gives less output).

Re-scaling covariates

Sometimes convergence issues in covariate (MCDS) models are caused by values of the covariate being very large, so a rescaling of that covariate is then necessary. Simply scaling by the standard deviation of the covariate can help (e.g. dat$size.scaled <- dat$scale/sd(dat$scale) for a covariate size, then including size.scaled in the model instead of size).

It is important to note that one needs to use the original covariate (size) when computing Horvitz-Thompson estimates of population size if the group size is used in that estimate. i.e. use the unscaled size in the numerator of the H-T estimator.

Factor levels

By default R will set the base factor level to be the label which comes first alphabetically. Sometimes this can be an issue when that factor level corresponds to a subset of the data with very few observations. This can lead to very large uncertainty estimates (CVs) for model parameters. One way around this is to use relevel to set the base level to a level with more observations.

Initial values

Initial (or starting) values for the dsmodel can be set via the initial element of the control list. initial is a list itself with elements scale, shape and adjustment, corresponding to the associated parameters. If a model has covariates then the scale or shape elements will be vectors with parameter initial values in the same order as they are specific in the model formula (using showit is a good check they are in the correct order). Adjustment starting values are in order of the order of that term (cosine order 2 is before cosine order 3 terms).

One way of obtaining starting values is to fit a simpler model first (say with fewer covariates or adjustments) and then use the starting values from this simpler model for the corresponding parameters.

Another alternative to obtain starting values is to fit the model (or some submodel) using Distance for Windows. Note that Distance reports the scale parameter (or intercept in a covariate model) on the exponential scale, so one must log this before supplying it to ddf.

Bounds

One can change the upper and lower bounds for the dsmodel parameters. These specify the largest and smallest values individual parameters can be. By placing these constraints on the parameters, it is possible to "temper" the optimisation problem, making fitting possible.

Again, one uses the control list, the elements upperbounds and lowerbounds. In this case, each of upperbounds and lowerbounds are vectors, which one can think of as each of the vectors shape, scale and adjustment from the "Initial values" section above, concatenated in that order. If one does not occur (e.g. no shape parameter) then it is simple omitted from the vector.

Conventional distance sampling optimizer choice

The key function plus adjustment approach of Conventional Distance Sampling (CDS) can sometimes run into issues because it is sensible to constrain the fitted detection function to be monotonic non-increasing (i.e., flat or going down) with increasing distance - finding the maximum of the constrained likelihood is more difficult than the same task without constraints.

There are several options within the `ddf` control argument that may help if difficulties are encountered. These are documented in the ddf manual page, and a few are mentioned below.

One potential strategy (as mentioned above) is to use better starting values for the optimization. If mono.startvals is set to TRUE then the detection function is first fit without adjustments and the resulting scale (and shape) estimates used as starting values in the model with adjustments. For even finer control, the initial option can be used as documented above.

Another potential thing to change is the constraint solver used. From `mrds` v 3.0.0 a new constraint solver, `slsqp`, has been included as the default. This was found to work better than the solver previously used (`solnp`) but if needed this solver can be specified using the mono.method option of the control argument of `ddf`.

It is also possible to use the optimizer implemented in Distance for Windows by downloading a separate binary - see the manual page on mcds_dot_exe. If specified, this will also be used for Multiple Covariate Distance Sampling (MCDS) analyses.

Author

David L. Miller <dave@ninepointeightone.net>