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
data(attitude)
o = lm(rating ~ complaints, data = attitude)
par(mfrow=c(1,2), bg="white")
plot(rating ~ complaints, data = attitude)
abline(o, col = "red")
plot(o, ask = FALSE)
x = rnorm(1000)
y = rnorm(1000)
plot(x,y,pch=19,col=rgb(0,0,1,.2))

plot of chunk unnamed-chunk-2

@richarddmorey
richarddmorey / index.Rmd
Last active November 29, 2017 21:26
example for shinyjs
---
runtime: shiny
---
```{r echo=FALSE, message=FALSE, warning=FALSE}
require(shinyjs)
useShinyjs(rmd=TRUE)
observe({
updateTextInput(session, 'ID', value = "Updated.")
## Richard D. Morey
## 3 Nov 2017
# Redirect plots to temp directory
# We just want the variables
wd = getwd()
setwd(tempdir())
source('https://osf.io/x73zq/download?version=1')
setwd(wd)
@richarddmorey
richarddmorey / bf_inv.R
Created October 17, 2017 08:44
Inverse function of Bayes factor for t test
## Given a (scaled Cauchy) Bayes factor for the null against the
## alternative (Rouder et al 2009), yields the t statistic
## that would yield it. The ... arguments are passed to
## the ttest.tstat function.
bf.inv = Vectorize(function(b10, ...){
fn = Vectorize(function(t,...){
BayesFactor::ttest.tstat(t,...)[["bf"]]
}, "t")
t0 = optimize(function(t0, ...){
@richarddmorey
richarddmorey / for_lakens.R
Last active October 15, 2017 00:20
For Lakens
find.ncp = Vectorize(function(a=.05, b=.2, df=1){
cr = qchisq(1-a,df)
q = optimize(function(q){
(pchisq(cr,df,ncp=q/(1 - q)) - b)^2
},interval = c(0,1))$minimum
q / (1 - q)
},"b")
find.eb = Vectorize(function(a = 0.05, b = .2, df = 1){
@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
@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 / 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 / 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