Learn R Programming

HelpersMG (version 6.2)

as.quantiles: Extract quantile distribution from mcmcComposite object

Description

Extract quantile distribution from mcmcComposite object

Usage

as.quantiles(
  x,
  chain = 1,
  fun = function(...) return(as.numeric(list(...))),
  probs = c(0.025, 0.975),
  xlim = NULL,
  nameparxlim = NULL,
  namepar = NULL
)

Value

A data.frame with quantiles

Arguments

x

A mcmcComposite obtained as a result of MHalgoGen() function

chain

The number of the chain in which to get parameters

fun

The function to apply the parameters

probs

The probability to get quantiles

xlim

The values to apply in fun

nameparxlim

The name of the parameter for xlim

namepar

The name of parameters from mcmc object to be used in fun

Author

Marc Girondot marc.girondot@gmail.com

See Also

Other mcmcComposite functions: MHalgoGen(), as.mcmc.mcmcComposite(), as.parameters(), merge.mcmcComposite(), plot.PriorsmcmcComposite(), plot.mcmcComposite(), setPriors(), summary.mcmcComposite()

Examples

Run this code
if (FALSE) {
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 <- data.frame(Density=c('dnorm', 'dlnorm'), 
Prior1=c(10, 0.5), Prior2=c(2, 0.5), SDProp=c(1, 1), 
Min=c(-3, 0), Max=c(100, 10), Init=c(10, 2), stringsAsFactors = FALSE, 
row.names=c('mean', 'sd'))
mcmc_run <- MHalgoGen(n.iter=10000, parameters=parameters_mcmc, data=x, 
likelihood=dnormx, n.chains=1, n.adapt=100, thin=1, trace=1)
k <- as.quantiles(x=mcmc_run, namepar="mean")
k <- as.quantiles(x=mcmc_run, namepar="mean", 
                 xlim=c(1:5), nameparxlim="sd", 
                 fun=function(...) return(sum(as.numeric(list(...)))))
}

Run the code above in your browser using DataLab