Skip to content

Instantly share code, notes, and snippets.

View mcfrank's full-sized avatar

Michael Frank mcfrank

View GitHub Profile
library(tidyverse)
library(lubridate)
d <- read_csv("psychjobwiki.csv")
ms <- d %>%
group_by(year, category) %>%
count() %>%
left_join(d %>% group_by(year) %>% count() %>% rename(total = n)) %>%
mutate(prop = n / total)
@mcfrank
mcfrank / power_sim_bayes.R
Created March 7, 2018 00:59
Frequentist and Bayesian power simulation stub code
library(tidyverse)
library(BayesFactor)
# simulation-based frequentist power analysis with known ES
ES <- .5
n_sims <- 100
ns <- c(2, 5, 10, 20, 50, 100)
sims <- as.tibble(expand.grid(sim = 1:n_sims,
n = ns)) %>%
@mcfrank
mcfrank / expt_sims.R
Created February 6, 2018 22:53
making up data for a series of experiments - generic stub code
conditions <- read_csv("condition_means.csv")
generate_data <- function(condition_df, n_subs = 40, n_trials = 3) {
tibble(speaker = condition_df$speaker,
prior = condition_df$prior,
info = condition_df$info,
experiment = condition_df$experiment,
correct = rbinom(1, n_subs * n_trials,
condition_df$mean_correct),
subid = rep(1:n_subs, n_trials))
@mcfrank
mcfrank / psych_sci_author_net.R
Created January 25, 2018 22:58
psych sci author network
library(tidyverse)
library(viridis)
library(knitr)
d <- read_csv("AuthorList.csv")
authors <- d %>%
group_by(author) %>%
count
@mcfrank
mcfrank / scraper.py
Created January 25, 2018 22:58
pubmed psych science scraped
from Bio import Entrez
Entrez.email = "[email protected]"
def get_links_term(term):
links = Entrez.esearch(db="pubmed", retmax = 5000, term=term)
record = Entrez.read(links)
link_list = record[u'IdList']
return link_list
@mcfrank
mcfrank / tw_autoencode.R
Created January 11, 2018 18:18
Sparse autoencoder version of Twomey & Westermann (2017), Dev Sci
# very quick re-implementation of a loose version of Experiment 1 from
# Twomey & Westermann 2017
# Mike Frank ([email protected])
library(autoencoder)
library(tidyverse)
# need this to evaluate pairwise distance in training sets
euclidean_pairwise <- function (x) {
@mcfrank
mcfrank / hyperbolic.R
Created November 7, 2017 01:29
hyperbolic discount using optim - example for Yochai Shavit Psych 251 project
library(tidyverse)
d <- read_csv("~/Desktop/med_table_shavit.csv") %>%
arrange(age_grp, kinship, donation, soc_dist)
# first plot
ggplot(d,
aes(x = soc_dist, y = med_amnt, col = age_grp)) +
geom_point() +
facet_grid(kinship ~ donation) +
geom_smooth(method="lm", formula = y ~ poly(x, 2),
@mcfrank
mcfrank / chi2_powersim.R
Created October 5, 2017 19:00
simulation-based power analysis for chi2
library(tidyverse)
library(purrr)
n1 = 12
n2 = 30
nsims = 10
get_chi2 <- function(x) {
p1 <- rbinom(1, size = n1, prob = x$p1)
p2 <- rbinom(1, size = n2, prob = x$p2)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mcfrank
mcfrank / util_et.R
Created November 8, 2016 23:40
Simple utility-theoretic planning for eye-movements
library(purr)
library(tidyverse)
library(stringr)
# constants
locations <- 1:3
timestep <- 1
t_end <- 6
t <- seq(0, t_end, timestep)