Skip to content

Instantly share code, notes, and snippets.

View benwhalley's full-sized avatar

Ben Whalley benwhalley

  • Plymouth University
View GitHub Profile
https://transfer.sh/adEXM/6-sem.pdf
https://transfer.sh/FObPj/6-sem-extra.pdf
https://www.dropbox.com/s/76vg2ortmid2x6t/Session5.pptx?dl=0
https://psy379-placebo.s3.amazonaws.com/index.html
https://www.dropbox.com/s/76vg2ortmid2x6t/Session5.pptx?dl=0

Keybase proof

I hereby claim:

  • I am benwhalley on github.
  • I am benwhalley (https://keybase.io/benwhalley) on keybase.
  • I have a public key ASC19V1R0DG97deKeZwym3XYq0JBGYGSL4qscFyPL_bqXgo

To claim this, I am signing this object:

library(tidyverse)
library(lmerTest)
library(broom)
mu_type1 <- 20
mu_type2 <- 70
sd_both <- 20
pwr <- function(N, mu_type1, mu_type2, sd_both){
library(tidyverse)
library(lmerTest)
library(broom)
mu_type1 <- 20
mu_type2 <- 70
sd_both <- 20
pwr <- function(N, mu_type1, mu_type2, sd_both){
library(tidyverse)
library(lmerTest)
library(broom)
pwr <- function(N){
simdata <- data_frame(person =1:N, c1=rnorm(N, 20, 25), c2 = rnorm(N, 77, 27)) %>%
reshape2::melt(id.var="person")
lmer(value~variable+(1|person), data=simdata) %>% summary tidy %>%
mutate(N=N)
}
@benwhalley
benwhalley / gist:8686bdf8c80550a089f135ee303d7c5f
Last active January 19, 2017 22:23
Using sims from predictInterval to plot intervals around continuous covariate
library(lmerTest)
library(merTools)
library(tidyverse)
# linear model
m <- lmer(Reaction~Days*I(Days^2)+(1|Subject), data=sleepstudy)
newdata = expand.grid(Reaction=NA, Days=1:5, Subject=Inf) %>% as.data.frame
sims <- predictInterval(m, newdata=newdata, returnSims = T)
p1 <-
ggplot(group.table, aes(month, fit, group=grp, color=grp, shape=grp)) +
geom_point() + geom_line() +
scale_color_discrete("") + scale_shape_discrete("") +
geom_text(show_guide = FALSE, aes(label=fit, y=fit), size=3) +
xlab(paste("Month")) +
ylab(paste("Model adjusted", toupper(dv))) +
theme(legend.position="top") +
theme(axis.text.x=element_blank(),axis.title.x=element_blank())
rf2.longs.with <- bind_sims(extract_sims(rf2.preds), newdata)
rf2predswide <- rf2.longs %>%
dcast(., month+sim+pd.b~grp, value.var="fitted", fun.aggregate=mean)
intervals <- rf2predswide %>%
mutate(diff=tau-dbt) %>%
group_by(month) %>%
do(., as.data.frame(t(quantile(.$diff, probs=c(.025, .5, .975)))))