Learn R Programming

hbmem (version 0.3-3)

sampleNorm: Function sampleNorm

Description

Samples posterior of mean parameters of the hierarchical linear normal model with a single Sigma2. Usually used within an MCMC loop.

Usage

sampleNorm(sample, y, cond, subj, item, lag, N, I, J, R, ncond, nsub,
nitem, s2mu, s2a, s2b, meta, metb, sigma2, sampLag=TRUE,Hier=TRUE)

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 and 1s indicating which of the decorrelating steps were accepted.

Arguments

sample

Block of linear model parameters from previous iteration.

y

Vector of data

cond

Vector of condition index, starting at zero.

subj

Vector of subject index, starting at zero.

item

Vector of item index, starting at zero.

lag

Vector of lag index, zero-centered.

N

Number of conditions.

I

Number of subjects.

J

Number of items.

R

Total number of trials.

ncond

Vector of length (N) containing number of trials per each condition.

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.

sigma2

Variance of distribution.

sampLag

Logical. Whether or not to sample the lag effect.

Hier

Logical. If TRUE then effect variances are estimated from data. If FALSE then these values are set to whatever value is in the s2alpha and s2beta slots of sample. This should always be set to TRUE.

Author

Michael S. Pratte

References

See Pratte, Rouder, & Morey (2009)

See Also

hbmem

Examples

Run this code
library(hbmem)
N=2
t.mu=c(1,2)
I=20
J=50
R=I*J
#make some data
tmp=normalSim(N=N,I=I,J=J,mu=t.mu,s2a=2,s2b=2,muS2=log(1),s2aS2=0,s2bS2=0)
dat=tmp[[1]]
t.alpha=tmp[[2]]
t.beta=tmp[[3]]

ncond=table(dat$cond)
nsub=table(dat$sub)
nitem=table(dat$item)

M=10
keep=2:M
B=N+I+J+3
s.block=matrix(0,nrow=M,ncol=B)
met=c(.1,.1);b0=c(0,0)
jump=.001
for(m in 2:M)
{
tmp=sampleNorm(s.block[m-1,],dat$resp,dat$cond,dat$subj,dat$item,dat$lag,
N,I,J,R,ncond,nsub,nitem,5,.01,.01,met[1],met[2],1,1,1)
s.block[m,]=tmp[[1]]
b0=b0 + tmp[[2]]


#Auto-tuning of metropolis decorrelating steps 
if(m>20 & m.3)*c(jump,jump)
    met[met

Run the code above in your browser using DataLab