pveber / morse

Companion R package for MOSAIC website
7 stars 5 forks source link

Bug when plotting LCx object. #263

Closed pveber closed 3 years ago

pveber commented 6 years ago

The following code shows an error:

library(morse)
data(cadmium1)
fit = survFit(survData(cadmium1), model_type = 'SD')
plot(LCx(fit, X=50))

I get the following complaint:

Error in LCx.survFit(fit) : 
  l'argument "X" est manquant, avec aucune valeur par défaut

Seems related to cadmium1 example.

virgile-baudrot commented 6 years ago

Ok. Actually, it's not an "error", it's just that for some couple ('X', 'time_LCx') there is no value. But I agree, the error message is not clear at all. I'm going to work on it.

When there is no 'LCx' for a specific couple ('X', 'time_LCx'), the plot function should return:

  1. A plot without the horizontal line at (1-X/100)% (as it is not possible to compute)
  2. A message: "No LCx at the 'X' and 'time_LCx'. You can try the option 'time_LCx' (default is the maximum time of the experimental data) and/or other 'X'."
virgile-baudrot commented 6 years ago

The upper commit solve the issue. Try with different data set:

library(morse)
data(cadmium1)
data(cadmium2)
data(zinc)
data(copper)

fit_Cd1_SD = survFit(survData(cadmium1), model_type = 'SD')
fit_Cd1_IT = survFit(survData(cadmium1), model_type = 'IT')
fit_Cd2_SD = survFit(survData(cadmium2), model_type = 'SD')
fit_Cd2_IT = survFit(survData(cadmium2), model_type = 'IT')
fit_Cu_SD = survFit(survData(copper), model_type = 'SD')
fit_Cu_IT = survFit(survData(copper), model_type = 'IT')

plot(LCx(fit_Cd1_SD, X=50)) # Warning message
plot(LCx(fit_Cd1_SD, X=30)) # OK
plot(LCx(fit_Cd1_SD, X=40)) # OK

plot(LCx(fit_Cd1_IT, X=50)) # Warning message
plot(LCx(fit_Cd1_IT, X=30)) # OK
plot(LCx(fit_Cd1_IT, X=40)) # OK

plot(LCx(fit_Cd2_SD, X=50))
plot(LCx(fit_Cd2_SD, X=999)) # Warning message
plot(LCx(fit_Cd2_IT, X=50))
plot(LCx(fit_Cd2_IT, X=999)) # Warning message

plot(LCx(fit_Cu_SD, X=99))
plot(LCx(fit_Cu_IT, X=99)) # Warning message