Skip to content

Instantly share code, notes, and snippets.

View nutterb's full-sized avatar

Benjamin nutterb

  • Battelle Memorial Institute
  • Kentucky
View GitHub Profile
pi_birthdays <- function(birthdate, n = 1:30, format = "%Y-%m-%d"){
if (!is.Date(birthdate) | !is.POSIXct(birthdate)){
birthdate <- as.Date(birthdate, format = format)
}
data.frame(n_pi = n,
pi_date = birthdate + 365.2425 * n * pi)
}
library(dplyr)
library(tidyr)
choose_partner <- function(People){
Males <- filter(People, gender == "M")
Females <- filter(People, gender == "F")
if (nrow(Males) <= nrow(Females)){
Males$partner_id <- sample(Females$id, nrow(Males))
People <- full_join(Males, Females,
@nutterb
nutterb / ggSurvGraph_Examples.R
Created March 10, 2015 13:19
Examples using ggSurvGraph
#* You'll have to source in the function code from the gist
#* https://gist.github.com/nutterb/004ade595ec6932a0c29
library(ggplot2)
install.packages("KMsurv")
data(kidney, package="KMsurv")
fit <- survfit(Surv(time, delta) ~ type, data=kidney)
ggSurvGraph(fit)
ggSurvGraph(fit, conf.bar=FALSE)
@nutterb
nutterb / ggSurvGraph.R
Last active August 29, 2015 14:16
Customizable Survival Curves in ggplot2
#* More examples at https://gist.github.com/nutterb/fb19644cc18c4e64d12a
#' @name ggSurvGraph
#' @export ggSurvGraph
#' @import ggplot2
#' @importFrom grid unit
#' @importFrom gridExtra grid.arrange
#' @importFrom plyr arrange
#' @importFrom plyr ddply
#' @importFrom reshape2 melt
#' @importFrom zoo na.locf