Skip to content

Instantly share code, notes, and snippets.

@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()
@steveharoz
steveharoz / generate graph analyze.R
Last active June 13, 2023 08:38
Example data for analysis
library(tidyverse)
library(lmerTest)
# subject count
COUNT = 5
set.seed(8675309)
# generate a unique intercept per subject
data = tibble(
@steveharoz
steveharoz / image.md
Last active May 18, 2023 11:42
perceived correlation of rank

image

@steveharoz
steveharoz / extract citation numbers.R
Created January 7, 2023 08:07
Extract IEEE citation numbers from a PDF
# Extract all citation numbers such as [1] from a PDF's text
# It also includes cases for multiples [1, 3] and ranges [1-5]
# It tries to exclude confidence intervals by skipping
#
# written by Steve Haroz with help from ChatGPT
# MIT license
library(tidyverse)
library(pdftools)
@steveharoz
steveharoz / multiple comparison simulation.R
Last active December 1, 2022 02:28
Simulate multiple comparisons to show that an adjustment is needed
COUNT = 100000
# How often does a single t-test of random data yield p<0.05?
replicate(COUNT,
t.test(rnorm(20))$p.value < 0.05
) %>% mean()
#> 0.05073
# 5% false positive rate
@steveharoz
steveharoz / README.md
Last active October 29, 2022 15:29 — forked from cjrd/README.md
Interactive tool for creating directed graphs using d3.js.

directed-graph-creator

Interactive tool for creating directed graphs, created using d3.js.

Operation:

  • drag/scroll to translate/zoom the graph
  • shift-click on graph to create a node
  • shift-click on a node and then drag to another node to connect them with a directed edge
@steveharoz
steveharoz / hierarchical pie.R
Created April 5, 2022 02:16
hierarchical pie
library(tidyverse)
COUNT = 40
data = tibble(
car = paste0(sample(LETTERS, COUNT, TRUE), sample(letters, COUNT, TRUE), sample(letters, COUNT, TRUE)),
value = rnorm(COUNT, 3),
group = c(rep("Petrol", COUNT/2), rep("Hybrid", COUNT/4), rep("Pure Electric", COUNT/8), rep("Diesel", COUNT/8))
)
@steveharoz
steveharoz / endpoint.R
Last active February 16, 2022 14:42
Endpoint stat for ggplot
StatEndpoint <- ggproto("StatEndpoint", Stat,
compute_group = function(data, scales) {
# sort by x so indexing is meaningful
data = arrange(data, x)
# grab only the first and last row
data[c(1,nrow(data)),]
},
required_aes = c("x", "y")
)
@steveharoz
steveharoz / .block
Last active January 13, 2022 23:02
animacy
height: 600