This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |