Skip to content

Instantly share code, notes, and snippets.

#Binomial distribution of 30 attempts with a probability of .5, simulated 100,000 times
g <- rbinom(100000, 30, .5)
graph1 <- hist(g,xlab = expression(paste(italic(n),'=30, ', italic(P),'=.5')),main = "Simulated data for 30 trials with a probabiltiy of .5", col = "skyblue2")
#Binomial distribution of 30 attempts with a probability of .15, simulated 100,000 times
h <- rbinom(100000, 30, .15)
graph2 <- hist(h,xlab = expression(paste(italic(n),'=30, ', italic(P),'=.15')),main = "Simulated data for 30 trials with a probabiltiy of .15", col = "skyblue2")
#Binomial distribution of 30 attempts with a probability of .001, simulated 100,000 times
j <- rbinom(100000, 30, .01)
@PsychBrief
PsychBrief / gist:f90d1899c44b1e50a88ccd68b4405686
Created December 14, 2017 13:03
Power estimates for differing SDs
parameter_grid <- expand.grid(n = c(32, 64),
d = seq(0.05, 2, by = 0.05),
sd = seq(1, 2, by = 0.2))
parameter_grid$power <- power.t.test(n = parameter_grid$n, delta = parameter_grid$d, sd = parameter_grid$sd)$power
library(tidyverse)
parameter_grid$n <- paste(parameter_grid$n, "pro group")
ggplot(parameter_grid,
aes(x = d,
@PsychBrief
PsychBrief / Demographics of the feed
Created September 27, 2017 13:27
How the authors in my feed are divided along the lines of gender, race, and whether they are an ECR or not
Gender
#Create a string called "BlogName" with all the names of the different blogs in it
BlogName<-c("Brown", "Coyne", "Allen", "Neurobonkers", "Sakaluk", "Heino", "Kruschke", "Giner-Sorolla", "Magnusson", "Zwaan", "CogTales", "Campbell", "Vanderkerckhove", "Mayo", "Funder", "Schonbrodt", "Fried", "Coyne", "Yarkoni", "Neuroskeptic", "JEPS", "Morey", "PsychBrief", "DataColada", "Innes-Ker", "Schwarzkopf", "PIG-E", "Rousselet", "Gelman", "Bishop", "Srivastava", "Vazire", "Etz", "Bastian", "Zee", "Schimmack", "Hilgard", "Rouder", "Lakens")
#Create a vector called "BlogGender" with a string of numbers to represent either female, male, or N/a
BlogGender<-c(2,2,2,2,2,2,2,2,2,2,1,1,2,2,1,2,2,2,2,2,2,3,2,1,2,2,2,1,2,2,2,2,1,2,1,2,1,2,2,2,2,2)
#Turn BlogGender into a factor where 1 is labelled Female, 2 male, and 3 N/a
BlogGender<-factor(BlogGender, levels= c(1:3), labels =c("Female","Male", "N/a"))
#Create a data frame of the variable BlogName by the variable BlogGender
Blogs<-data.frame(Name=BlogName, Gender=BlogG
@PsychBrief
PsychBrief / Code for Holmes et al. (2017)
Last active September 27, 2017 13:24
SESOI with different levels of power
#n=2267
#Calculating the smallest partial eta squared the study could detect given smallest effect size f it could detect at 95% power
f95<-c(0.0757429)
eta^2 = f^2 / ( 1 + f^2 )
(f95*f95)/(1+f95*f95)
0.005704262
#Calculating the smallest partial eta squared the study could detect given smallest effect size f it could detect at 80% power
f80<-c(0.0588656)
(f80*f80)/(1+f80*f80)