Skip to content

Instantly share code, notes, and snippets.

Jake Westfall jake-westfall

Block or report user

Report or block jake-westfall

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jake-westfall
jake-westfall / conditioning.R
Created Dec 3, 2018
Illustration of the concept of conditioning on a random variable
View conditioning.R
library("scatterplot3d")
library("MASS")
path <- "/Users/jakewestfall/Desktop/"
# simulate data from gaussian copula
covmat <- matrix(.9, nrow=3, ncol=3)
diag(covmat) <- 1
dat <- pnorm(mvrnorm(n=3000, mu=c(0,0,0), Sigma=covmat))
# pairs(dat)
@jake-westfall
jake-westfall / RWiener.R
Created Jun 15, 2017
Simple illustration of getting maximum likelihood estimates of Wiener diffusion model (and profile likelihood confidence intervals) in R using RWiener and bbmle packages
View RWiener.R
library("RWiener")
library("bbmle")
# alpha = boundary separation parameter.
# tau = non-decision time parameter.
# beta = bias parameter.
# delta = drift rate parameter
dat <- rwiener(200, alpha=2, tau=.3, beta=.5, delta=1)
str(dat)
wiener_plot(dat)
View number_of_folds.R
# function to fold data into k folds. this returns a list of matrices where
# the 1st column in each is the response and all other columns are predictors
fold <- function(y, X, k){
n <- length(y)
lapply(0:(k-1)*n/k + 1, function(i){
cbind(y, X)[seq(from=i, length.out=n/k),]
})
}
# function to compute MSE for datasets with different numbers of folds
@jake-westfall
jake-westfall / nested_contour.R
Created Jul 1, 2016
Produce statistical power contour plot for simple nested design w/ participants (pl) nested in labs (l)
View nested_contour.R
# replace this with a path on your own machine
path <- "/Users/Jake/Desktop/nested_power.png"
# define function to compute statistical power
pow <- function(d, E, LC, l, pl){
t <- d/2/sqrt(E/(2^pl)/(2^l) + LC/(2^l))
DF <- (2^l) - 1
return(pt(qt(.975, DF), DF, ncp=t, lower.tail=F) +
pt(qt(.025, DF), DF, ncp=t))
}
View esPuzzlerData.R
dat <- read.table("http://pcl.missouri.edu/exp/effectSizePuzzler.txt", header=TRUE)
str(dat)
# 'data.frame': 2500 obs. of 3 variables:
# $ id : int 1 1 1 1 1 1 1 1 1 1 ...
# $ cond: int 1 1 1 1 1 1 1 1 1 1 ...
# $ rt : num 0.56 0.93 0.795 0.615 1.028 ...
(means <- with(dat, tapply(rt, cond, mean)))
# 1 2
@jake-westfall
jake-westfall / random_scale_item_sim.R
Created Nov 5, 2015
Estimate/test correlation between subjects' scores on two tests composed of random items
View random_scale_item_sim.R
library(MASS) # for mvrnorm()
library(lme4) # for lmer()
# function to simulate data, fit models, do model comparison
sim <- function(n, # number of subjects
m, # number of items per test
mu, # mean for both tests
SD, # subject SD in test means
r, # correlation between subject test means
diff, # SD of item difficulties (intercepts)
You can’t perform that action at this time.