Skip to content

updated random forest metric, model and simulate_wrappers for survival#90

Merged
rid4stat merged 1 commit intomainfrom
pmsims-ml
Feb 24, 2026
Merged

updated random forest metric, model and simulate_wrappers for survival#90
rid4stat merged 1 commit intomainfrom
pmsims-ml

Conversation

@rid4stat
Copy link
Collaborator

No description provided.

@@ -149,16 +149,34 @@ predict_custom <- function(x, y = NULL, fit, model, type = "response") {
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[air] reported by reviewdog 🐶

Suggested change

# Survival: ranger returns a matrix of survival probabilities by timepoint
if (is.matrix(preds) && inherits(fit, "ranger") && fit$treetype == "Surv") {
# If user asks for survival probabilities, return the matrix
if (is.matrix(pr$survival) && inherits(fit, "ranger") && fit$treetype == "Survival") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[air] reported by reviewdog 🐶

Suggested change
if (is.matrix(pr$survival) && inherits(fit, "ranger") && fit$treetype == "Survival") {
if (
is.matrix(pr$survival) &&
inherits(fit, "ranger") &&
fit$treetype == "Survival"
) {

# If user asks for survival probabilities, return the survival matrix
if (type == "survival") {
return(preds)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[air] reported by reviewdog 🐶

Suggested change


times <- pr$unique.death.times
surv_matrix <- pr$survival

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[air] reported by reviewdog 🐶

Suggested change

if (type == "lp") {
lp <- -rowMeans(preds, na.rm = TRUE)
return(as.numeric(lp))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[air] reported by reviewdog 🐶

Suggested change

)

},
xgboost = function(d, nrounds = 100, params = list(objective = "binary:logistic", eval_metric = "logloss")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[air] reported by reviewdog 🐶

Suggested change
xgboost = function(d, nrounds = 100, params = list(objective = "binary:logistic", eval_metric = "logloss")) {
xgboost = function(
d,
nrounds = 100,
params = list(objective = "binary:logistic", eval_metric = "logloss")
) {

@@ -141,7 +157,7 @@ default_models <- list(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[air] reported by reviewdog 🐶

Suggested change

stopifnot(all(c("time", "event") %in% colnames(d)))
formula <- stats::as.formula("survival::Surv(time, event) ~ .")
ranger::ranger(formula, data = d, num.threads = nthreads)
ranger::ranger(formula, data = d, num.trees = 300, num.threads = nthreads)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[air] reported by reviewdog 🐶

Suggested change
ranger::ranger(formula, data = d, num.trees = 300, num.threads = nthreads)
ranger::ranger(formula, data = d, num.trees = 300, num.threads = nthreads)

ranger::ranger(formula, data = d, num.threads = nthreads)
ranger::ranger(formula, data = d, num.trees = 300, num.threads = nthreads)
},
xgboost = function(d, nrounds = 100, params = list(objective = "survival:cox", eval_metric = "cox-nloglik")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[air] reported by reviewdog 🐶

Suggested change
xgboost = function(d, nrounds = 100, params = list(objective = "survival:cox", eval_metric = "cox-nloglik")) {
xgboost = function(
d,
nrounds = 100,
params = list(objective = "survival:cox", eval_metric = "cox-nloglik")
) {

@@ -364,7 +364,7 @@ simulate_survival <- function(
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[air] reported by reviewdog 🐶

Suggested change

@rid4stat rid4stat merged commit 39af818 into main Feb 24, 2026
1 of 8 checks passed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[air] reported by reviewdog 🐶

stop("rf (ranger) prediction type not supported or unknown prediction structure.")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant