Skip to content

Instantly share code, notes, and snippets.

View berndweiss's full-sized avatar

Bernd Weiss berndweiss

View GitHub Profile
@berndweiss
berndweiss / .bash_aliases
Created October 23, 2021 03:01 — forked from vratiu/.bash_aliases
Git shell coloring
# Customize BASH PS1 prompt to show current GIT repository and branch.
# by Mike Stewart - http://MediaDoneRight.com
# SETUP CONSTANTS
# Bunch-o-predefined colors. Makes reading code easier than escape sequences.
# I don't remember where I found this. o_O
# Reset
Color_Off="\[\033[0m\]" # Text Reset
@berndweiss
berndweiss / Directed Acyclic Graphs in LaTeX using TikZ
Created May 14, 2016 05:15 — forked from lcomm/Directed Acyclic Graphs in LaTeX using TikZ
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}[%
@berndweiss
berndweiss / lmm
Last active August 29, 2015 14:14 — forked from ThierryO/lmm
library(ggplot2)
library(lme4)
library(mvtnorm)
fixed.intercept <- 1
n.subject <- 10
n.replicate <- 10
mean.subject <- c(1, 2, 3, 3, 2, 1)
sd.subject <- 0.1 * diag(length(mean.subject))
sd.noise <- 0.5
RMDFILE=demo-rmd-pandoc
PANDOC=~/.cabal/bin/pandoc
all:
Rscript -e "require(knitr); require(markdown); knit('$(RMDFILE).rmd', '$(RMDFILE).md'); purl('$(RMDFILE).rmd')"
${PANDOC} --mathjax --toc -B header.html -A footer.html --bibliography refs.bib --css markdown.css -s $(RMDFILE).md -o $(RMDFILE).html
@berndweiss
berndweiss / Hmisc_bezier.R
Created December 10, 2012 11:34 — forked from dsparks/Hmisc_bezier.R
Economics-style graphs
doInstall <- TRUE
toInstall <- c("Hmisc", "ggplot2", "proxy", "grid")
if(doInstall){install.packages(toInstall, repos = "http://cran.us.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
# Example usage
x <- c(4,6,4,5,6,7)
y <- 1:6
plot(x, y, "o", pch=20) # bezier() generates smoothed curves from these points
points(bezier(x, y), type="l", col="red")
@berndweiss
berndweiss / gist:4023903
Created November 6, 2012 10:25
Multiple merge via Reduce()
a <- data.frame(id = c(1,2,3,7,9), y1 = rnorm(5))
b <- data.frame(id = 1:3, y2 = rnorm(3))
c <- data.frame(id = 1:4, y3 = rnorm(4))
a
b
c
Reduce(function(x,y){merge(x, y, by.x = "id", by.y = "id", all = TRUE)},
list(a, b, c), accumulate = FALSE)
@berndweiss
berndweiss / aREADME.rst
Created October 7, 2012 07:33 — forked from leetrout/aREADME.rst
Clone all your github repos into a local directory

USAGE

python ghclone.py

Follow the prompts

Notes

@berndweiss
berndweiss / by_n.R
Created September 29, 2012 03:42
R code snippet that mimics Stata's "by & _n" behavior
##
## See "Counting with by" for a Stata example
## http://www.ats.ucla.edu/stat/stata/notes/countn.htm
## Hadley's version (which I like most) using ave() and seq_along()
mydf <- data.frame(id = c(1,1,1,2,2,2,2,3,3,3), v1 = 1)
mydf
mydf$v2 <- ave(mydf$v1, mydf$id, FUN = seq_along)
mydf
@berndweiss
berndweiss / gist:1391938
Created November 24, 2011 18:04
Episode splitting with qualitative covariates
## Note: No missing values in tvc.start_/tvc.stop_ allowed!
## 0. Step: Make up some data
## event: event status
## start: starting time
## stop: ending time
## tvc.start_: starting time of qualitative/categorial TVC
## tvc.stop_: ending time of qualitative/categorial TVC
df <- data.frame(id=c(1, 2),
@berndweiss
berndweiss / gist:1068292
Created July 6, 2011 20:50
MLM in R and Stata
In R
dfr <- read.table(file="c:/tmp/dataset.csv", sep=",", header=TRUE)
head(dfr)
length(table(dfr$ipnum))
lmer(ene ~ videocond + ifrelevant + videorelevant + choicenum +(1|ipnum), data=dfr)
> lmer(ene ~ videocond + ifrelevant + videorelevant + choicenum +(1|ipnum), data=dfr)
Linear mixed model fit by REML
Formula: ene ~ videocond + ifrelevant + videorelevant + choicenum + (1 | ipnum)