Skip to content

Instantly share code, notes, and snippets.

View davebraze's full-sized avatar

Dave Braze davebraze

View GitHub Profile
@davebraze
davebraze / random-effects.R
Last active September 27, 2018 10:46
Basic random effect structures and non-convergence in lmer()
library(lme4)
library(nlme)
library(ggplot2)
data(Oxboys)
head(Oxboys, 12)
ggplot(aes(y=height, x=age), data=Oxboys) +
geom_point() + geom_path(aes(group=Subject))
@davebraze
davebraze / block-randomize.R
Last active February 2, 2018 19:59
Block randomize a stimulus list with dplyr
library(dplyr)
## Toy data
df <- data_frame(block=rep(1:3, each=4), item=rep(1:4,3),
cond=rep(LETTERS[1:2], 6),
stim=paste0(rep(letters[1:2],6), rep(1:6,each=2)))
## Randomize blocks and trials within blocks
df.rand <- df %>%
group_by(block) %>%