Skip to content

Instantly share code, notes, and snippets.

View mcfrank's full-sized avatar

Michael Frank mcfrank

View GitHub Profile
## analysis code for Fiona Lee's class project
## Psych 241, Stanford Winter 2013
library(ggplot2)
library(reshape2)
library(psych)
library(bootstrap)
library(lme4)
## for bootstrapping 95% confidence intervals
theta <- function(x,xdata,na.rm=T) {mean(xdata[x],na.rm=na.rm)}
@mcfrank
mcfrank / gist:21062dc6852fc580ba94
Created December 13, 2014 05:57
Mixture distribution power
# mixture distribution power sims
rm(list=ls())
# from http://stats.stackexchange.com/questions/27088/shapiro-francia-test-error
sf.testBIG=function (x)
{
DNAME <- deparse(substitute(x))
x <- sort(x[complete.cases(x)])
n <- length(x)
@mcfrank
mcfrank / pubmed.py
Created October 7, 2015 22:08
Example of using the Entrez API to get pubmed citations
## this little script shows off the use of the pubmed API through bioconductor
## requires installing Biopython (using pip)
## also requires installing the DTD files for each of the Entrez API calls,
## but the instructions for this are given when you run the script
## useful list of Entrez databases that can be queried through API
# pmc_pubmed PubMed citations for these articles
# pmc_refs_pubmed PubMed article citing PMC article
# pmc_pmc_cites PMC articles that given PMC article cites
# pmc_pmc_citedby PMC article citing given PMC article
---
title: "RMarkdown for writing scientific papers: A minimal working example"
author: "Mike Frank"
date: "`r Sys.Date()`"
output:
html_document:
toc: true
number_sections: true
bibliography: mwe.bib
---
@mcfrank
mcfrank / blake.Rmd
Last active February 16, 2016 00:04
---
title: 'Class 6a: Blake et al. (2015) exercise'
author: "Mike Frank"
date: "February 9, 2016"
output:
html_document:
toc: true
---
# Intro
@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)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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)
@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 / 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 (mcfrank@stanford.edu)
library(autoencoder)
library(tidyverse)
# need this to evaluate pairwise distance in training sets
euclidean_pairwise <- function (x) {