Rev 3543 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{mcmcsamp}\docType{genericFunction}\alias{mcmcsamp}\alias{mcmcsamp,lmer-method}\alias{mcmcsamp,glmer-method}\title{Generate an MCMC sample}\description{This generic function generates a sample from the posteriordistribution of the parameters of a fitted model using Markov ChainMonte Carlo methods.}\usage{mcmcsamp(object, n, verbose, \dots)}\arguments{\item{object}{An object of a suitable class - usually an\code{\linkS4class{lmer}} or \code{\linkS4class{glmer}} object.}\item{n}{integer - number of samples to generate. Defaults to 1.}\item{verbose}{logical - if \code{TRUE} verbose output is printed.Defaults to \code{FALSE}.}\item{\dots}{Some methods for this generic function may takeadditional, optional arguments. The method for\code{\linkS4class{lmer}} objects takes the optional argument\code{saveb} which, if \code{TRUE}, causes the values of the randomeffects in each sample to be saved. Note that this can result invery large objects being saved. Use with caution. A second optionalargument is \code{trans} which, if \code{TRUE} (the default), returnsa sample of transformed parameters. All variances are expressed onthe logarithm scale and any covariances are converted to Fisher's "z"transformation of the corresponding correlation.}}\value{An object of (S3) class \code{"mcmc"} suitable for use with thefunctions in the "coda" package.}\section{Methods}{\describe{\item{object = "lmer"}{generate MCMC samples from the posteriordistribution of the parameters of a linear mixed model. The prioron the fixed effects parameters is taken to be locally uniform.The prior on the variance-covariance matrices of the randomeffects is taken to be the locally non-informative prior describedin Box and Tiao (1973). Conditional on the current values of therandom effects these are sampled from a Wishart distribution.}\item{object = "glmer"}{generate MCMC samples from the posteriordistribution of the parameters of a generalized linear mixedmodel. The prior on the fixed effects parameters is taken to belocally uniform. The prior on the variance-covariance matrices ofthe random effects is taken to be the locally non-informativeprior described in Box and Tiao (1973). Conditional on the currentvalues of the random effects these are sampled from a Wishartdistribution.}}}\examples{require("lattice", quietly = TRUE, character = TRUE)data(sleepstudy)(fm1 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy))set.seed(101)samp1 <- mcmcsamp(fm1, n = 1000)frm <-data.frame(vals = c(samp1), iter = rep(1:nrow(samp1), ncol(samp1)),par = factor(rep(1:ncol(samp1), each = nrow(samp1)),labels = colnames(samp1)))densityplot(~ vals | par, frm, plot.points = FALSE,scales = list(relation = 'free', x = list(axs='i')))xyplot(vals ~ iter | par, frm, layout = c(1, ncol(samp1)),scales = list(x = list(axs = "i"), y = list(relation = "free")),main = "Trace plot", xlab = "Iteration number", ylab = "",type = "l")qqmath(~ vals | par, frm, type = 'l',scales = list(y = list(relation = 'free')))if (require("coda", quietly = TRUE, character = TRUE)) {print(summary(samp1))print(autocorr.diag(samp1))}(eDF <- mean(samp1[,"deviance"]) - deviance(fm1, REML=FALSE)) # potentially useful approximate D.F.\dontshow{stopifnot(abs(eDF - 7) < 1)}}\keyword{methods}\keyword{datagen}