brianstock / MixSIAR

A framework for Bayesian mixing models in R:
http://brianstock.github.io/MixSIAR/
94 stars 75 forks source link

Error in jags.model #291

Open masaba79 opened 3 years ago

masaba79 commented 3 years ago

Hello! I used MixSIAR successfully since ~2018 (thanks a lot by the way for this modeling framework!!). I´ve used the gui and modified the example scripts to use my data without problems in the past. But now, after a year or so without touching the script I want to run it with another set of data, I get an error when I try to run the test (and any jags model). I get through everything ok (loading the mixture, source and discrimination files, making the isospace and priors plot, calculating the convex hull area all ok). I think the model is written ok too (attached) MixSIAR_modelDate1Loc1.txt.

This is my code (like I said I basically modified the example script): model_filename <- "MixSIAR_modelDate1Loc1.txt" resid_err <- TRUE process_err <- FALSE write_JAGS_model(model_filename, resid_err, process_err, mix, source) jags<- run_model(run="test", mix, source, discr, model_filename, alpha.prior=1, resid_err, process_err)

But I get this error:

Compiling model graph Resolving undeclared variables Allocating nodes Graph information: Observed stochastic nodes: 9 Unobserved stochastic nodes: 47 Total graph size: 652 Initializing model Deleting model

Error in jags.model(model.file, data = data, inits = init.values, n.chains = n.chains, : Error in node src_tau[3,1] Invalid parent values

Also, not sure if related, mixsiar_gui() doesnt work:

Error in mixsiar_gui() : could not find function "mixsiar_gui"

any idea what is wrong? and how can I fix this?

More info: I had to uninstall and install again R, Rstudio and MixSIAR because I had a previous problem with ggplot2 not being able to work (aka got stuck in ploting the isospace, but got resoved by fresh install of everything). To install MixSIAR now I followed instructions just like the first time and just noticed that now I have two versions of JAGS in my computer: JAGS-4.2.0 and JAGS-4.3.0...how do I know which one uses MixSIAR, or does it matter? Shall I delete one of these? which one? The freshly installed one is the oldest 4.2.0 (not sure how this happended).

Any help appreciated! thnks

Susana.

masaba79 commented 3 years ago

update: I ran it with previous datasets (which have worked before) and now the Jags model ran smoothly! So it might be something about the dataset... cant figure what it is.

DSchimmenti commented 12 months ago

I think I might be having a similar issue and I am also looking for a solution. I am working on Mac OSX with R version 4.3.1 in RStudio (I have checked and I get this error regardless of whether I run my code in RStudio or the R console). I have run MixSIAR many times with my own data using 2 isotopes/tracers, 11 sources, and 35 mixture data points with no errors when I run the JAGS model. I am also using age as a fixed effect and running the model with residual error only no process error. Now that I am attempting 3 isotopes/tracers with the same amount of sources, mixture data points, fixed effects, and error settings, I get the following error message when I attempt to run the JAGS model:

Compiling model graph Resolving undeclared variables Allocating nodes Deleting model

Error in jags.model(model.file, data = data, inits = init.values, n.chains = n.chains, : RUNTIME ERROR: Unable to resolve the following parameters: Factor.1[67] (line 40) cross[67,1,1:10] (line 50) cross[67,2,1:10] (line 50) cross[67,3,1:10] (line 50) cross[67,4,1:10] (line 50) cross[67,5,1:10] (line 50) cross[67,6,1:10] (line 50) cross[67,7,1:10] (line 50) cross[67,8,1:10] (line 50) cross[67,9,1:10] (line 50) cross[67,10,1:10] (line 50) cross[67,11,1:10] (line 50) mix.mu[1:3,67] (line 92, 93) p.ind[67,1:11] (line 83) tmp.p[67,1:11] (line 53) Either supply values for these nodes with the data or define them on the left hand side of a relation.

I attempted to run the Isopod example to see if for some reason it was an issue related to using more than 2 isotopes/tracers, but I was able to run that vignette with no errors. I also double checked my mixture, source, and discrimination factor data files and everything looked okay and consistent.

My code for my data is as follows:

library(MixSIAR) setwd("/Users/Danielle/Documents/R Data/PhD_Ch3/Manuscript Data Files") mix206208eNd <- load_mix_data(filename = "Mixture_206208eNd_MixSIAR_withAges.csv", iso_names = c("Pb206204", "Pb208204", "eNd"), factors = c("Age..kyr.BP."), fac_random = FALSE, fac_nested = NULL, cont_effects = NULL) source206208eNd <- load_source_data(filename = "Sources_206208eNd_AllPSAs_MixSIAR.csv", source_factors = NULL, conc_dep = FALSE, data_type = "means", mix206208eNd) discr206208eNd <- load_discr_data(filename = "Discrimination_206208eNd_AllPSAs.csv", mix206208eNd) model_filename206208eNd <- "MixSIAR_model_206208eNd_AllPSAs.txt" resid_err <- TRUE process_err <- FALSE write_JAGS_model(model_filename206208eNd, resid_err, process_err, mix206208eNd, source206208eNd) jags.1_206208eNd_test <- run_model(run="test", mix206208eNd, source206208eNd, discr206208eNd, model_filename206208eNd, alpha.prior = 1)