Skip to content
Snippets Groups Projects
Commit 68f3e9d5 authored by Boulakis Paradeisios Alexandros's avatar Boulakis Paradeisios Alexandros
Browse files

folder organization

parent 5b84e648
No related branches found
No related tags found
No related merge requests found
??pwr
sesoi.eff <- pwr.t.test(n=previous.sample,
sig.level=alpha.level,
power = 1/3,
type="two.sample",
alternative="two.sided" )
# Packages ---------------------------------------------------------------------
list.of.packages <- c("pwr")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
library(pwr)
# Find SESOI -------------------------------------------------------------------
previous.sample <- 25
alpha.level <- .01
beta.level <- .05
# find the SESOI
# ask for help using ??pwr
sesoi.eff <- pwr.t.test(n=previous.sample,
sig.level=alpha.level,
power = 1/3,
type="two.sample",
alternative="two.sided" )
sesoi.eff
sesoi.eff$n
pwr.t.test(sig.level=alpha.level,
power = beta.level,
d=sesoi.eff$d
type="two.sample",
pwr.t.test(sig.level=alpha.level,
power = beta.level,
d=sesoi.eff$d,
type="two.sample",
alternative="two.sided" )
pwr.t.test(sig.level=alpha.level,
power = 1- beta.level,
d=sesoi.eff$d,
type="two.sample",
alternative="two.sided" )
# Simulation parameters --------------------------------------------------------
n.sim <- 500
cohen.d <- .6
sd <- 2
alpha.error <- .01
beta.error <- .05
sample.sizes <- seq(10,200,5)
numeric(len(sample.sizes))
storage.power <- numeric(length(sample.sizes))
storage.power
?rnorm
?t.test
set.seed(2024)
# Simulation parameters --------------------------------------------------------
n.sim <- 500
cohen.d <- .6
sd <- 2
alpha.error <- .01
beta.error <- .05
sample.sizes <- seq(10,200,5)
# Simulation ------------------------------------------------------------------
storage.power <- numeric(length(sample.sizes))
#for every sample size
for (sample.size in sample.sizes){
# create a storage vector for pvals
storage.statistic <- numeric(n.sim)
# create a storage vector for statistic
storage.pvals <- numeric(n.sim)
# for every simulation
for (simulation in seq(n.sim)){
control.data <- rnorm(n=sample.size,mean = 0, sd= sd)
smoker.data <- rnorm(n=sample.size,mean = cohen.d, sd= sd)
results <- t.test(control.data,smoker.data)
}
}
results
control.data
smoker.data
results$statistic
results$p.value
# for every simulation
for (simulation in seq(n.sim)){
# simulate random normally distributed samples for group 1 and add noise
control.data <- rnorm(n=sample.size,mean = 0, sd= sd)
# simulate random normally distributed samples for group 2, add your effect and noise
smoker.data <- rnorm(n=sample.size,mean = cohen.d, sd= sd)
# do an independent t-test
results <- t.test(control.data,smoker.data)
# store statistic and pvals
storage.statistic[simulation] <- results$statistic
storage.pvals[simulation] <- results$p.value
}
storage.pvals
storage.pvals
storage.pvals < alpha.error
mean(storage.pvals < alpha.error)
set.seed(2024)
# Simulation parameters --------------------------------------------------------
n.sim <- 500
cohen.d <- .6
sd <- 2
alpha.error <- .01
beta.error <- .05
sample.sizes <- seq(10,200,5)
# Simulation ------------------------------------------------------------------
storage.power <- numeric(length(sample.sizes))
#for every sample size
for (ii in seq(length(sample.sizes)){
set.seed(2024)
# Simulation parameters --------------------------------------------------------
n.sim <- 500
cohen.d <- .6
sd <- 2
alpha.error <- .01
beta.error <- .05
sample.sizes <- seq(10,200,5)
# Simulation ------------------------------------------------------------------
storage.power <- numeric(length(sample.sizes))
#for every sample size
for (ii in seq(length(sample.sizes))){
# create a storage vector for pvals
storage.statistic <- numeric(n.sim)
# create a storage vector for statistic
storage.pvals <- numeric(n.sim)
# for every simulation
for (simulation in seq(n.sim)){
# simulate random normally distributed samples for group 1 and add noise
control.data <- rnorm(n=sample.sizes[ii],mean = 0, sd= sd)
# simulate random normally distributed samples for group 2, add your effect and noise
smoker.data <- rnorm(n=sample.sizes[ii],mean = cohen.d, sd= sd)
# do an independent t-test
results <- t.test(control.data,smoker.data)
# store statistic and pvals
storage.statistic[simulation] <- results$statistic
storage.pvals[simulation] <- results$p.value
}
# count how many results where significant
achieved.power <- mean(storage.pvals < alpha.error)
storage.power[ii] <- achieved.power
}
storage.power
set.seed(2024)
# Simulation parameters --------------------------------------------------------
n.sim <- 500
cohen.d <- .6
sd <- 2
alpha.error <- .01
beta.error <- .05
sample.sizes <- seq(10,200,5)
# Simulation ------------------------------------------------------------------
storage.power <- numeric(length(sample.sizes))
#for every sample size
for (ii in seq(length(sample.sizes))){
print(ii,sample.sizes[ii])
# create a storage vector for pvals
storage.statistic <- numeric(n.sim)
# create a storage vector for statistic
storage.pvals <- numeric(n.sim)
# for every simulation
for (simulation in seq(n.sim)){
# simulate random normally distributed samples for group 1 and add noise
control.data <- rnorm(n=sample.sizes[ii],mean = 0, sd= sd)
# simulate random normally distributed samples for group 2, add your effect and noise
smoker.data <- rnorm(n=sample.sizes[ii],mean = cohen.d, sd= sd)
# do an independent t-test
results <- t.test(control.data,smoker.data)
# store statistic and pvals
storage.statistic[simulation] <- results$statistic
storage.pvals[simulation] <- results$p.value
}
# count how many results where significant
achieved.power <- mean(storage.pvals < alpha.error)
storage.power[ii] <- achieved.power
}
sample.sizes
sample.sizes[ii]
set.seed(2024)
# Simulation parameters --------------------------------------------------------
n.sim <- 500
cohen.d <- .6
sd <- 2
alpha.error <- .01
beta.error <- .05
sample.sizes <- seq(10,200,5)
# Simulation ------------------------------------------------------------------
storage.power <- numeric(length(sample.sizes))
#for every sample size
for (ii in seq(length(sample.sizes))){
print(sample.sizes[ii])
# create a storage vector for pvals
storage.statistic <- numeric(n.sim)
# create a storage vector for statistic
storage.pvals <- numeric(n.sim)
# for every simulation
for (simulation in seq(n.sim)){
# simulate random normally distributed samples for group 1 and add noise
control.data <- rnorm(n=sample.sizes[ii],mean = 0, sd= sd)
# simulate random normally distributed samples for group 2, add your effect and noise
smoker.data <- rnorm(n=sample.sizes[ii],mean = cohen.d, sd= sd)
# do an independent t-test
results <- t.test(control.data,smoker.data)
# store statistic and pvals
storage.statistic[simulation] <- results$statistic
storage.pvals[simulation] <- results$p.value
}
# count how many results where significant
achieved.power <- mean(storage.pvals < alpha.error)
storage.power[ii] <- achieved.power
}
storage.power
set.seed(2024)
# Simulation parameters --------------------------------------------------------
n.sim <- 500
cohen.d <- .6
sd <- 1
alpha.error <- .01
beta.error <- .05
sample.sizes <- seq(10,200,5)
# Simulation ------------------------------------------------------------------
storage.power <- numeric(length(sample.sizes))
#for every sample size
for (ii in seq(length(sample.sizes))){
print(sample.sizes[ii])
# create a storage vector for pvals
storage.statistic <- numeric(n.sim)
# create a storage vector for statistic
storage.pvals <- numeric(n.sim)
# for every simulation
for (simulation in seq(n.sim)){
# simulate random normally distributed samples for group 1 and add noise
control.data <- rnorm(n=sample.sizes[ii],mean = 0, sd= sd)
# simulate random normally distributed samples for group 2, add your effect and noise
smoker.data <- rnorm(n=sample.sizes[ii],mean = cohen.d, sd= sd)
# do an independent t-test
results <- t.test(control.data,smoker.data)
# store statistic and pvals
storage.statistic[simulation] <- results$statistic
storage.pvals[simulation] <- results$p.value
}
# count how many results where significant
achieved.power <- mean(storage.pvals < alpha.error)
storage.power[ii] <- achieved.power
}
storage.power
# Packages ---------------------------------------------------------------------
list.of.packages <- c("ggplot2")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
library(ggplot2)
set.seed(2024)
# Simulation parameters --------------------------------------------------------
n.sim <- 500
cohen.d <- .6
sd <- 1
alpha.error <- .01
beta.error <- .05
sample.sizes <- seq(10,200,5)
# Simulation ------------------------------------------------------------------
storage.power <- numeric(length(sample.sizes))
#for every sample size
for (ii in seq(length(sample.sizes))){
print(sample.sizes[ii])
# create a storage vector for pvals
storage.statistic <- numeric(n.sim)
# create a storage vector for statistic
storage.pvals <- numeric(n.sim)
# for every simulation
for (simulation in seq(n.sim)){
# simulate random normally distributed samples for group 1 and add noise
control.data <- rnorm(n=sample.sizes[ii],mean = 0, sd= sd)
# simulate random normally distributed samples for group 2, add your effect and noise
smoker.data <- rnorm(n=sample.sizes[ii],mean = cohen.d, sd= sd)
# do an independent t-test
results <- t.test(control.data,smoker.data)
# store statistic and pvals
storage.statistic[simulation] <- results$statistic
storage.pvals[simulation] <- results$p.value
}
# count how many results where significant
achieved.power <- mean(storage.pvals < alpha.error)
storage.power[ii] <- achieved.power
}
ggplot(data=NULL,aes(x=sample.sizes,y=storage.power))+
geom_line()
ggplot(data=NULL,aes(x=sample.sizes,y=storage.power))+
geom_line()+
geom_point()
ggplot(data=NULL,aes(x=sample.sizes,y=storage.power))+
geom_line()+
geom_point()+
labs(
title = "Simulation for Power Analysis",
x = "Sample Size",
y = "Achieved Power",
) +
theme_minimal()
ggplot(data=NULL,aes(x=sample.sizes,y=storage.power))+
geom_line()+
geom_point()+
labs(
title = "Simulation for Power Analysis",
x = "Sample Size",
y = "Achieved Power",
)
ggplot(data=NULL,aes(x=sample.sizes,y=storage.power))+
geom_line()+
geom_point()+
geom_vline(xintercept=1-beta.error)
labs(
title = "Simulation for Power Analysis",
x = "Sample Size",
y = "Achieved Power",
)
ggplot(data=NULL,aes(x=sample.sizes,y=storage.power))+
geom_line()+
geom_point()+
geom_hline(xintercept=1-beta.error)
labs(
title = "Simulation for Power Analysis",
x = "Sample Size",
y = "Achieved Power",
)
ggplot(data=NULL,aes(x=sample.sizes,y=storage.power))+
geom_line()+
geom_point()+
geom_hline(yintercept=1-beta.error)
labs(
title = "Simulation for Power Analysis",
x = "Sample Size",
y = "Achieved Power",
)
ggplot(data=NULL,aes(x=sample.sizes,y=storage.power))+
geom_line()+
geom_point()+
geom_hline(yintercept=1-beta.error,color = 'red', linetype = "dashed", size = 1)
labs(
title = "Simulation for Power Analysis",
x = "Sample Size",
y = "Achieved Power",
)
ggplot(data=NULL,aes(x=sample.sizes,y=storage.power))+
geom_line()+
geom_point()+
geom_hline(yintercept=1-beta.error,color = 'red', linetype = "dashed", linewidth = 1) +
labs(
title = "Simulation for Power Analysis",
x = "Sample Size",
y = "Achieved Power",
)
target.sample <- sample.sizes[storage.power > 1-beta.error][1]
target.sample
# Packages ---------------------------------------------------------------------
list.of.packages <- c("ggplot2")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
library(ggplot2)
set.seed(2024)
# Simulation parameters --------------------------------------------------------
n.sim <- 500
cohen.d <- .6
sd <- 1
alpha.error <- .01
beta.error <- .05
sample.sizes <- seq(10,200,5)
# Simulation ------------------------------------------------------------------
storage.power <- numeric(length(sample.sizes))
#for every sample size
for (ii in seq(length(sample.sizes))){
print(sample.sizes[ii])
# create a storage vector for pvals
storage.statistic <- numeric(n.sim)
# create a storage vector for statistic
storage.pvals <- numeric(n.sim)
# for every simulation
for (simulation in seq(n.sim)){
# simulate random normally distributed samples for group 1 and add noise
control.data <- rnorm(n=sample.sizes[ii],mean = 0, sd= sd)
# simulate random normally distributed samples for group 2, add your effect and noise
smoker.data <- rnorm(n=sample.sizes[ii],mean = cohen.d, sd= sd)
# do an independent t-test
results <- t.test(control.data,smoker.data)
# store statistic and pvals
storage.statistic[simulation] <- results$statistic
storage.pvals[simulation] <- results$p.value
}
# count how many results where significant
achieved.power <- mean(storage.pvals < alpha.error)
storage.power[ii] <- achieved.power
}
# print when your results was above your threshold
target.sample <- sample.sizes[storage.power > 1-beta.error][1]
ggplot(data=NULL,aes(x=sample.sizes,y=storage.power))+
geom_line()+
geom_point()+
geom_hline(yintercept=1-beta.error,color = 'red', linetype = "dashed", linewidth = 1) +
labs(
title = sprintf("Simulation for Power Analysis: Required sample size = %s",target.sample),
x = "Sample Size",
y = "Achieved Power",
)
# Packages ---------------------------------------------------------------------
list.of.packages <- c("ggplot2")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
library(ggplot2)
set.seed(2024)
# Simulation parameters --------------------------------------------------------
n.sim <- 5000
cohen.d <- .6
sd <- 1
alpha.error <- .01
beta.error <- .05
sample.sizes <- seq(10,200,5)
# Simulation ------------------------------------------------------------------
storage.power <- numeric(length(sample.sizes))
#for every sample size
for (ii in seq(length(sample.sizes))){
print(sample.sizes[ii])
# create a storage vector for pvals
storage.statistic <- numeric(n.sim)
# create a storage vector for statistic
storage.pvals <- numeric(n.sim)
# for every simulation
for (simulation in seq(n.sim)){
# simulate random normally distributed samples for group 1 and add noise
control.data <- rnorm(n=sample.sizes[ii],mean = 0, sd= sd)
# simulate random normally distributed samples for group 2, add your effect and noise
smoker.data <- rnorm(n=sample.sizes[ii],mean = cohen.d, sd= sd)
# do an independent t-test
results <- t.test(control.data,smoker.data)
# store statistic and pvals
storage.statistic[simulation] <- results$statistic
storage.pvals[simulation] <- results$p.value
}
# count how many results where significant
achieved.power <- mean(storage.pvals < alpha.error)
storage.power[ii] <- achieved.power
}
# print when your results was above your threshold
target.sample <- sample.sizes[storage.power > 1-beta.error][1]
ggplot(data=NULL,aes(x=sample.sizes,y=storage.power))+
geom_line()+
geom_point()+
geom_hline(yintercept=1-beta.error,color = 'red', linetype = "dashed", linewidth = 1) +
labs(
title = sprintf("Simulation for Power Analysis: Required sample size = %s",target.sample),
x = "Sample Size",
y = "Achieved Power",
)
ggplot(data=NULL,aes(x=sample.sizes,y=storage.power))+
geom_line()+
geom_point()+
geom_hline(yintercept=1-beta.error,color = 'red', linetype = "dashed", linewidth = 1) +
geom_hline(xintercept=target.sample,color = 'red', linetype = "dashed", linewidth = 1) +
labs(
title = sprintf("Simulation for Power Analysis: Required sample size = %s",target.sample),
x = "Sample Size",
y = "Achieved Power",
)
ggplot(data=NULL,aes(x=sample.sizes,y=storage.power))+
geom_line()+
geom_point()+
geom_hline(yintercept=1-beta.error,color = 'red', linetype = "dashed", linewidth = 1) +
geom_vline(xintercept=target.sample,color = 'red', linetype = "dashed", linewidth = 1) +
labs(
title = sprintf("Simulation for Power Analysis: Required sample size = %s",target.sample),
x = "Sample Size",
y = "Achieved Power",
)
# Packages ---------------------------------------------------------------------
list.of.packages <- c("pwr","rpact")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
library(pwr)
library(rpact)
??pwr
??pwr
sesoi.eff <- pwr.t.test(n=previous.sample.cont + previous.sample.depr,
sig.level=alpha.level,
power = 1/3,
type="two.sample",
alternative="two.sided" )
previous.sample.cont <- 50
previous.sample.depr <- 44
alpha.error <- .01
beta.error <- .05
sesoi.eff <- pwr.t.test(n=previous.sample.cont + previous.sample.depr,
sig.level=alpha.level,
power = 1/3,
type="two.sample",
alternative="two.sided" )
sesoi.eff
sesoi.eff <- pwr.t.test(n=50,
sig.level=alpha.level,
power = 1/3,
type="two.sample",
alternative="two.sided" )
sesoi.eff
power <- pwr.t.test(sig.level=alpha.level,
power = 1- beta.level,
d=sesoi.eff$d,
type="two.sample",
alternative="two.sided" )
power
??rpact
design <- getDesignGroupSequential(
kMax = 4,
typeOfDesign = "P",
sided = 2,
alpha = alpha.error,
beta = beta.error
)
print(summary(design))
?getDesignGroupSequential
library(ggplot2)
# make results replicable
set.seed(2024)
# specify how many simulations you want to run
nSimul <- 10000
# specify how many effects size you want to test
effects <- seq(.1,.9,.1)
# specify how many sample sizes you want to test
samples <- seq(10,150,10)
# Storage for plotting
results <- list()
# Simulation loop
for (effect in effects) {
sample.storage <- numeric(length(samples))
for (ii in seq_along(samples)) {
p.storage <- numeric(nSimul)
for (simulation in seq(nSimul)) {
# run statistical test
x <- rnorm(n = samples[ii], mean = 0, sd = 1)
y <- rnorm(n = samples[ii], mean = effect, sd = 1)
#extract significance
z <- t.test(x, y)
p.storage[simulation] <- z$p.value
}
achieved.power <- mean(p.storage < 0.05)
sample.storage[ii] <- achieved.power
}
# Store results for the current effect size
results[[paste0("effect_", effect)]] <- data.frame(
sample_size = samples,
achieved_power = sample.storage
)
}
# Combine results into a single data frame for plotting
plot_data <- do.call(rbind, lapply(names(results), function(effect) {
data <- results[[effect]]
data$effect <- effect
data
}))
# Convert effect to numeric for better plotting
plot_data$effect <- as.numeric(gsub("effect_", "", plot_data$effect))
# Create the plot
ggplot(plot_data, aes(x = sample_size, y = achieved_power, color = factor(effect))) +
geom_line(linewidth = 1) +
labs(
title = "Achieved Power vs. Sample Size",
x = "Sample Size",
y = "Achieved Power",
color = "Effect Size"
) +
theme_minimal()
library(ggplot2)
# make results replicable
set.seed(2024)
# specify how many simulations you want to run
nSimul <- 10000
# specify how many effects size you want to test
effects <- seq(.1,.9,.1)
# specify how many sample sizes you want to test
samples <- seq(10,150,10)
# Storage for plotting
results <- list()
# Simulation loop
for (effect in effects) {
sample.storage <- numeric(length(samples))
for (ii in seq_along(samples)) {
p.storage <- numeric(nSimul)
for (simulation in seq(nSimul)) {
# run statistical test
x <- rnorm(n = samples[ii], mean = 0, sd = 1)
y <- rnorm(n = samples[ii], mean = effect, sd = 1)
#extract significance
z <- t.test(x, y)
p.storage[simulation] <- z$p.value
}
achieved.power <- mean(p.storage < 0.05)
sample.storage[ii] <- achieved.power
}
# Store results for the current effect size
results[[paste0("effect_", effect)]] <- data.frame(
sample_size = samples,
achieved_power = sample.storage
)
}
# Combine results into a single data frame for plotting
plot_data <- do.call(rbind, lapply(names(results), function(effect) {
data <- results[[effect]]
data$effect <- effect
data
}))
# Convert effect to numeric for better plotting
plot_data$effect <- as.numeric(gsub("effect_", "", plot_data$effect))
# Create the plot
ggplot(plot_data, aes(x = sample_size, y = achieved_power, color = factor(effect))) +
geom_line(linewidth = 1) +
labs(
title = "Achieved Power vs. Sample Size",
x = "Sample Size",
y = "Achieved Power",
color = "Effect Size"
) +
theme_minimal()
File moved
# Packages ---------------------------------------------------------------------
list.of.packages <- c("pwrss")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
library(pwrss)
# Independent t-test -----------------------------------------------------------
# parameters
cont.mean <- 130
drug.mean <- 120
cont.sd <- 15
drug.sd <- 15
alpha.error <- .05
beta.error <- .05
alternative <- "not equal" # also try "greater" or "less"
# find the correct function
# assign the correct parameters
# you can look around the documentation of pwrss library using ??pwrss
t.test.power <-
plot(t.test.power)
# Paired t-test ----------------------------------------------------------------
# parameters
before.mean <- 130
after.mean <- 120
before.sd <- 15
after.sd <- 15
alpha.error <- .05
beta.error <- .05
alternative <- "not equal" # also try "greater" or "less"
# find the correct function
# assign the correct parameters
# you can look around the documentation of pwrss library using ??pwrss
paired.t.power <-
plot(paired.t.power)
# Packages ---------------------------------------------------------------------
list.of.packages <- c("pwrss")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
library(pwrss)
# Independent t-test -----------------------------------------------------------
# parameters
cont.mean <- 130
drug.mean <- 120
cont.sd <- 15
drug.sd <- 15
alpha.error <- .05
beta.error <- .05
alternative <- "not equal" # also try "greater" or "less"
# find the correct function
# assign the correct parameters
# you can look around the documentation of pwrss library using ??pwrss
t.test.power <-
plot(t.test.power)
# Paired t-test ----------------------------------------------------------------
# parameters
before.mean <- 130
after.mean <- 120
before.sd <- 15
after.sd <- 15
alpha.error <- .05
beta.error <- .05
alternative <- "not equal" # also try "greater" or "less"
# find the correct function
# assign the correct parameters
# you can look around the documentation of pwrss library using ??pwrss
paired.t.power <-
plot(paired.t.power)
File moved
# Packages ---------------------------------------------------------------------
list.of.packages <- c("pwr")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
library(pwr)
# Find SESOI -------------------------------------------------------------------
previous.sample <- 25
alpha.level <- .01
beta.level <- .05
# find the SESOI
# ask for help using ??pwr
sesoi.eff <-
# Find power -------------------------------------------------------------------
# run a power analysis using the SESOI
# ask for help using ??pwr
# Packages ---------------------------------------------------------------------
list.of.packages <- c("pwr")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
library(pwr)
# Find SESOI -------------------------------------------------------------------
previous.sample <- 25
alpha.level <- .01
beta.level <- .05
# find the SESOI
# ask for help using ??pwr
sesoi.eff <-
# Find power -------------------------------------------------------------------
# run a power analysis using the SESOI
# ask for help using ??pwr
File moved
# Packages ---------------------------------------------------------------------
list.of.packages <- c("ggplot2")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
library(ggplot2)
set.seed(2024)
# Simulation parameters --------------------------------------------------------
n.sim <-
cohen.d <-
sd <-
alpha.error <-
beta.error <-
sample.sizes <-
# Simulation ------------------------------------------------------------------
#create storage so you track every sample size's power
#for every sample size (try to iterate over the indices)
# create a storage vector for pvals
# create a storage vector for statistic
# for every simulation
# simulate random normally distributed samples for group 1 and add noise
# simulate random normally distributed samples for group 2, add your effect and noise
# do an independent t-test
# store statistic and pvals
# count how many results where significant
# print when your results was above your threshold
# think of when you sample sizes become larger than the power you want to achieve
# Packages ---------------------------------------------------------------------
list.of.packages <- c("ggplot2")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
library(ggplot2)
set.seed(2024)
# Simulation parameters --------------------------------------------------------
n.sim <-
cohen.d <-
sd <-
alpha.error <-
beta.error <-
sample.sizes <-
# Simulation ------------------------------------------------------------------
#create storage so you track every sample size's power
#for every sample size (try to iterate over the indices)
# create a storage vector for pvals
# create a storage vector for statistic
# for every simulation
# simulate random normally distributed samples for group 1 and add noise
# simulate random normally distributed samples for group 2, add your effect and noise
# do an independent t-test
# store statistic and pvals
# count how many results where significant
# print when your results was above your threshold
# think of when you sample sizes become larger than the power you want to achieve
File moved
File moved
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment