% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/PPD.R
\name{PPD}
\alias{PPD}
\title{Posterior Predictive Distribution from mcmcComposite object}
\usage{
PPD(
  x,
  chain = "all",
  FUN = NULL,
  probs = c(0.025, 0.975),
  xlim = NULL,
  nameparxlim = NULL,
  namepar = NULL
)
}
\arguments{
\item{x}{A mcmcComposite obtained as a result of \code{MHalgoGen()} function}

\item{chain}{The number of the chain in which to get parameters or "all"}

\item{FUN}{The function to apply the parameters. It must be text.}

\item{probs}{The probability to get quantiles}

\item{xlim}{The values to apply in fun if required}

\item{nameparxlim}{The name of the parameter for xlim}

\item{namepar}{The name of parameters from mcmc object to be used in fun}
}
\value{
A data.frame with quantiles
}
\description{
Extract quantile distributions from mcmcComposite object. If FUN is used, it keeps the
correlations between parameters.
}
\examples{
\dontrun{
library(HelpersMG)
require(coda)
x <- rnorm(30, 10, 2)
dnormx <- function(data, x) {
 data <- unlist(data)
 return(-sum(dnorm(data, mean=x['mean'], sd=x['sd'], log=TRUE)))
}

parameters_mcmc <- setPriors1(Name = "mean", 
                              Density = "dnorm", Prior1 = 10, Prior2 = 2, 
                              SDProp = 1, Min = -3, Max = 100, Init = 10)
parameters_mcmc <- parameters_mcmc + setPriors1(Name = "sd", 
                              Density = "dlnorm", Prior1 = 0.5, Prior2 = 0.5, 
                              SDProp = 1, Min = 0, Max = 10, Init = 2)
                              
mcmc_run <- MHalgoGen(n.iter=10000, parameters=parameters_mcmc, data=x, 
                     likelihood=dnormx, n.chains=1, n.adapt=100, thin=1, trace=1)

# Return the 2.5\% and 97.5\% quantiles of the mean parameter
k <- PPD(x=mcmc_run, namepar="mean")
k <- PPD(x=mcmc_run, namepar=NULL)
k <- PPD(x=mcmc_run, namepar=c("mean", "sd"))

# Here I return the distribution of coefficient of variation as a posterior predictive distribution
k <- PPD(x=mcmc_run            , 
                 FUN="sd/mean" )

# I can generate an output based on a x variable 
k <- PPD(x=mcmc_run                   , 
                  xlim=c(1, 2)        ,
                  nameparxlim="mult"  ,
                  FUN="mult*mean"     )
}
}
\seealso{
Other mcmcComposite functions:
\code{\link[=+.PriorsmcmcComposite]{+.PriorsmcmcComposite()}},
\code{\link[=MHalgoGen]{MHalgoGen()}},
\code{\link[=as.mcmc.mcmcComposite]{as.mcmc.mcmcComposite()}},
\code{\link[=as.parameters]{as.parameters()}},
\code{\link[=merge.mcmcComposite]{merge.mcmcComposite()}},
\code{\link[=plot.PriorsmcmcComposite]{plot.PriorsmcmcComposite()}},
\code{\link[=plot.mcmcComposite]{plot.mcmcComposite()}},
\code{\link[=setPriors]{setPriors()}},
\code{\link[=setPriors1]{setPriors1()}},
\code{\link[=summary.mcmcComposite]{summary.mcmcComposite()}}
}
\author{
Marc Girondot \email{marc.girondot@gmail.com}
}
\concept{mcmcComposite functions}
