{{ message }}

Instantly share code, notes, and snippets.

# Michael Frankmcfrank

Last active Mar 3, 2020
get possessive datas from wordbank and plot
View possessives.R
 library(wordbankr) library(tidyverse) possess_data <- get_instrument_data(language = "English (American)", form = "WS", items = "item_687") # note that 687 is the s-possess item admin_data <- get_administration_data(language = "English (American)", form = "WS") left_join(possess_data, admin_data) %>%
Created Mar 2, 2020
MB4 GLM simulation
View mb4_sim.R
 library(tidyverse) n_sim <- 100 sims <- expand_grid(n_total = seq(50,500,25), i = 1:n_sim) %>% mutate(idx = 1:n()) %>% split(.\$idx) %>% map_df(function (df) { cntl_sim <- tibble(choice = c(rbinom(n = df\$n_total/2, size = 1, p = .68), rbinom(n = df\$n_total/2, size = 1, p = .5)), condition = c(rep("social", df\$n_total/2),
Last active Oct 15, 2019
Simulate covariate effect on linear model - modified from Jan Vanhove
View sim_covariates.R
 library(MASS) library(tidyverse) # from https://homeweb.unifr.ch/VanhoveJ/Pub/simulation_covariates.html # Define function # n <- 20 # observations per group # diff <- 0 # difference between groups # sd_y <- 3 # within-group sd of outcome (population-level) # rho_covars <- c(0.7, 0.3, 0) # correlation of control variables with outcome # in control group; add more coefficients to
Created Oct 10, 2019
Sample categorical regression with table turning
View table_turning.R
 library(tidyverse) library(brms) library(langcog) d <- tibble(subject = c(1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4), response = c("E",NA,"A","error", "E","E","E","error", "A","A","E","error", "A","A","A","A"),
Created Oct 8, 2019
View covariate_sim.R
 # based on http://egap.org/methods-guides/10-things-know-about-covariate-adjustment library(MASS) # for mvrnorm() library(tidyverse) set.seed(1234567) num.reps = 1000 # True treatment effect is 0 for every unit adj.est = function(n, cov.matrix, treated) {
Created Jul 1, 2019
View regression_example.R
 iqs <- data_frame(iq = rnorm(mean = 100, sd = 15, n= 40), school = c(rep("Stanford",20), rep("Berkeley",20)), year = factor(rep(c(1950,1990),20))) summary(lm(iq ~ school * year, data = iqs)) summary(lm(scale(iq) ~ school * year, data = iqs))
Created May 3, 2019
Bayesian vs. frequentist LMMs for ManyBabies
View bayesian_mb1.R
 library(brms) library(lme4) library(here) library(tidyverse) d <- read_csv(here("processed_data/03_data_trial_main.csv")) %>% mutate(method = case_when( method == "singlescreen" ~ "Central fixation", method == "eyetracking" ~ "Eye tracking", method == "hpp" ~ "HPP",
Created Jan 24, 2019
Simulation for manybabies 2 pilot
View manybabies2_sim.R
 library(tidyverse) library(ggthemes) n_trials <- c(2,4,8) p_anticipation <- seq(0,1,.1) n_subs <- c(12,24,36,48) n_sims <- 1000 d <- expand.grid(n_trials = n_trials, p_anticipation = p_anticipation,
Created Jul 10, 2018
plot of negation in context (model results)
View negation_context.R
 library(tidyverse) # Nonexistence context, Nonexistence referent, apples? QUD nna <- tibble(ratio = c("ratio0", "ratio1", "ratio2", "ratio3"), probs = c(0.3323976330361966, 0.39954163105573637, 0.37453297805618113, 0.3323976330361966), context = "nonexistence context", referent = "nonexistence referent", qud = "apples?") naa <- tibble(ratio = c("ratio0", "ratio1", "ratio2", "ratio3"),
Created Jun 30, 2018
transition between states in some code
View time_transition.R
 library(tidyverse) foo <- data_frame(time = c(1:5, 1:5), code = c(1,2,3,2,1,0,0,1,2,1), subid = c(rep(1,5), rep(2, 5))) foo %>% group_by(subid) %>% mutate(d_code = c(0,diff(code)), one_two_transition = code == 2 & d_code == 1, two_three_transition = code == 3 & d_code == 1) %>%
You can’t perform that action at this time.