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
set.seed(1) | |
# genarate random paired sets and get p-values for t-test and wolcoxon test | |
ps = replicate(10000, (function() { | |
temp = tibble( | |
subject = paste0("S", 1:100), | |
before = rnorm(100, 5, 1) %>% round() %>% pmin(7) %>% pmax(1) | |
) %>% mutate(after = (before + rnorm(100,0,1)) %>% round() %>% pmin(7) %>% pmax(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
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 |
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
#' Find every `scale_colour_*()` in the environment and remap it for a different colour-based aesthetic. | |
#' The new scale functions will be named `scale_[new_aesthetics]_*()`. | |
#' | |
#' @param new_aesthetics The name of one or more new colour-based aesthetics to create scales for | |
#' @rdname reuse_scale | |
#' @export | |
reuse_all_colour_scales <- function(new_aesthetics = c("fill")) { | |
new_aesthetic_name <- paste(new_aesthetics, collapse="") | |
# get colour scales | |
all_variable_names <- ls(envir = parent.env(current_env())) |
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) | |
# from https://github.com/matsukik/grt/blob/master/R/gaborPatch.R | |
gaborPatchTidy <- function( | |
spatial_frequency, | |
orientation_degrees = 0, | |
orientation_radians = (orientation_degrees * pi)/180, | |
peak_contrast = 1, | |
sigma = 1/6, # same for x and y | |
psi = 0, |
NewerOlder