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 / solve.Rmd_
Last active November 17, 2016 02:03
Troubleshooting flexdashboard scrollbars
---
title: "Generated data demo"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: scroll
runtime: shiny
---
```{r setup, include=FALSE}
### Utility functions
# Do a single t test simulation
# report the p value
ttest.sim = function(n, func, true.mean = 0, alpha = 0.05){
x = func(n) - true.mean
t.test(x)$p.value
}
# Do a sequence of M t tests, report significance
@richarddmorey
richarddmorey / delta_t.R
Last active February 27, 2017 22:20
posterior for delta given only t and N
### Data
t = 2
N = 20
rscale = sqrt(2)/2
### Begin utility functions
posterior = Vectorize(function(delta, t, N1, N2 = NULL, rscale = sqrt(2)/2, log = FALSE){
@richarddmorey
richarddmorey / likert_check.R
Last active March 4, 2017 14:51
R script to check possible means and standard deviations for likert responses
############
# Option 1: Get all solutions
# using brute force
############
## This function creates every possible distribution of responses for
## a likert scale with nlev responses. This is total brute force. There's
## probably a better way.
## Argument:
## v : initially, the total number of responses
@richarddmorey
richarddmorey / onetail_lmBF.R
Created April 5, 2017 18:03
One-tailed testing with lmBF
## For the singer dataset
library(lattice)
data(singer)
## Get data ready (recode to two factors)
singer$female = factor(with(singer, grepl("S",voice.part) | grepl("A",voice.part)))
singer$high = factor(with(singer, grepl("S",voice.part) | grepl("T",voice.part)))
## We will test the hypothesis that the main effect
## of "high voice" is such that high voiced singers are shorter
@richarddmorey
richarddmorey / _scatter.R
Last active May 29, 2017 18:40
APS2017 Presidential symposium slide 1
d = read.csv("https://gist.githubusercontent.com/richarddmorey/f7c3ed9fe3f9f1fc0520f332b4a8efd7/raw/900d75f765a086dba65a316504c926da1c1e894a/golf.csv")
plot(d$score, d$size, xlab = "Course score", ylab = "Perceived size", axes = FALSE, ylim = c(0,9), xlim = c(60,140), pch = 19)
axis(2, at = 1:9, las = 1)
axis(1)
abline(lm(size~score, data = d))
cor(d$size, d$score, method = "spearman")
# edge of significance
cor.test(d$size, d$score, method = "spearman")
@richarddmorey
richarddmorey / cov.R
Created July 1, 2017 15:37
covariance matrix
x = scan()
0.78
0.71
0.69
0.71
0.73
0.68
0.69
0.64
0.64
@richarddmorey
richarddmorey / meta-normal.Rmd
Created July 4, 2017 22:37
Bayesian normal meta-analysis with descriptives
---
title: "Normal meta-analysis"
author: "Richard D. Morey"
date: "04/07/2017"
output: html_document
---
```{r}
# data here
@richarddmorey
richarddmorey / stereograms.csv
Created September 6, 2017 11:08
Frisby and Clatworthy (1975) stereogram data (from http://lib.stat.cmu.edu/DASL/Stories/FusionTime.html)
ID fuseTime condition logFuseTime
1 47.20001 NV 3.85439410445589
2 21.99998 NV 3.09104154426699
3 20.39999 NV 3.01553441065397
4 19.70001 NV 2.98061914335803
5 17.4 NV 2.85647020622048
6 14.7 NV 2.68784749378469
7 13.39999 NV 2.59525396068793
8 13 NV 2.56494935746154
9 12.3 NV 2.50959926237837
@richarddmorey
richarddmorey / sample.eta2.R
Last active October 2, 2017 09:26
Sampling distribution of eta^2, omega^2-hat, and epsilon^2
## Explore the sampling distribution of eta^2, omega^2-hat, and epsilon^2
## Richard D. Morey
## Sept 30, 2017
## Settings
## Number of participants in group
N = 10
## Number of groups
J = 3