Skip to content

Instantly share code, notes, and snippets.

@sumprain
sumprain / code_drug_comparison
Created January 11, 2018 01:46
Code for the blog post: Interpretation of effectiveness between two interventions: A new perspective
# load library
library(tidyverse)
# Function to create probability distribution of survival data (PFS)
prob_dist <- function(surv, lcl, ucl, ci = 0.95, arm) {
lci <- log(-log(lcl))
uci <- log(-log(ucl))
lsurv <- log(-log(surv))
@sumprain
sumprain / server.R
Created January 2, 2018 17:36
Code for Shinyapp for PIRO Model: Predicting AKI in ACLF
library(shiny)
shinyServer(function(input, output, session) {
observe({
input$calc
isolate({
creat_cat <- input$creat_cat
urea <- as.numeric(input$urea)
bil_cat <- input$bil
@sumprain
sumprain / choices.R
Last active November 29, 2015 06:30
choices: a new function to be used within dplyr's mutate and transmute function
#' Make a new column in dataframe with one of the specified values based on given criteria
#'
#' @description This function is to be run from within \code{mutate, transmute} functions in \code{dplyr} and it makes a new column within the dataframe based on formula based expressions with LHS representing the value to be put in case expression on RHS is satisfied. Rows with no matching expressions will be filled up by the character given by argument \code{escape}. The names appearing in expression will be populated with the values from variables within the parent dataframe, and if not available, will be populated with the values from the calling environment (usually the global environment).
#'
#' @param ... expressions in form of two sided formula of the form \code{"name_of_choice" ~ expression}. The expressions will be evaluated from left to right and the values in the rows will be modified accordingly.
#' @param escape character showing the value to be filled if none of the expressions satisfy (defaults to N