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

Negative value in cp_thrs_PR2 computation #26

Open
EdoardoCostantini opened this issue Aug 11, 2023 · 3 comments
Open

Negative value in cp_thrs_PR2 computation #26

EdoardoCostantini opened this issue Aug 11, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@EdoardoCostantini
Copy link
Owner

EdoardoCostantini commented Aug 11, 2023

In cp_thrs_PR2(), it can happen that:

CNR2 <- 1 - exp(-2 / nrow(ivs) * (univ_mods$lls - univ_mods$ll0))

returns a negative value. This could happen if the likelihood of the more complex model is almost identical to the likelihood of the null model. In using this package, it could be that one of the possible predictors is so bad that this happens.

This was fixed in #ce6cc01 by taking the absolute value of the resulting CNR2 before taking the square root. This is not the most elegant solution. You could instead use some numerical trick. For example:

  1. Check if the difference univ_mods$lls - univ_mods$ll0 is smaller than floating point precision. If so, just set CNR2 to zero.
  2. After computing CNR2, check if it is less than 0. If so, set it to 0.
  3. Can also think of other transformations of the value to make things more stable (add values, multiple, take logs) and then reverse later.
@EdoardoCostantini EdoardoCostantini added the enhancement New feature or request label Aug 11, 2023
@EdoardoCostantini
Copy link
Owner Author

Added data for replicating the issue in #1b55040

@EdoardoCostantini
Copy link
Owner Author

Implemented solution 2:

  1. After computing CNR2, check if it is less than 0. If so, set it to 0.

in #289e3b3

Still needs testing.

@EdoardoCostantini
Copy link
Owner Author

EdoardoCostantini commented Aug 11, 2023

devtools::check() and testthat do not see the data for replication of error. Need to fix that before you can test the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant