Skip to content

Instantly share code, notes, and snippets.

View Lakens's full-sized avatar

Daniel Lakens Lakens

View GitHub Profile
@Lakens
Lakens / standardized_alpha_power_analysis.R
Created December 1, 2018 21:08
Calculating standardized p-values and alpha levels (Good, 1982)
#Standardized p-value
#This is untested alpha software provided with no guarantees - use at your own risk
#Good 1982: P SQRT(N/100)
#Enter the observed p-value and the sample size
p_stan <- function(p, N){
p * sqrt(N/100)
}
@Lakens
Lakens / emailing_students_from_R.R
Created September 2, 2018 13:36
Emailing students from R using mailR package
#Load packages
library(readxl)
library(mailR)
#Read student data
info <- read_excel("student_names_email.xls",
sheet = 1,
col_names = TRUE)
#Loop from 1 to the number of email addresses in the spreadsheet
@Lakens
Lakens / p-value_misconceptions_figures.R
Created December 5, 2017 11:51
figures to explain p-value misconceptions
options(scipen=999) #disable scientific notation for numbers
#Figure 1 & 2 (set to N <- 5000 for Figure 2)
# Set x-axis upper and lower scalepoint (to do: automate)
low_x<--1
high_x<-1
y_max<-2
#Set sample size per group and effect size d (assumes equal sample sizes per group)
N<-50 #sample size per group for indepndent t-test
@Lakens
Lakens / blog_hits.csv
Last active April 14, 2017 08:44
blog hits
NAME COMMENTS HITS DATE
Equivalence testing in jamovi 12 1870 14-3-2017
No the p-values are not to blame: Part 53 1 2675 10-3-2017
How p-values solve 50% of the problems with p-values 4 2273 6-3-2017
ROPE and Equivalence Testing: Practically Equivalent? 9 1991 12-2-2017
Examining Non-Significant Results with Bayes Factors and Equivalence Tests 26 2332 29-1-2017
Why Type 1 errors are more important than Type 2 errors (if you care about evidence) 32 7435 18-12-2016
TOST equivalence testing R package (TOSTER) and spreadsheet 8 3885 9-12-2016
Why Within-Subject Designs Require Fewer Participants than Between-Subject Designs 0 4792 12-11-2016
Improving Your Statistical Inferences Coursera course 7 3154 6-10-2016
@Lakens
Lakens / TOSTvsROPE.R
Last active February 12, 2017 08:51
Comparing ROPE and TOST
#Make sure JAGS is installed or R will crash: https://sourceforge.net/projects/mcmc-jags/files/JAGS/4.x/
require(BEST) #To calculate HDI
require(TOSTER) #To calculate Equivalence Tests
set.seed(1)
x<-rnorm(100) #Generate 100 random normally distributed observations
y<-rnorm(100) #Generate 100 random normally distributed observations
#ROPE test
@Lakens
Lakens / volunteer_reanalysis.R
Created January 29, 2017 09:39
Re-analysis if volunteer data
# Code from https://osf.io/aqi5j/ made by original authors, adapted by Daniel Lakens
# Download the csv file from https://osf.io/aqi5j/
# Paper: http://www.tandfonline.com/doi/full/10.1080/23743603.2016.1273647
require(car)
# IMPORTANT: change this to match your path/file
fileLocation <- 'C:\\Users\\Daniel\\surfdrive\\Data\\blog volunteer study\\VolunteeringDataFile_05.09.16.csv'
# Dienes functions
@Lakens
Lakens / 3dplotLR.R
Last active January 9, 2017 15:07
likelihood of true positive and false positive as a function of power and alpha
#Create single plot for graph----
power <- seq(0.01,1,0.01)
alpha <- seq(0.01,1,0.01)
pH0 <- 0.5
tp<-((1-pH0)*power)
fp<-((pH0)*alpha)
likelihood_ratio<-outer(tp, fp, "/")
#Create color shading
nrz<-nrow (likelihood_ratio)
@Lakens
Lakens / WithinBetween.R
Last active April 1, 2017 13:23
Why Within-Subject Designs Require Less Participants than Between-Subject Designs
if(!require(ggplot2)){install.packages('ggplot2')}
library(ggplot2)
if(!require(Rcpp)){install.packages('Rcpp')}
library(Rcpp)
if(!require(MASS)){install.packages('MASS')}
library(MASS)
options(digits=10,scipen=999)
#Set color palette
@Lakens
Lakens / DanceBayesFactors.R
Last active September 23, 2016 09:05
Dance of the Bayes factors
if(!require(BayesFactor)){install.packages('BayesFactor')}
library(BayesFactor)
#to get emoticons for each test, set wait to 0.5 and showfaces to 1.
#When running large number of simulations, set wait to 0 and showfaces to 0.
options(scipen=20) #disable scientific notation for numbers
waitx<-0.5 #To see a small wait between individual trials, set a wait time to e.g., 0.5
showfaces<-1 #Set to 0 if you do not want the faces, set to 1 if you want to see the faces
cohensd<-0.3 #set true effect size
n<-75 #sample size in each group
@Lakens
Lakens / test.R
Created June 19, 2016 19:41
test.R
if(!require(ggplot2)){install.packages('ggplot2')}
library(ggplot2)
if(!require(pwr)){install.packages('pwr')}
library(pwr)
nSims <- 100000 #number of simulated experiments
M<-106 #Mean IQ score in the sample
n<-26 #set sample size
SD<-15 #SD of the simulated data