Created
July 7, 2022 10:10
-
-
Save peterdalle/1c888cc973ff87b0882b45ab98dc78e6 to your computer and use it in GitHub Desktop.
2 x 2 between-subjects Anova power analysis
This file contains hidden or 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(ggplot2) | |
library(purrr) | |
library(pwr2) | |
power_analysis_go_brrr <- function(f, n) { | |
res <- pwr.2way(a = 2, b = 2, f.A = f, f.B = f, alpha = .05, size.A = n/2, size.B = n/2) | |
data.frame(f = f, | |
n = n, | |
power_a = res$power.A, | |
power_b = res$power.B, | |
power_ab = res$power) | |
} | |
combinations <- expand.grid(f = c(.10, .15, .20, .25, .30), | |
n = seq.int(2, 1000, by=50)) | |
lots_of_numbers <- pmap_dfr(combinations, power_analysis_go_brrr) | |
lots_of_numbers |> | |
ggplot(aes(n, power_a, color=as.factor(f), shape=as.factor(f))) + | |
geom_point() + | |
geom_line() + | |
scale_x_continuous(breaks = seq.int(0, 1e7, by=100)) + | |
scale_y_continuous(breaks = seq.int(.10, 1, by=.1)) + | |
labs(x = "Total sampelstorlek", | |
y = "Power", | |
color = "Cohen's f", | |
shape = "Cohen's f", | |
title = "2 x 2 between-subjects Anova", | |
subtitle = "alpha = 0.05, samma varians, endast huvudeffekter") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment