👁️🗨️
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
# fast R update | |
rupdate <- function(){ | |
utils::update.packages( | |
ask = FALSE, | |
Ncpus = 6, | |
repos = "https://cloud.r-project.org" | |
) | |
} |
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
#' @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") |
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
#' @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'. |
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
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.") | |
} |
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
--- | |
title: "Sample Equations used in Statistics" | |
output: html_document | |
--- | |
### Summations | |
### Without Indices | |
$\sum x_{i}$ |
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
# Flatten a list returned by the rle() function | |
library(purrr) | |
# ARRAY ------------------------------------------------------------------- | |
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
st_set_varlabs <- function(data, | |
dict = ITEMDESC, | |
view = modul, | |
keeps = PAGE_TABLE, | |
name = ITEM_COLUMN, | |
label = ITEM_LABEL) { | |
library(dplyr, warn.conflicts = FALSE) |
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
df.VARLABS <- tibble::tribble( | |
~VARNAME, ~LABEL, | |
"PATIENT_ID", "Patient ID", | |
"ARM", "Randomisation arm", | |
"RANDO_DAT", "Randomisation date" | |
) | |