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(tidyverse) | |
library(patchwork) | |
library(glue) | |
set.seed(7) | |
data = tibble( | |
x = rnorm(50, 5), | |
y = x + rnorm(50, 0, .7), | |
x_noise = x + rnorm(50, 0, 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
# t-test vs wilcox vs ordinal | |
library(tidyverse) | |
library(multidplyr) # parallelize | |
library(rms) # ordinal regression | |
sample_size = 100 # N | |
# genarate paired sets and calculate p-values with different techniques |
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(tidyverse) | |
library(ggdist) | |
data = expand.grid( | |
effect_size = c(0, 0.2, 0.4, 0.6, 0.8), | |
sample_size = 1000, | |
rep = 1:10000 | |
) %>% |
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
# put each attribute into a column if possible | |
# rownames_to_column: (logical) add rownames if the attribute exists | |
# fix_name_conflicts: (logical) if an attribute name already exists as a column name, find a unique name for it | |
attributes_to_columns = function(dataframe, rownames_to_column = TRUE, fix_name_conflicts = TRUE) { | |
for (name in names(attributes(dataframe))) { | |
value = attr(dataframe, name) | |
if (name %in% c("names", "class")) { | |
#skip |
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(tidyverse) | |
# simulate one experiment | |
simulate = function(subject_count = 20, effect_size = 0) { | |
a = rnorm(subject_count/2) | |
b = rnorm(subject_count/2, effect_size) | |
tibble( | |
p = t.test(a, b, alternative = "less")$p.value, | |
d = (mean(b) - mean(a)) / sd(c(a-mean(a), b-mean(b))) | |
) |
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
# t-test vs wilcox vs ordinal | |
library(tidyverse) | |
library(multidplyr) # parallelize | |
library(rms) # ordinal regression | |
sample_size = 500 # N | |
# generate paired sets and calculate p-values with different techniques |
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
a | b | c | |
---|---|---|---|
5.567 | 5.592 | 0.679 | |
-3.816 | -5.165 | -0.164 | |
0.294 | -0.225 | -0.333 | |
-0.942 | 0.39 | 0 | |
-2.08 | -6.879 | 1.217 | |
-3.736 | -2.92 | -3.078 | |
1.015 | -5.236 | -1.246 | |
-2.046 | -7.99 | 0.234 | |
0.595 | 2.535 | 0.599 |
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
# Simulate different experiment designs and approaches to calculating Cohen's D | |
# References | |
# https://journalofcognition.org/articles/10.5334/joc.10 (h/t Aaron Caldwell @arcstats.bsky.social) | |
# https://jakewestfall.org/blog/index.php/2016/03/25/five-different-cohens-d-statistics-for-within-subject-designs/ | |
library(tidyverse) | |
library(lmerTest) | |
library(multidplyr) # not necessary, but helps performance |
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(tidyverse) | |
library(effectsize) # cohens_d() | |
# reproducible | |
set.seed(8675309) | |
# simulate one experiment | |
simulate = function(count_a, count_b, replicate_count) { | |
count_total = count_a + count_b |
NewerOlder