Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calc_CentralDose() ... a few bugs #302

Closed
RLumSK opened this issue Oct 9, 2024 · 3 comments · Fixed by #304
Closed

calc_CentralDose() ... a few bugs #302

RLumSK opened this issue Oct 9, 2024 · 3 comments · Fixed by #304
Labels
bug Clear problem or crash
Milestone

Comments

@RLumSK
Copy link
Member

RLumSK commented Oct 9, 2024

Describe the bug

This dataset

     De ERR_DE
1 -0.56  -0.15
2 -0.16  -0.10
3  0.00   0.12
4  0.04     NA

with

calc_CentralDose(
  data = df, 
  log = FALSE)

returns

Error in sig/delta : non-numeric argument to binary operator

for

calc_CentralDose(
  data = df, 
  log = TRUE)

It returns a warning without context:

In log(data$ED) : NaNs produced

In all cases the error should be caught earlier and with meaningful messages.

@mcol mcol added this to the Release version 1.0.0 milestone Oct 9, 2024
@mcol mcol added the bug Clear problem or crash label Oct 9, 2024
@mcol
Copy link
Contributor

mcol commented Oct 9, 2024

By default this function uses na.rm = FALSE, and by setting it to true, the error goes away, although we get warnings for the removed NAs (I think these should be just messages, as the user has explicitly asked for it and it's the sensible thing to do).

Perhaps we should warn if na.rm = FALSE but the data contains missing values?

I'll continue chasing the error, but I'm one stop away from home. 🚀

@mcol
Copy link
Contributor

mcol commented Oct 9, 2024

If na.rm = FALSE, the NA in the data frame very quickly extends to all other expressions (for example, after operations such as sum(wu * yu)). After sig <- try(seq(sig0, sig1, sig1 / 1000), silent = TRUE), sig is of class try-error, but the function carries on anyway, until it reaches

if(!log)  sig <- sig / delta

which is where the "Error in sig/delta : non-numeric argument to binary operator" gets printed.

I think it doesn't make sense to run this function with na.rm = FALSE: we should at least change the default to TRUE, but probably we should always remove the missing values like we do somewhere else. Given that the function needs to sums over all data, I can't see a case where leaving NAs in the dataset is a good idea.

@RLumSK
Copy link
Member Author

RLumSK commented Oct 9, 2024

Then I suggest that the function removes NA values automatically with a warning, this is probably the best way. The other point is that, by definition, the uncertainty cannot be < 0. So I suggest running abs() silently over the dataset.

  • Deprecate the na.rm argument and remove NA values by default
  • Always run abs() silently over the function
  • If values are negative, switch the function automatically to log = FALSE with a warning

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Clear problem or crash
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants