Learn R Programming

ltbayes (version 0.3)

postsamp: MCMC Simulation from the Posterior Distribution of the Latent Trait of an Item Response Model

Description

postsamp implements Markov chain Monte Carlo (MCMC) algorithms to simulate realizations from the posterior distribution of the latent trait of an item response model. The distribution is conditional on a single response vector or a subset of response vectors.

Usage

postsamp(fmodel, y, method = "metrop", control = list(), ...)

Arguments

fmodel
Function with first argument zeta which returns a list of the (unnormalized) natural logarithm of the posterior distribution evaluted at zeta. This must be returned as a list with the named object post.
y
A m-dimensional vector or a s by m matrix of item responses, where in the latter case the posterior is computed by conditioning on the event that the response pattern is one of the s response patterns in y. .
method
The sampler used. Currently the options are a random-walk Metropolis sampler (method = 'metrop') or an adaptive random-walk Metropolis sampler (method = 'adapt'). Both samplers use a normal proposal distribution. The default is method = 'mcmc'.
control
List of options for the sampler. See the help file for the sampler used for details. For method = 'metrop' see metrop and for method = 'adapt' see Metro_Hastings.
...
Additional arguments to be pased to fmodel.

Value

out
List of the output from the sampler. See the help file for the sampler specified in method for details.

Warning

Sampling from the posterior distribution of the latent trait of an item response model typically exhibits quick convergence and efficient mixing. However as with any MCMC algorithm it is important to check the performance of the algorithm. In some cases adjustment of the scale of the proposal density may be necessary to achieve a suitable acceptance rate.

Details

This function uses MCMC samplers from the mcmc and MHadaptive packages, using the functions metrop and Metro_Hastings for random-walk (method = 'metrop') and adaptive random-walk (method = 'adapt') Metropolis samplers, respectively. Default options are used by postsamp except that the default burn-in samples is set to zero and the number of samples is set to 1000.

See Also

See metrop and Metro_Hastings for details on the samplers.

Examples

Run this code
# simulating 10000 realizations from the posterior distribution from
# a partial credit model using a non-adaptive Metropolis algorithm
zeta <- postsamp(fmodelpcm, c(0,1,2,1,0), bpar = matrix(0, 5, 2),
   control = list(nbatch = 10000))
plot(zeta$batch, type = "l") # trace plot

# simulating 10000 realizations from the posterior distribution from
# a partial credit model using an adaptive Metropolis algorithm
zeta <- postsamp(fmodelpcm, c(0,1,2,1,0), bpar = matrix(0, 5, 2),
   control = list(iterations = 10000), method = 'adapt')
plot(zeta$trace, type = "l") # trace plot

Run the code above in your browser using DataLab