This vignette help you deal with troubling messages from the run_model function.

As a prerequisite, the preprocess_data, write_model and run_model functions must have been run without errors before trying to solve the convergence problems:

library(EcoDiet)

example_stomach_data_path <- system.file("extdata", "example_stomach_data.csv",
                                    package = "EcoDiet")
example_biotracer_data_path <- system.file("extdata", "example_biotracer_data.csv",
                                    package = "EcoDiet")

data <- preprocess_data(biotracer_data = read.csv(example_biotracer_data_path),
                        trophic_discrimination_factor = c(0.8, 3.4),
                        literature_configuration = FALSE,
                        stomach_data = read.csv(example_stomach_data_path))

model_string <- write_model(literature_configuration = FALSE)

mcmc_output <- run_model(textConnection(model_string), data)

Increase the number of iterations and/or adaptation steps

The first thing that you should try is setting a higher number of iterations and/or adaptation steps to run the model. Depending on your data (e.g., food-web complexity, data informativeness), this can take hours or days to run:

mcmc_output <- run_model(textConnection(model_string), data, nb_adapt = 1e4, nb_iter = 1e7)

If you have already tried this and that increasing again these numbers may take several days or weeks, try the following.

Understand which variable is problematic

The full Gelman-Rubin diagnostic for each variable is saved everytime the run_model function is used, and you can acess it using:

load("convergence_diagnostic.Rdata")
View(gelman)

It will allow you to identify which variables have not converged properly (the closer to 1, the better it has converged) and understand the potential origins of the convergence failure.

If the PI and eta variables has both trouble converging for a specific trophic link between a predator and a prey, you can look at the corresponding data to see if there is not an error somewhere (maybe a biotracer measurement was entered as 104 instead of 1.04 for this prey or predator).

Specify initial values for the model

The next step might be to define starting values from which to run the MCMC chains. By default JAGS will use the prior distributions to randomly fix the starting values of the chains, which can cause problems.

A large inconsistency between the literature priors and the data can eventually create convergence problems. Thus, first check and eventually modify the prior distributions used through the literature_diets table, the nb_literature and the literature_slope parameters (if you used priors from the literature).

Or you can try to manually set a good set of fixed values for initializing MCMC chains, i.e., fixed values that you know are close to the values you want the model to converge to. This way the model is given a good start and it should be faster to converge.

Conclusions

If you still have an 'adaptation incomplete' warning or 'Stopping adaptation' note, you can just live with the sub-optimal sampler efficiency and run the model for a higher number of iterations.

If you still have a 'convergence problem' message, you cannot use the obtained results as they are clearly incorrect.



heloisethero/EcoDiet documentation built on Feb. 12, 2020, 6:08 p.m.