sampleNormb {hbmem}R Documentation

Function sampleNormb

Description

Same as sampleNorm, but assumes an additive model on sigma2, and takes the block of sigma2 parameters as argument

Usage

sampleNormb(sample,y,subj,item,lag,I,J,R,nsub,nitem,s2mu,s2a,s2b,meta,metb,blockSigma2,sampLag)

Arguments

sample Block of linear model parameters from previous iteration.
y Vector of data
subj Vector of subject index, starting at zero.
item Vector of item index, starting at zero.
lag Vector of lag index, zero-centered.
I Number of subjects.
J Number of items.
R Total number of trials.
nsub Vector of length (I) containing number of trials per each subject.
nitem Vector of length (J) containing number of trials per each item.
s2mu Prior variance on the grand mean mu; usually set to some large number.
s2a Shape parameter of inverse gamma prior placed on effect variances.
s2b Rate parameter of inverse gamma prior placed on effect variances. Setting both s2a AND s2b to be small (e.g., .01, .01) makes this an uninformative prior.
meta Matrix of tuning parameter for metropolis-hastings decorrelating step on mu and alpha. This hould be adjusted so that .2 < b0 < .6.
metb Tunning parameter for decorrelating step on alpha and beta.
blockSigma2 Block of parameters for Sigma2 (on log scale). Like all blocks, first element is the overall mean, followed by participant effects and then item effects.
sampLag Logical. Whether or not to sample the lag effect.

Value

The function returns a list. The first element of the list is the newly sampled block of parameters. The second element contains a vector of 0s or 1s indicating which of the decorrelating steps were accepted.

Author(s)

Michael S. Pratte

See Also

hbmem

Examples

library(hbmem)
I=20
J=50
B=I+J+4 #number of parameters in block
R=I*J
trueSigma2=1
#make some data
dat=normalSim(I=I,J=J,mu=10,s2a=1,s2b=1,muS2=log(trueSigma2),s2aS2=0,s2bS2=0)
nsub=table(dat$sub)
nitem=table(dat$item)
blockS2=c(trueSigma2,rep(0,B-1))

M=2000
keep=200:M
s.block=matrix(0,nrow=M,ncol=B)
met=c(.1,.1);b0=c(0,0)
for(m in 2:M)
{
tmp=sampleNormb(s.block[m-1,],dat$resp,dat$subj,dat$item,dat$lag,I,J,R,nsub,nitem,100,.01,.01,met[1],met[2],blockS2,1)
s.block[m,]=tmp[[1]]
b0=b0 + tmp[[2]]
}

hbest=colMeans(s.block[keep,])
estAlpha=tapply(dat$resp,dat$subj,mean) - mean(dat$resp)
estBeta=tapply(dat$resp,dat$item,mean) - mean(dat$resp)

par(mfrow=c(2,3),pch=19,pty='s')
plot(s.block[keep,1],t='l')
abline(h=mean(dat$resp),col="green")
plot(hbest[2:(I+1)]~estAlpha)
abline(0,1,col="green")
plot(hbest[(I+2):(I+J+1)]~estBeta)
abline(0,1,col="green")

#variance of participant effect
hist(s.block[keep,(I+J+2)])
#variance of item effect
hist(s.block[keep,(I+J+3)])
#estimate of lag effect 
hist(s.block[keep,(I+J+4)])

[Package hbmem version 0.1 Index]