JAGS Code: My first few models


library('rjags')

#Simple Normal
N <- 1000
x <- rnorm(N, 0, 5)
jags <- jags.model('example1.bug',data = list('x' = x,'N' = N))
update(jags, 1000)
jags.samples(jags,c('mu', 'tau'),1000)

#############################################################
#Two Conditions
N <- 1000
x <- rnorm(N, 0, 5)
y <- rnorm(N, 1, 5)
jags <- jags.model('example2.bug',data = list('x' = x,'y' = y,'N' = N))
update(jags, 1000)
jags.samples(jags,c('mu1', 'mu2', 'tau'),1000)

##############################################################
#Two Conditions, Efffects Parameterization
N <- 1000
x <- rnorm(N, 0, 5)
y <- rnorm(N, 1, 5)
jags <- jags.model('example3.bug',data = list('x' = x,'y' = y,'N' = N))
update(jags, 1000)
jags.samples(jags,c('mu', 'alpha', 'tau'),1000)

############################################################
#Many conditions, hierarchical
N=100
M=30
y=matrix(nrow=M,ncol=N)
for (i in 1:M) y[i,]=rnorm(N,i,1)
jags <- jags.model('example4.bug',data = list('y' = y,'N' = N,'M'=M))
update(jags, 1000)
jags.samples(jags,c('mu','tau','theta','tauD'),1000)

AttachmentSize
example1.bug122 bytes
example2.bug172 bytes
example3.bug179 bytes
example4.bug263 bytes

Research Methods 3020