Skip to content

Instantly share code, notes, and snippets.

@steveharoz
steveharoz / Texas congressional district simulation.R
Created October 21, 2021 16:53
Texas congressional district simulation
library(tidyverse)
# arbitrary number
district_count = 38
# population from stephanie's figure
# https://twitter.com/evergreendata/status/1450862060972216320
population = c(
rep("White", 40),
rep("Latino", 39),
@steveharoz
steveharoz / data simulation
Last active October 14, 2021 12:58
power analysis for within-subject, high-repetition experiment
library(tidyverse)
library(magrittr)
library(afex)
library(Superpower)
set.seed(555)
SUBJECT_COUNT = 3 # per between-subject condition
#### ground-truth parameters for 3w x 2w x 2b (100 repetitions)
@steveharoz
steveharoz / ggdist psychometric functions.R
Last active September 28, 2021 07:44
ggdist psychometric functions
library(tidyverse)
library(ggdist)
# make some data
expand_grid(
condition = c("A", "B"),
stimulus = seq(-3,3,0.3),
repetitions = 1:20
) %>%
# make some noisy response data
@steveharoz
steveharoz / readme.txt
Created September 5, 2021 14:09
Atlantic Ocean Storms 1975-2020
reference: https://dplyr.tidyverse.org/reference/storms.html
visualization: https://imgur.com/a/TMONnmS
source: https://www.nhc.noaa.gov/data/#hurdat
@steveharoz
steveharoz / _words before and after.R
Last active September 16, 2021 00:37
Get text before "author" or "researcher" and after "author is" or "authors are"
library(tidyverse)
PATH = "peerj_reviews_txt/"
ignored_words = c("the", "dear", "original")
filenames = dir(path = PATH, pattern="*.txt", recursive = TRUE)
preceeding_words = sapply(filenames, function(f) {
words = read_file(paste0(PATH, f)) %>%
subject x color rep y
H 1 0 1 10.390916389674972
J 1 0 1 11.877635692199044
A 1 0 1 6.40831056135098
G 1 0 1 10.143656530161934
F 1 0 1 9.858462287495191
B 1 0 1 8.726973066068064
C 1 0 1 9.09479144777112
D 1 0 1 9.689029831578754
E 1 0 1 9.806302728246905
# simulate true effect sizes vs p in 0.01-0.05 range
library(tidyverse)
SUBJECT_COUNT = 16
TEST_COUNT = 16
# test if the p-value is in the specified range
inRange = function(p) {
(p > 0.01) & (p < 0.05)
}
library(tidyverse)
library(ggdist) # for stat_histinterval()
############# make the dataset ###################
# 1 sample per subject per condition
data_per_subject_condition = expand_grid(
subjectID = paste0("S", 1:50),
independent_variable_A = c("circle", "square"),
independent_variable_B = 1:3
@steveharoz
steveharoz / VR Gender.R
Created May 28, 2020 11:32
VR research - correlation between female participant proportion vs simulator sickness
library(tidyverse)
# Mind the Gap:The Underrepresentation of Female Participants and Authors in Virtual Reality Research
# Tabitha C. Peck,Laura E. Sockol, and Sarah M. Hancock
# Table 3
data = read_csv(
"Study,N,CohensD,CI.Low,CI.Hi,p,SAMD,FemaleParticipants
Arafat et al. [4],16,0.42,0.19,0.65,<.001,−.07,81%
Ariza et al. [5],18,0.12,-0.09,0.33,0.263,−.68,22%
We can make this file beautiful and searchable if this error is corrected: It looks like row 9 should actually have 8 columns, instead of 4. in line 8.
X,COVID-19 New Cases,Rep 1-N1,Rep 2-N1,Rep 1-N2,Rep 2-N2,Hospital admissions,virus RNA/ml
0,0.0,0.01771832019916774,0.025327583188293947,0.0012636319937241525,0.021536686448187715,0.22274881516587694,0.011848341232227562
1,0.0,0.01771832019916774,0.013927423563501674,0.0,0.01771832019916774,0.2819905213270144,0.014218009478673148
2,0.0,0.06076422295302489,0.10633738965673233,0.008872894878409794,0.006345630953625507,0.07819905213270138,0.06161137440758302
3,0.044047743576570264,0.0,0.1164739172696972,0.0012636319937241525,0.036727742012376295,0.22274881516587694,0.0
4,0.07024387534899187,0.15191055715279342,0.05950059026999374,0.0898827021364172,0.036727742012376295,0.2819905213270144,0.12796208530805683
5,0.022630983907802882,0.09240996608905253,0.08482817343043705,0.07342801384045856,0.08861906947427432,0.3388625592417062,0.08293838862559255
6,0.1726258132144233,0.17215614066131332,0.24558415520075633,0.28102079504903993,0.14682855819289167,0.22274881516587694,0.20616113744075823
7,0.0,0.15822871709356356,0