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(metafor) | |
g <- escalc( | |
measure = "SMD", | |
n1i = 43, # sample size in group 1 is 50 | |
m1i = 1.3, # observed mean in group 1 is 5.6 | |
sd1i = 1, # observed standard deviation in group 1 is 1.2 | |
n2i = 43, # sample size in group 2 is 53 | |
m2i = 1, # observed mean in group 1 is 4.9 | |
sd2i = 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
library(segHT) | |
library(rpact) | |
looks <- 3 | |
n_seg <- 50 | |
alpha_level <- 0.05 | |
true_d <- 0.5 # can not enter 0, segmented_hyp_test_outcomes gives error | |
############################### | |
# Segmented procedure ---- |
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: "Power Analysis for Interactions" | |
author: "Daniel Lakens" | |
date: "28-3-2020" | |
output: | |
html_document: default | |
pdf_document: default | |
word_document: default | |
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
# Scienceverse Sim | |
# install scienceverse | |
# devtools::install_github("scienceverse/scienceverse") | |
library(scienceverse) | |
library(faux) | |
set.seed(2) # set.seed(2) is a random draw where H1 is corroborated. |
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
# Scienceverse Sim | |
# install scienceverse | |
# devtools::install_github("scienceverse/scienceverse") | |
library(scienceverse) | |
library(faux) | |
set.seed(2) # set.seed(2) is a random draw where H1 is corroborated. |
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
n<-2000 #total number of datapoints (per condition) you are willing to collect after initial 10 | |
D<-0.0 #True effect size (Keep SD below to 1, otherwise, this is just mean dif, not d) | |
SD<-1 #Set True standard deviation. | |
p<-numeric(n) #store p-values | |
x<-numeric(n) #store x-values | |
y<-numeric(n) #store y-values | |
n<-n+10 #script calculates p-values after 10 people in each condition, so add 10 to number of datapoints |
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
#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
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) | |
} |
NewerOlder