Skip to content

Instantly share code, notes, and snippets.

View JimGrange's full-sized avatar

Jim Grange JimGrange

View GitHub Profile
@JimGrange
JimGrange / functions.R
Created August 28, 2015 07:38
Response Time Reliability Simulations
#------------------------------------------------------------------------------
# generate data from a multivariate normal distribution with known
# correlations between values
mvrnorm <- function(n, nValues, meanValues, sdValues, corMatrix) {
Z <- matrix(rnorm(n * nValues), nValues, n)
t(meanValues + sdValues * t(chol(corMatrix)) %*% Z)
}
#------------------------------------------------------------------------------
@JimGrange
JimGrange / priorRobustnessCheck.R
Last active November 27, 2015 15:16
Code for animating robustness check of Bayesian prior.
### plots of prior robustness check
# gif created from PNG plots using http://gifmaker.me/
# clear R's memory
rm(list = ls())
# load the Bayes factor package
library(BayesFactor)
@JimGrange
JimGrange / snowman.R
Created December 1, 2015 05:36
Code for snowman plot
library(ggplot2)
library(emoGG)
ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) +
geom_emoji(emoji = "2744") + add_emoji(emoji = "26c4")
#------------------------------------------------------------------------------
### set up
# clear workspace
rm(list = ls())
# set working directory
setwd("D:/Work/Blog_YouTube code/Blog/Olympic Medals")
# load relevant packages
setwd("C:/Users/psa33/Dropbox/Work/Blog/gifs/increasingN")
binWidth <- 0.005
# define parameter space
x <- seq(from = binWidth / 2, to = 1 - binWidth / 2, by = binWidth)
# what rate of fairness is the coin?
rate <- 0.5
@JimGrange
JimGrange / effect_sizes.R
Last active November 25, 2021 15:48
Low power = inaccurate effect size estimates
#------------------------------------------------------------------------------
rm(list = ls())
set.seed(50)
# function for generating random draws from multivariate distribution
# n = number of draws; p = number of variables
# u = mean of each variable; s = SD of each variable
# corMat = correlation matrix
mvrnorm <- function(n, p, u, s, corMat) {
#------------------------------------------------------------------------------
### initial set up
rm(list = ls())
# set working directory
setwd("D:/Work/Other/Blog_YouTube code/Blog/Bayesian Partial Correlation")
# load libraries
library(ppcor)
library(Hmisc)
library(metafor)
library(dplyr)
# sample size per study
n <- 10
# population effect size
true_d <- 0.2
# generate studies
library(rtdists)
set.seed(42)
# declare correct & error drift rate
correct_drift <- 2.4
error_drift <- 1 - correct_drift
# generate RTs with the diffusion model
rt1 <- rLBA(500, A = 0.5, b = 1, t0 = 0.5,
@JimGrange
JimGrange / parallel_examples.R
Created July 20, 2019 07:50
Examples of different parallelisations in R
# https://nceas.github.io/oss-lessons/parallel-computing-in-r/parallel-computing-in-r.html
library(parallel)
library(foreach)
library(doParallel)
library(snow)
set.seed(42)
n_subs <- 100000
n_trials <- 5000