Skip to content

Instantly share code, notes, and snippets.

View vasishth's full-sized avatar
💭
My status is high.

Shravan Vasishth vasishth

💭
My status is high.
View GitHub Profile
@vasishth
vasishth / ranking.Rnw
Created November 25, 2014 18:20
hospital rankings
<<>>=
# n: no of operations
# x: no of deaths
# N: no of hospitals
dat<-list(n=c(47,211,810,148,196,360,119,207,97,
256,148,215),
x=c(0,8,46,9,13,24,8,14,8,29,18,31),
N=12)
cat("model
@vasishth
vasishth / recoveringcorrelationsV2.R
Created November 25, 2014 08:25
Maximal models in linear mixed models
### R code from vignette source 'recoveringcorrelationsV2.Rnw'
###################################################
### code chunk number 1: recoveringcorrelationsV2.Rnw:98-156
###################################################
new.df <- function(cond1.rt=487, effect.size=123,
sdev=544,
sdev.int.subj=160, sdev.slp.subj=195,
rho.u=0.6,
nsubj=37,
@vasishth
vasishth / falsepositivesversion2.R
Last active September 27, 2015 11:02
False positives in a lifetime [revised 23 Nov 2014; comments and corrections welcome]
## Our simulated scientist will declare
## significance only if he/she gets
## 2 replications with p<0.05:
stringent<-FALSE
## Set the above to FALSE if you want to
## have the scientist publish a single
## expt. as soon as it's significant:
#stringent <- FALSE
## num of scientists to simulate:
@vasishth
vasishth / falsepositives.R
Last active August 29, 2015 14:10
False positives in a scientist's lifetime
## store proportion of false positives
## in one lifetime of 200 experiments:
prop_fps<-rep(NA,1000)
## run k=1000 scientists, each with
## a lifetime of 200 experiments:
for(k in 1:1000){
## number of experiments for each scientist:
nexp<-200
## prob of sampling from a population
## where the null is true:
@vasishth
vasishth / ParisLecture4.R
Created October 17, 2014 05:25
Paris Lecture 4
### R code from vignette source '04_ADALecture4.Rnw'
###################################################
### code chunk number 1: 04_ADALecture4.Rnw:67-72
###################################################
vpost<-function(v=0.2609^2,n=1,s=0.15^2){
return(1/((1/v)+n/s))
}
n<-seq(1,1000,by=1)
plot(n,vpost(v=2600,n=n),type="l",ylab="posterior variance",xlab="sample size")
@vasishth
vasishth / ParisLecture3.R
Created October 14, 2014 20:49
Paris lecture 3 code
### R code from vignette source '03_ADALecture3.Rnw'
###################################################
### code chunk number 1: 03_ADALecture3.Rnw:85-92
###################################################
data<-read.table("~/Git/Statistics-lecture-notes-Potsdam/AdvancedDataAnalysis/data/gibsonwu2012data.txt",header=T)
## take reciprocal rt to normalize residuals:
data$rrt<- -1000/data$rt
## define predictor x:
data$x <- ifelse(
### R code from vignette source '02_ADALecture2.Rnw'
###################################################
### code chunk number 1: 02_ADALecture2.Rnw:66-72
###################################################
library(mvtnorm)
u0 <- u1 <- seq(from = -3, to = 3, length.out = 30)
Sigma1<-diag(2)
f <- function(u0, u1) dmvnorm(cbind(u0, u1), mean = c(0, 0),sigma = Sigma1)
z <- outer(u0, u1, FUN = f)
@vasishth
vasishth / gist:9bef6eac226c4d17f931
Created October 7, 2014 18:39
Paris Lecture 1 code
### R code from vignette source '01_ADAIntroLecture.Rnw'
###################################################
### code chunk number 1: 01_ADAIntroLecture.Rnw:134-141
###################################################
## load data:
data<-read.table("~/Git/Statistics-lecture-notes-Potsdam/AdvancedDataAnalysis/data/gibsonwu2012data.txt",header=T)
## take reciprocal rt to normalize residuals:
data$rrt<- -1000/data$rt
## define predictor x:
@vasishth
vasishth / gist:f112e80e2d00147b3476
Created August 23, 2014 12:54
Recovering correlations
### R code from vignette source 'recoveringcorrelations.Rnw'
###################################################
### code chunk number 1: recoveringcorrelations.Rnw:93-151
###################################################
new.df <- function(cond1.rt=487, effect.size=123,
sdev=544,
sdev.int.subj=160, sdev.slp.subj=195,
rho.u=0.6,
nsubj=37,
library(MASS)
new.df <- function(cond1.rt=600, effect.size=10, sdev=40,
sdev.int.subj=10, sdev.slp.subj=10,
rho.u=0.6,
nsubj=10,
sdev.int.items=10, sdev.slp.items=10,
rho.w=0.6,
nitems=10) {
ncond <- 2