R-Lum/Luminescence

calc_FiniteMixture() ... object 'max.dose' not found

RLumSK opened this issue · 1 comments

Expected behaviour

The function works or stops with an understandable error

Observed behaviour

Error in lapply(X = X, FUN = FUN, ...) : object 'max.dose' not found

Running mini example

rm(list = ls())
library(Luminescence)
library(readxl)

##load data
datalu <- as.data.frame(read_excel("RWY-1_MAM.xlsx", sheet = 1, skip = 1))

##run analysis
FMM <- calc_FiniteMixture(
  datalu,
  sigmab = 0.30,
  n.components = c(2:3),
  pdf.weight = TRUE,
  dose.scale = c(0, 20)
)

## show results
FMM

Dataset will be sent by email.

tzerk commented

This particular error occurred due to the finite mixture model producing NaNs for the standard errors of the fitted components (more specifically: due to taking the square root of a negative number). With NaN values the density functions in plot_RLum.Results() cannot be computed, hence the error. The root cause for this behaviour is due to i) inappropriate data the model was never designed to be applied to[1], and ii) inappropriatly chosen model parameters[2], which is why the model is bound to fail.

Given the above, there is no need to change the model or the plotting capabilities. In the commited changes, however, the function now checks the model results for NaNs, replaces them with NA and warns the user about it. In case of NA values, plotting is now prevented.

[1] Comparatively narrow distribution of DE values with no visually identifiable, distinct components; but with a very distinct "outlier" almost three times as large as the mean of all other DE values.
[2] Including the alleged outlier the data set has an overdispersion of ~23 %. Removing the value reduces the OD to ~16 %. In the failing example a sigmab value of 30 % is used, which is much larger than the observed spread of the whole data set!