Skip to content

Instantly share code, notes, and snippets.


Carl Frederick carlbfrederick

View GitHub Profile
View calc-rolling-week.R
#' Calculates rolling weeks backward from the end_date.
#' The purpose is to group a vector of dates into 7 day weeks
#' backward in time. For example, if the end date was 2020-06-09,
#' the days 2020-06-03 through 2020-06-09 would be one week,
#' 2020-05-27 through 2020-06-02 would be another week, 2020-05-20
#' through 2020-05-26 another and so on. The function will work even
#' if the vector of dates is missing one or more dates in the series.
#' @param date_vector the vector of dates to group into weeks. Must be
View sampleLatoReport.Rmd
title: "Sample Lato .Rmd"
author: "Carl Frederick"
date: "11/12/2018"
mainfont: Lato
latex_engine: xelatex
carlbfrederick / DescribeDataSharing.R
Created Jul 20, 2018
Using babynames package to illustrate complex data sharing
View DescribeDataSharing.R
snames <- sample(babynames$name, 14)
unames <- snames[11:14]
snames <- snames[1:10]
Agency1 <- data_frame(Person = c(sample(snames, 5), unames[1]),
carlbfrederick / dataMaid_cleanPlot.R
Created Jul 10, 2018
4th attempt at clean plots for data documentation
View dataMaid_cleanPlot.R
#'These functions makes the default graphics prettier/easier to read:
#' 1. Minimal Theme
#' 2. Angled Axis Text
#' @example
cleanPlotHelper <- function(data, vnam, sideways) {
carlbfrederick / dataMaid_isIDvar.R
Last active Jan 11, 2019
dataMaid check function: deal with "key" variables that do not uniquely identify rows
View dataMaid_isIDvar.R
#'This function identifies "Key" and similar variables and stops dataMaid::makeDataReport from creating
#'visualizations and/or other inappropriate summaries. Instead it outputs a table with minimal information
#'(see for inspiration).
#' @example
#' makeDataReport(toyData, output = "html",
#' preChecks = c("isKey", "isSingular", "isSupported", "isIDvar"))
carlbfrederick / packageFunctionMap.R
Last active Sep 8, 2020
Visualize internal package functions
View packageFunctionMap.R
#Get package functions ----
ls_fcns <- function(pkg) {
fcns <- unclass(lsf.str(envir = asNamespace(pkg), all = TRUE))
carlbfrederick / survProbs.coxme.R
Last active Sep 2, 2015
I wrote these functions to calculate survival probabilities at various levels of the random effect estimate from a coxme.object. The code is heavily adapted from survfit.coxph(). It should work, but all errors and inelegant hacks I have introduced are certainly my own doing. Comments/improvements welcome, enjoy!
View survProbs.coxme.R
#Internal Functions
MYagsurv <- function(y, x, wt, risk, survtype=3, vartype=3) {
nvar <- ncol(as.matrix(x))
status <- y[, ncol(y)]
dtime <- y[, ncol(y) - 1]
death <- (status == 1)
time <- sort(unique(dtime))
nevent <- as.vector(rowsum(wt * death, dtime))
ncens <- as.vector(rowsum(wt * (!death), dtime))
wrisk <- c(wt * risk) #Had to add c() to remove the dimnames so that the multiplication later would work