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
#Install pwr package if needed | |
if(!require(pwr)){install.packages('pwr')} | |
library(pwr) | |
alpha_level = 0.05 #set alpha level | |
n = 100 #set number of observations | |
st_dev = 1 #set true standard deviation | |
SESOI <- 0.5 #set smallest effect size of interest (raw mean difference) | |
# calculate lower and upper critical values c_l and c_u |
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
#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 |
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
--- | |
title: "Observed Alpha Levels" | |
output: | |
word_document: default | |
html_document: | |
df_print: paged | |
editor_options: | |
chunk_output_type: console | |
--- |
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
# Code by Chelsea Parlett, small additions by Daniel Lakens | |
library(pwr) | |
library(ggplot2) | |
#set up vector of effect sizes | |
es <- seq(0.01,1, length = 1000) | |
#specify power for test | |
pow <- 0.8 | |
#calculate ns (sample size for 80% power in two-sided test) |
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
optimal_alpha <- function(power_function, costT1T2 = 1, prior_H1H0 = 1, error = "minimal") { | |
#Define the function to be minimized | |
f = function(x, power_function, costT1T2 = 1, prior_H1H0 = 1, error = "minimal") { | |
y <- 1 - eval(parse(text=paste(power_function))) | |
print(c(x, y, x+y)) #optional: print alpha, beta, and objective | |
if(error == "balance"){ | |
max((costT1T2*x - prior_H1H0*y)/(prior_H1H0+1), (prior_H1H0*y - costT1T2*x)/(prior_H1H0+1)) | |
} else if (error == "minimal"){ | |
2*(costT1T2*x + prior_H1H0*y)/(prior_H1H0+1) | |
} |
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
#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) | |
} |
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
if(!require(ggplot2)){install.packages('ggplot2')} | |
library(ggplot2) | |
n=20 #set sample size | |
nSims<-100000 #set number of simulations | |
x<-rnorm(n = n, mean = 100, sd = 15) #create sample from normal distribution | |
#95%CI | |
CIU<-mean(x)+qt(0.975, df = n-1)*sd(x)*sqrt(1/n) |
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
require(ggplot2) | |
#Save downloaded Scopus data in your working directory | |
scopusdata<-read.csv("scopusPS2010_2015.csv") | |
plot1<-ggplot(scopusdata, aes(x=Cited.by)) + | |
geom_histogram(colour="#535353", fill="#84D5F0", binwidth=2) + | |
xlab("Number of Citations") + ylab("Number of Articles") + | |
ggtitle("Citation Data for Psychological Science 2011-2015") + | |
coord_cartesian(xlim = c(-5, 250)) |
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
if(!require(meta)){install.packages('meta')} | |
library(meta) | |
nSims <- 1000000 #number of simulated experiments | |
numberstudies<-4 # nSim/numberofstudies should be whole number | |
p <-numeric(nSims) #set up empty container for all simulated p-values | |
metapran <-numeric(nSims/numberstudies) #set up empty container for all simulated p-values for random effects MA | |
metapfix <-numeric(nSims/numberstudies) #set up empty container for all simulated p-values for fixed effects MA | |
heterog.p<-numeric(nSims/numberstudies) #set up empty container for test for heterogeneity | |
d <-numeric(nSims) #set up empty container for all simulated d's |
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
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 |