knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

NoBodySorrow package

NoBodySorrow (nbs) is an R package with a range of functions to improve programming workflow in R.

Installation

detach(package:nbs, unload=TRUE)
library(utils)
remove.packages("nbs")
devtools::install_github("mikeniemant/nbs")

Load package

library(nbs)
library(tidymodels)
theme_set(theme_bw() + theme(plot.title = element_text(hjust = 0.5)))

Dummy datasets

single model tibble

data(single_model_tibble)
single_model_tibble

multi model tibble

data(multi_model_tibble)
multi_model_tibble

Functions

computeBaseNetBenefit

base_nbt <- computeBaseNetBenefit(single_model_tibble$y)

computeNetBenefit

nbt <- computeNetBenefit(pt = base_nbt$pt, 
                         y = single_model_tibble$y, 
                         pred = single_model_tibble$pred)

nbt <- base_nbt %>% 
  left_join(nbt,
            by = "pt")

ggplot(nbt %>% 
         pivot_longer(cols = -pt, names_to = "model", values_to = "nbt") %>% 
         filter(nbt >= -0.1),
       aes(x = pt, y = nbt, colour = model, linetype = model)) + 
  geom_line() +
  labs(x = "Threshold probability (%)",
       y = "Net benefit",
       colour = "Model",
       linetype = "Model")

computeCalibration

computeCalibration(labs = single_model_tibble$y, preds = single_model_tibble$pred, event_level = "1")

plotCalibration

dat <- multi_model_tibble %>% 
  nest(dat = c(y, pred)) %>% 
  mutate(cal = map(dat, ~ computeCalibration(labs = .x$y,
                                             preds = .x$pred,
                                             event_level = "1",
                                             plot = F)))

# Plot calibration curve for all models
plotCalibration(dat %>% 
                  unnest(cal), 
                group = "model")

plotPrc

dat <- multi_model_tibble %>% 
  nest(dat = c(y, pred)) %>% 
  mutate(pr = map(dat, ~ .x %>% pr_curve(pred, truth = y, event_level = "second"))) %>% 
  unnest(pr)
plotPrc(dat, group = "model")

plotRoc

dat <- multi_model_tibble %>% 
  nest(dat = c(y, pred)) %>% 
  mutate(roc = map(dat, ~ .x %>% roc_curve(pred, truth = y, event_level = "second"))) %>% 
  unnest(roc)
plotRoc(dat, group = "model")

cws

Clear work space - Remove all objects in environment - (Close any SQL connections) - (Close all clusters)

findTodo

Find all #TODO statements in all .R and .Rmd files in a directory.

replacePattern

Finds and replaces a particular pattern in all .R and .Rmd files in a directory.

objSize

Compute memory size of objects in the R environment.

Notes

Open a new issue here for any bug reports or feature requests.

Copyright (C) Michael Niemantsverdriet, the Netherlands, 2022, all rights reserved. Use for personal and educational purposes.



mikeniemant/nbs documentation built on June 23, 2022, 4:52 a.m.