Skip to content

Instantly share code, notes, and snippets.

View nrkoehler's full-sized avatar
👁️‍🗨️
Focusing

Norbert Köhler nrkoehler

👁️‍🗨️
Focusing
View GitHub Profile
# fast R update
rupdate <- function(){
utils::update.packages(
ask = FALSE,
Ncpus = 6,
repos = "https://cloud.r-project.org"
)
}
#' @title {Plot Accrual of patients by month}
#' @description {This function creates a plot of the accrual of patients by month.}
#' @param data A data frame containing the dates column.
#' @param dates The name of the dates column in \code{data}.
#' @return A ggplot object.
#' @export
#' @examples
#' # Create a data frame
#' df <- data.frame(
#' dates = seq(as.Date("2020-01-01"), as.Date("2020-07-01"), by = "month")
#' @title {Accrual of Patients in a Clinical Trial}
#' @description {This function plots the expected, randomised and registered number of patients
#' in a clinical trial.}
#' @param start Character. Start date of the trial. Default is "2020-01-01".
#' @param end Character. End date of the trial. Default is "2022-12-31".
#' @param n_target Numeric. Expected number of patients in the trial.
#' @param finished Is patient recruitment finished?
#' @param dates_rando Numeric. Vector of dates of randomised patients.
#' @param dates_regi Numeric. Vector of dates of registered patients.
#' @param x_axis_text Position of X-axis text: 'asis' (default)), 'shifted'.
report_samplesize_t.test <- function(pwr, drop_out){
n_raw <- ceiling(pwr$n)
n_total <- (n_raw + ceiling(n_raw * drop_out))*2
glue::glue("A two-sample t-test to detect a difference of {round(pwr$delta, 1)} l/min between the groups with an SD of {round(pwr$sd, 1)} l/min has power of {pwr$power*100}% if {ceiling(pwr$n)} patients per arm are randomized. Allowing for a drop-out of {drop_out*100}% implies that {n_total} patients need to be randomized in total.")
}
@nrkoehler
nrkoehler / stats_equations.Rmd
Created November 17, 2022 13:45 — forked from derekmcloughlin/stats_equations.Rmd
Useful Latex Equations used in R Markdown for Statistics
---
title: "Sample Equations used in Statistics"
output: html_document
---
### Summations
### Without Indices
$\sum x_{i}$
# Flatten a list returned by the rle() function
library(purrr)
# ARRAY -------------------------------------------------------------------
st_set_varlabs <- function(data,
dict = ITEMDESC,
view = modul,
keeps = PAGE_TABLE,
name = ITEM_COLUMN,
label = ITEM_LABEL) {
library(dplyr, warn.conflicts = FALSE)
df.VARLABS <- tibble::tribble(
~VARNAME, ~LABEL,
"PATIENT_ID", "Patient ID",
"ARM", "Randomisation arm",
"RANDO_DAT", "Randomisation date"
)