Skip to content

Instantly share code, notes, and snippets.

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))
@steveharoz
steveharoz / .block
Last active March 21, 2024 15:14 — forked from mbostock/.block
d3-force testing ground
license: gpl-3.0
height: 1030
scrolling: yes
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

#' 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()))
@steveharoz
steveharoz / eye.R
Last active September 13, 2023 11:16
Logo for the Vision Science feed on BlueSky
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,
@steveharoz
steveharoz / datacolada 110.R
Last active June 20, 2023 14:15
datacolada 110 replot
library(tidyverse)
library(foreign) # for read.spss()
library(ggdist) # for geom_dots()
# load the data
# source: https://osf.io/sd76g/
data = foreign::read.spss("data_Experiment_4.sav", to.data.frame=TRUE) %>%
as_tibble()