This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' riscitation - Create .ris file from R citation | |
#' | |
#' Suggests: | |
#' Package `berryFunctions` if `opendelete = TRUE`. | |
#' | |
#' Arguments | |
#' `pkg:character(1)` - Name of package to cite | |
#' `path:character(1)` - Path to write file too, should include file name but not extension | |
#' `opendelete:logical(1)` - If `TRUE` (default), opens the .ris file in the default application then deletes | |
#' the file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## select holdout as the resampling strategy | |
resampling <- rsmp("cv", folds = 3) | |
## add KM and CPH | |
learners <- c(learners, lrns(c("surv.kaplan", "surv.coxph"))) | |
design <- benchmark_grid(tasks, learners, resampling) | |
bm <- benchmark(design) | |
## Aggreggate with Harrell's C and Integrated Graf Score | |
msrs <- msrs(c("surv.cindex", "surv.graf")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Documentation | |
on: | |
push: | |
branches: | |
- main | |
- master | |
tags: '*' | |
pull_request: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
options(repos=c( | |
mlrorg = 'https://mlr-org.r-universe.dev', | |
raphaels1 = 'https://raphaels1.r-universe.dev', | |
CRAN = 'https://cloud.r-project.org' | |
)) | |
install.packages(c("ggplot2", "mlr3benchmark", "mlr3pipelines", "mlr3proba", "mlr3tuning", | |
"survivalmodels", "mlr3extralearners")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Get SHAPs from a trained xgboost model | |
#' @param model trained xgboost model | |
#' @param data new data for calculating shaps | |
get_shaps <- function(model, data) { | |
p = predict(model, data, | |
predcontrib = T, approxcontrib = F) | |
p = p[, -ncol(p)] | |
shaps = reshape2::melt(p) | |
vars = reshape2::melt(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
raincloudplot <- function(data, y, fill, x = fill, cols = NULL, | |
boxplots = c("below", "in", "none")) { | |
require(dplyr) | |
require(ggplot2) | |
source("https://raw.githubusercontent.com/datavizpyr/data/master/half_flat_violinplot.R") | |
boxplots <- match.arg(boxplots) | |
p <- ggplot(data, aes_string(y = y, x = x, fill = fill)) + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`%=%` <- function(l, r) { | |
l <- trimws(strsplit(l, ",", TRUE)[[1]]) | |
if (all(l == "USE.NAMES") || all(l == "*") || all(l == "?")) { | |
stopifnot(length(names(r)) > 0) | |
l <- names(r) | |
} else { | |
stopifnot(identical(length(l), length(r))) | |
which <- l == "?" | |
if (any(which)) { | |
stopifnot(length(names(r)) > 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(mlr3benchmark) | |
## create mlr3benchmark object | |
bma <- as.BenchmarkAggr(bm) | |
## run global Friedman test | |
bma$friedman_test() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## learners are stored in mlr3extralearners | |
library(mlr3extralearners) | |
## load learners | |
learners <- lrns( | |
paste0("surv.", c("coxtime", "deephit", "deepsurv", "loghaz", "pchazard")), | |
frac = 0.3, early_stopping = TRUE, epochs = 10, optimizer = "adam" | |
) | |
# apply our function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(paradox) | |
search_space <- ps( | |
## p_dbl for numeric valued parameters | |
dropout = p_dbl(lower = 0, upper = 1), | |
weight_decay = p_dbl(lower = 0, upper = 0.5), | |
learning_rate = p_dbl(lower = 0, upper = 1), | |
## p_int for integer valued parameters | |
nodes = p_int(lower = 1, upper = 32), |
NewerOlder