Skip to content

Instantly share code, notes, and snippets.

View richarddmorey's full-sized avatar

Richard Morey richarddmorey

  • Cardiff University
  • Cardiff, Wales
View GitHub Profile
@richarddmorey
richarddmorey / eqt_pvalue.R
Last active July 17, 2020 11:37
Compute p value for equivalence test
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, ...)
{
@richarddmorey
richarddmorey / repro_subways.R
Created June 21, 2020 18:42
Attempt to reproduce Maglio & Polman (2014) Figure 1
## 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(
@richarddmorey
richarddmorey / planning_precision.Rmd
Created June 12, 2020 16:30
Figures for "Power and precision" blog post
---
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
---
title : "The title"
shorttitle : "Title"
author:
- name : "First Author"
affiliation : "1"
corresponding : yes # Define only one corresponding author
address : "Postal address"
email : "[email protected]"
@richarddmorey
richarddmorey / precision.R
Created August 21, 2019 20:28
CI "precision" reversal
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)
}
@richarddmorey
richarddmorey / bf_one_way
Created June 23, 2019 12:41
Bayes factor for one-way table
# Prior setup
prior_concentration = 10
# null
p0 = c(0.3, 0.3, 0.4)
# fake data, null
@richarddmorey
richarddmorey / eurovision2019.csv
Last active May 19, 2019 11:48
Eurovision 2016-2018 analysis
To.country Jury Televoting
Netherlands 231 261
Italy 212 253
Russia 125 244
Switzerland 148 212
Norway 47 291
Sweden 239 93
Azerbaijan 197 100
North Macedonia 237 58
Australia 154 131
@richarddmorey
richarddmorey / demo.R
Last active April 3, 2019 09:00
Demonstrate reading bibtex for Rmarkdown from the web (e.g., from github)
# This file is to demonstrate the output.
# It is not needed.
testRmd = "https://gist.githubusercontent.com/richarddmorey/c4dd7d1fba2aa055a6f71286baedac25/raw/c256dd9f1ca0b22dfbce12443e1cb98ed5bb9d86/demo.Rmd"
tf = tempfile(fileext = ".Rmd")
tf_out = tempfile(fileext = ".html")
cat(RCurl::getURL(testRmd), file = tf)
@richarddmorey
richarddmorey / install_flexjags.R
Last active March 19, 2019 12:15
Install flexjags in R for Essex Summer School 3F (Bayesian data analysis)
## First install the devtools package if necessary
devtools::install_github("richarddmorey/EssexSummerSchoolBayes", subdir = "shiny_demo/flexjags/flexjags")
flexjags::run_flexjags()
@richarddmorey
richarddmorey / power.R
Created March 26, 2018 12:48
power graph
M = 1000
N = round(sort(rpois(M, 10)^1.5, decreasing = TRUE)) + 20
pows = c(.5,.8,.95)
setup = expand.grid(N=N, pow = pows)
es = mapply(FUN = function(n, power, alpha) power.t.test(n = n, sig.level = alpha, power = power)$delta,
n = setup$N, power = setup$pow, MoreArgs = list(alpha = .05))
dim(es) = c(setup$es,length(N), length(pows))