Skip to content

Make .check_censor_model() error for non-censored-regression models #972

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

Merged
merged 1 commit into from
Jun 8, 2023

Conversation

hfrick
Copy link
Member

@hfrick hfrick commented May 18, 2023

closes #971

Regression and classification models also have $censor_probs even though it's just an empty list, so this check function didn't error before.

Test is to be updated in extratests.

With this PR:

library(parsnip)
library(survival)

lung2 <- lung %>%
  dplyr::mutate(surv = Surv(time, status), .keep = "unused")

not_a_censor_model <- fit(linear_reg(), mpg ~ ., data = mtcars)

# this now errors
parsnip:::.check_censor_model(not_a_censor_model)
#> Error in `parsnip:::.check_censor_model()`:
#> ! The model needs to be for mode 'censored regression', not for mode
#>   'regression'.

# so also this errors now with the better message
.censoring_weights_graf(not_a_censor_model, lung2)
#> Error in `.check_censor_model()` at parsnip/R/survival-censoring-weights.R:226:2:
#> ! The model needs to be for mode 'censored regression', not for mode
#>   'regression'.

Created on 2023-05-18 with reprex v2.0.2

because regression and classification models also have `$censor_probs` even though its just an empty list
@hfrick
Copy link
Member Author

hfrick commented May 18, 2023

An alternative is to make changes in fit() and fit_xy() to only fit the additional model for censoring probabilities if the main model has mode censored regression. On the one hand, the model_fit objects then only carry what they need. On the other hand, the model_fit objects look somewhat different on what the mode is, was there hesitation around type-stability there? Do you have a preference for either of the two options?

@hfrick hfrick requested a review from topepo May 18, 2023 16:33
@topepo topepo merged commit 3bf1da9 into main Jun 8, 2023
@topepo topepo deleted the check_censor_model branch June 8, 2023 13:10
@github-actions
Copy link

This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

check_censor_model() should error for models without mode "censored regression"
2 participants