Skip to content

Instantly share code, notes, and snippets.

@steveharoz
steveharoz / t-test vs wilcox vs ordinal.R
Last active July 2, 2024 19:58
t-test vs Wilcox test vs ordinal regression
# 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
@steveharoz
steveharoz / extreme p_values.R
Created June 28, 2024 19:01
Extreme p-values
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
) %>%
# 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
@steveharoz
steveharoz / readme.MD
Last active April 26, 2024 09:50
Uncanny Mountain simulations
@steveharoz
steveharoz / Replication rate by effect size.R
Last active April 3, 2024 16:54
Replication rate by effect size
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)))
)
# 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
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
@steveharoz
steveharoz / cohens d replicate simulation.R
Last active November 13, 2023 03:22
cohen's d by replicate count
# 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
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
@steveharoz
steveharoz / readme.md
Last active October 26, 2023 21:06
NOAA Storm and Hurricane data for this year

Plot:

image