crp2a / BayLum

Chronological Bayesian models integrated for Optically Stimulated Luminescence (OSL) Dating
https://crp2a.github.io/BayLum
GNU General Public License v3.0
9 stars 1 forks source link

Age_OSLC14() ... crashes with Compilation error on line 8. #13

Closed RLumSK closed 3 years ago

RLumSK commented 4 years ago

Expected behaviour

The function runs without any error according to the manual description.

Observed behaviour

Error in rjags::jags.model(file = con, data = dataList, n.chains = n.chains,  : 
  RUNTIME ERROR:
Compilation error on line 8.
Attempt to redefine node Sigma[1,1] 

Running mini example

This example is a copy & paste from the manual, except for the distribution, which is set to gaussian.

library(BayLum)
## Load data
# OSL data
data(DATA1,envir = environment())
data(DATA2,envir = environment())
Data <- combine_DataFiles(DATA2,DATA1)

# 14C data
C14Cal <- DATA_C14$C14[1,1]
SigmaC14Cal <- DATA_C14$C14[1,2]
Names <- DATA_C14$Names[1]

# Prior Age
prior=rep(c(1,60),3)
samplenature=matrix(data=c(1,0,1,0,1,0),ncol=3,nrow=2,byrow=TRUE)
SC <- matrix(data=c(1,1,1,0,1,1,0,0,1,0,0,0),ncol=3,nrow=4,byrow=TRUE)

## Age computation of samples
Age <-
  Age_OSLC14(
    DATA = Data,
    Data_C14Cal = C14Cal,
    Data_SigmaC14Cal = SigmaC14Cal,
    SampleNames = c("GDB5", Names, "GDB3"),
    Nb_sample = 3,
    SampleNature = samplenature,
    PriorAge = prior,
    StratiConstraints = SC,
    distribution = "gaussian",
    LIN_fit = TRUE,
    Origin_fit = FALSE,
    Iter = 50,
    n.chains = 2
  )

Error analysis

It appears to be an error in the underlying model (the BUGS code) for a particular setting. Below are listed the relevant code line 8 in the BUGs model (ModelOSL).

##LIN_FIT = TRUE & Origin_fit = FALSE >> FAILED
Sigma[CS_OSL[i1],CS_OSL[i1]]=A[i1]*A[i2]*Gamma[CS_OSL[i1],CS_OSL[i1]]

##LIN_FIT = FALSE & Origin_fit = FALSE >> OK
Sigma[CS_OSL[i1],CS_OSL[i2]]=A[i1]*A[i2]*Gamma[CS_OSL[i1],CS_OSL[i2]]

##LIN_FIT = TRUE & Origin_fit = TRUE >> OK
Sigma[CS_OSL[i1],CS_OSL[i2]]=A[i1]*A[i2]*Gamma[CS_OSL[i1],CS_OSL[i2]]

##LIN_FIT = FALSE & Origin_fit = TRUE >> OK
Sigma[CS_OSL[i1],CS_OSL[i2]]=A[i1]*A[i2]*Gamma[CS_OSL[i1],CS_OSL[i2]]

##uses the default configuration
Sigma[CS_OSL[i1],CS_OSL[i2]]=A[i1]*A[i2]*Gamma[CS_OSL[i1],CS_OSL[i2]]

Solution?

AgesMultiOSL_EXPLIN fails and I guess the model should read:

Sigma[CS_OSL[i1],CS_OSL[i2]]=A[i1]*A[i2]*Gamma[CS_OSL[i1],CS_OSL[i1]]
RLumSK commented 4 years ago

@philippe-a Do you agree with the suggested fix? If yes I could update the package.

guiguerin commented 3 years ago

Disagree - the corresponding line should read like all others:

Sigma[CS_OSL[i1],CS_OSL[i2]]=A[i1]A[i2]Gamma[CS_OSL[i1],CS_OSL[i2]]

RLumSK commented 3 years ago

That is what I meant, but did not write. I will fix that.

Correction: Sorry, I meant it correctly. There are two index values. But in this case, the model has even two bugs. I will fix it as advised.