Skip to content

Instantly share code, notes, and snippets.

View mcfrank's full-sized avatar

Michael Frank mcfrank

View GitHub Profile
@mcfrank
mcfrank / scopus_bib.R
Created May 11, 2022 19:32
example use of Scopus API for a citation network
library(rscopus)
library(tidyverse)
library(igraph)
library(GGally)
faculty <- read_csv("faculty.csv")
faculty$au_id <- NA
for (i in 1:nrow(faculty)) {
print(i)
library(tidyverse)
library(BFpack)
# function to simulate bayes factors in Kat's experiments
# takes:
# - n subjects in each condition
# - p1 for first condition success probability
# - p2 for second condition success probability
sim_bfs <- function(n, p1, p2) {
library(tidyverse)
# let's define hunter and ames functions as a family of quadratic functions
# where y = beta_1 * x + beta_2 * x^2
# and beta_1 < 0 and beta_2 > 0
t <- seq(0, 10, .1)
sim <- expand_grid(b1 = seq(-1, 0, .2),
b2 = seq(0, .1, .02),
@mcfrank
mcfrank / BFpack.R
Created February 16, 2022 17:44
using BFpack
library(tidyverse)
library(BFpack)
n <- 12
kat_data <- tibble(condition = c(rep("reliable", n),
rep("unreliable", n)),
harder = c(rbernoulli(n, p = .8),
rbernoulli(n, p = .3)))
kat_data %>% group_by(condition) %>% summarise(mean_harder = mean(harder))
library(tidyverse)
probs <- c(.6, .8)
df <- expand_grid(subid = 1:10,
condition = 1:2,
trial_num = 1:12) %>%
group_by(condition) %>%
mutate(correct = rbinom(n = n(), size = 1, prob = probs[condition][1]))
@mcfrank
mcfrank / sullivan_2020_jepg.R
Last active February 10, 2021 20:27
item-by-item plot for Sullivan et al. (2020), JEPG
library(tidyverse)
d <- read_csv("Replication_Race_For_R_012519.csv")
correct <- tribble(~name, ~correct_value, ~longname,
"SocialMotherLanguage", 0, "prefer individuals who speak their mother’s primary language",
"SocialGenderGroup", 24, "start identifying as members of a particular gender group",
"SocialFaceNonface", 0, "can tell the difference between faces and things",
"SocialFat", 36, "begin associating being fat with negative traits",
"RaceRace-Status", 47, "associating particular racial groups with status",
"RaceLowStatusNegative", 36, "associate low-status racial groups with negative traits",
@mcfrank
mcfrank / hierarchical_reg.R
Created January 15, 2021 21:52
hierarchical regression with only two datapoints (and two coefficients) at the subject level
tibble(y = c(1,2,3,4),
x = c("E","C","E","C"),
subid = c(1,1,2,2)) %>%
group_by(subid) %>%
do(broom::tidy(lm(y ~ x, data = .))) %>%
group_by(term) %>%
do(broom::tidy(lm(estimate ~ 1, data = .)))
library(tidyverse)
library(BayesFactor)
trials_per_kid <- 12
sim_data <- function (n) {
d <- expand.grid(subid = 1:n,
condition = c("pred","unpred","consistent")) %>%
rowwise %>%
mutate(correct = mean(rbinom(n = trials_per_kid,
@mcfrank
mcfrank / possessives.R
Last active March 3, 2020 05:12
get possessive datas from wordbank and plot
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) %>%
@mcfrank
mcfrank / mb4_sim.R
Created March 2, 2020 04:51
MB4 GLM simulation
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),