View guess_number.txt
https://www.theguardian.com/science/2021/feb/08/can-you-solve-it-think-of-a-number | |
The suggested answer using "yes" and "no" amounts to encoding in base 2, which is inefficient because there are | |
three possible response options ("yes", "no", "I don't know"). We want to find a way of encoding in base 3, which | |
amounts to assigning 1/3 of the numbers to "yes", 1/3 to "no", and 1/3 to "I don't know". We can do that by telling | |
Johnny on the first step (and analogously afterward): | |
"I have two numbers in mind. One of them is 334. The other is less than 667 but greater than 333, but I will not tell you what it is. Is your | |
number less than both of my numbers?" |
View rlogis.R
x = rlogis(10000,0,10) | |
mod = "model{ | |
y ~ dlogis(0, 1/10) | |
} | |
" | |
library(rjags) | |
m = rjags::jags.model(file = textConnection(mod)) | |
s = rjags::coda.samples(m,n.iter = 10000,variable.names = "y") |
View time.R
library(tictoc) | |
df = data.frame(y = rnorm(10000000), x = rbinom(10000000,1,.5)) | |
tic() | |
z = df[df$x == 1,]$y | |
toc() | |
rm(z) | |
tic() |
View X2.R
N = c(16, 16) | |
y = c(3, 9) | |
actual_result = prop.test(y, N, correct = FALSE) | |
compute_p_value = function(p0){ | |
## Probability of all outcomes, | |
## assuming independence | |
pr_X2s = | |
outer( dbinom(0:N[1], N[1], p0), |
View eqt_pvalue.R
data(attitude) | |
library(cocor) | |
## EQtest at alpha = .05 needs a 90% CI | |
cocor(~ rating + complaints | rating + learning, data = attitude, alternative = "less", | |
null.value = .2, test = "zou2007", conf.level = .9) | |
zou_ci_func = function(conf.level, ...) | |
{ |
View repro_subways.R
## Get file off OSF | |
tf = tempfile(fileext = ".xlsx") | |
download.file(url = "https://osf.io/846cb/download", destfile = tf) | |
## Create summaries | |
library(tidyverse) | |
readxl::read_xlsx(tf) %>% | |
group_by(STN_NUMBER, DIRECTION) %>% | |
summarise( |
View planning_precision.Rmd
--- | |
title: "Power and precision" | |
author: "Richard D. Morey" | |
date: "11/06/2020" | |
output: | |
html_document: | |
dev: png | |
self_contained: no | |
editor_options: | |
chunk_output_type: console |
View papaja_example.Rmd
--- | |
title : "The title" | |
shorttitle : "Title" | |
author: | |
- name : "First Author" | |
affiliation : "1" | |
corresponding : yes # Define only one corresponding author | |
address : "Postal address" | |
email : "my@email.com" |
View precision.R
desired_precision = .6 | |
N1 = 5 | |
N2 = 6 | |
# Function to compute CDFs of "precisions" (CI widths) | |
SS_func = function(W, n, alpha = .05){ | |
n * (n - 1) * W^2 / (4 * qt(1-alpha/2, n - 1)^2) | |
} |
View bf_one_way
# Prior setup | |
prior_concentration = 10 | |
# null | |
p0 = c(0.3, 0.3, 0.4) | |
# fake data, null |
NewerOlder