R-Lum / Luminescence

Development of the R package 'Luminescence'
http://r-lum.github.io/Luminescence/
GNU General Public License v3.0
15 stars 7 forks source link

analyse_baSAR() crashes after incomplete adaptation #407

Closed mcol closed 1 day ago

mcol commented 2 days ago

This reports a number of errors then crashes:

data(ExampleData.BINfileData, envir = environment())
CWOSL.sub <- subset(CWOSL.SAR.Data,
                    subset = POSITION %in% c(1:3) & LTYPE == "OSL")
analyse_baSAR(CWOSL.sub, verbose = TRUE,
              source_doserate = c(0.04, 0.001),
              signal.integral = c(1:2),
              background.integral = c(80:100),
              method_control = list(n.chains = 1),
              n.MCMC = 10)
# NOTE: Stopping adaptation
# 
# 
# Error in ar.yw.default(x, aic = aic, order.max = order.max, na.action = na.action,  :
#   'order.max' must be >= 1
# In addition: Warning messages:
# 1: [analyse_baSAR()] Only multiple grain data provided, automatic selection skipped
# 2: In rjags::jags.model(file = textConnection(baSAR_models[[distribution]]),  :
#   Adaptation incomplete
# Error in ar.yw.default(x, aic = aic, order.max = order.max, na.action = na.action,  :
#   'order.max' must be >= 1
# Error in ar.yw.default(x, aic = aic, order.max = order.max, na.action = na.action,  :
#   'order.max' must be >= 1
# Error in ar.yw.default(x, aic = aic, order.max = order.max, na.action = na.action,  :
#   'order.max' must be >= 1
# Error in aliquot_quantiles[2, x] : subscript out of bounds
mcol commented 2 days ago

This is due to the combination of n.MCMC (which we set to 10) and the thin argument (which is set automatically also to 10 for problems of this size). If I set n.MCMC = 10 or method_control = list(thin = 5), we don't crash on aliquot_quantiles (but the errors from JAGS are still there, that only goes away for n.MCMC >= 2 * thin).

The problem happens in these lines: https://github.com/R-Lum/Luminescence/blob/2d12e99bf37a09cc1847d2f836961ab6270eee2b/R/analyse_baSAR.R#L2052-L2054 With n.MCMC = 10 and thin = 10 we only get one posterior sample for each of D[1], D[2], D[3], and these get put into a single column in plot.matrix, rather than in 3 different columns. By creating a matrix of the desired dimensions, the crash disappears.

RLumSK commented 2 days ago

Please set a minimum number for n.MC; this should solve the issue.