Skip to content

Instantly share code, notes, and snippets.

@lcomm
lcomm / ExtractIDvar.R
Created March 31, 2016 02:22
Quick example of how you could extract ID variable from LME formula
#Function to extract the cluster ID variable from a formula
get_id <- function(formula){
#Extract the thing between the | and the ) in the last part of formula
#This is the clustering variable
idvar <- gsub('.*[|](.*?)).*','\\1',formula[-c(1:2)])
#Remove white space
idvar <- gsub("^\\s+|\\s+$", "", idvar)
@lcomm
lcomm / MethodsInR.R
Last active March 31, 2016 02:23
Example of how to use methods in R to have the print() function print out something special based on function output
#########################
# Print methods in R #
#########################
#Create my silly function
myfunc <- function(mu){
x <- rnorm(1, mean=mu, sd=3)
class(x) <- "myfunc"
return(x)
}
@lcomm
lcomm / Directed Acyclic Graphs in LaTeX using TikZ
Created October 6, 2014 14:55
TikZ-based LaTeX code to create 3 basic DAGs in epidemiology/biostatistics.
\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
%Graph 1
\begin{figure}
\caption{Graph 1}
\large{\begin{tikzpicture}[%