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 / gist:7879095
Created December 9, 2013 19:18
Hierarchical linear model (varying intercepts model) with t distribution instead of normal
model
{
# The model for each observational unit
# (each row is a subject's data point)
for( j in 1:N )
{
mu[j] <- beta[1] + beta[2] * ( so[j] ) + u[subj[j]] + w[item[j]]
rt[j] ~ dnorm( mu[j], tau.e )
##change the above line to:
#rt[j] ~ dt(mu[j],tau.e, 2)
@vasishth
vasishth / gist:7879003
Created December 9, 2013 19:13
Speed of light data revisited.
newcomb <-
c(28,26,33,24,34,-44,27,16,40,-2,
29,22,24,21,25,30,23,29,31,19,
24,20,36,32,36,28,25,21,28,29,
37,25,28,26,30,32,36,26,30,22,
36,23,27,27,28,27,31,27,26,33,
26,32,32,24,39,28,24,25,32,25,
29,27,28,29,16,23)
# Data as a list
@vasishth
vasishth / corr_fixedef_lm.R
Last active December 15, 2015 00:28
linear model correlations of fixed effects
> summary(lm<-lm(wear~material-1,BHHshoes))
> X<-model.matrix(lm)
> 2.49^2*solve(t(X)%*%X)
materialA materialB
materialA 0.62001 0.00000
materialB 0.00000 0.62001
@vasishth
vasishth / corr_fixedeff_example1.R
Created March 15, 2013 19:48
Example of correlations of fixed effects
> (lm.full<-lmer(wear~material-1+(1|Subject), data = BHHshoes))
Linear mixed model fit by REML
Formula: wear ~ material - 1 + (1 | Subject)
Data: BHHshoes
AIC BIC logLik deviance REMLdev
62.9 66.9 -27.5 53.8 54.9
Random effects:
Groups Name Variance Std.Dev.
Subject (Intercept) 6.1009 2.470
Residual 0.0749 0.274
@vasishth
vasishth / corr_fixedeff_example2.R
Created March 15, 2013 19:50
Calculating correlations of fixed effects in LMEs
> b1.vals<-subset(BHHshoes,material=="A")$wear
> b2.vals<-subset(BHHshoes,material=="B")$wear
>
> vcovmatrix<-var(cbind(b1.vals,b2.vals))
>
> covar<-vcovmatrix[1,2]
> sds<-sqrt(diag(vcovmatrix))
> covar/(sds[1]*sds[2])
b1.vals
0.98823
@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 / vincentgranville.txt
Created December 15, 2014 08:36
vincentgranville.txt
“He seems to have a solid stats background back in the day”
A lot of people claim a lot of things about themselves. I have met a lot of people who characterize themselves as “fluent in Japanese” (oddly, these are always Americans), where their actual on-the-ground fluency level is pretty laughable.
I couldn’t find any clear statements about what his educational background is. He says on his linkedin page: “Facultés universitaires ‘Notre-Dame de la Paix’ Ph.D., Statistics, Mathematics, Science, 1983 – 1993″, Then he lists two courses he did there, “Stochastic Geometry, Markov Processes.” I find it odd that a guy does a PhD somewhere, over 10 years, and lists two courses under that PhD.
Also, I searched for this mysterious uni I have never heard of: Facultés universitaires ‘Notre-Dame de la Paix.
I ended up at a weird Jesuits page in Belgium:
@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 / 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: