mcmcarray-object: Objects for representing MCMC output.

Description Usage Arguments Value See Also Examples

Description

A mcmcarray object is returned by the biips_pimh_samples or biips_pmmh_samples functions to represent MCMC output of a given variable.

A mcmcarray.list object is a named list of mcmcarray objects for different monitored variables.

The methods apply identically to mcmcarray or mcmcarray.list objects and return a named list with the same named members as the input object.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
mcmcarray(data = NA, dim = length(data), dimnames = NULL,
  iteration = length(dim), chain = NA, name = "mcmcarray", lower = NULL,
  upper = NULL)

is.mcmcarray(object)

is.mcmcarray.list(object)

## S3 method for class 'mcmcarray'
biips_summary(object, probs = c(), order = ifelse(mode,
  0, 1), mode = all(object == as.integer(object)), ...)

## S3 method for class 'mcmcarray.list'
biips_summary(object, ...)

## S3 method for class 'mcmcarray'
biips_table(x, ...)

## S3 method for class 'mcmcarray'
biips_density(x, bw = "nrd0", ...)

biips_hist(x, ...)

## S3 method for class 'mcmcarray'
biips_hist(x, main = NULL, xlab = NULL, ...)

## S3 method for class 'mcmcarray.list'
biips_table(x, ...)

## S3 method for class 'mcmcarray.list'
biips_density(x, bw = "nrd0", ...)

## S3 method for class 'mcmcarray.list'
biips_hist(x, main = NULL, xlab = NULL, ...)

## S3 method for class 'mcmcarray'
summary(object, ...)

## S3 method for class 'mcmcarray.list'
summary(object, ...)

## S3 method for class 'mcmcarray'
density(x, ...)

## S3 method for class 'mcmcarray.list'
density(x, ...)

## S3 method for class 'mcmcarray'
hist(x, ...)

## S3 method for class 'mcmcarray.list'
hist(x, ...)

Arguments

data

numerical vector

dim

vector of integers. dimension of the array

dimnames

character vector

iteration

integer. index of the dimension corresponding to iterations of the MCMC.

chain

integer. index of the dimension corresponding to chain of the MCMC.

name

string. variable name

lower

vector of integers. variable lower bound

upper

vector of integers. variable upper bound

object, x

a mcmcarray or mcmcarray.list object.

probs

vector of reals. probability levels in ]0,1[ for quantiles. (default = c())

order

integer. Moment statistics of order below or equal to order are returned. (default = 0 if all the components are discrete variables and 1 otherwise)

mode

logical. Activate computation of the mode, i.e. the most frequent value among the particles. (default = TRUE if all the components are discrete variables and FALSE otherwise)

...

additional arguments to be passed to the default methods. See density, hist, table

bw

either a real with the smoothing bandwidth to be used or a string giving a rule to choose the bandwidth. See bw.nrd. (default='nrd0')

main, xlab

plotting parameters with useful defaults.

Value

The methods apply identically to mcmcarray or mcmcarray.list objects and return a named list with the same named members as the input object.

The mcmcarray function returns an object of class mcmcarray.

The function is.mcmcarray returns TRUE if the object is of class mcmcarray.

The function is.mcmcarray.list returns TRUE if the object is of class mcmcarray.list.

The method biips_summary returns univariate marginal statistics. The output innermost members are objects of class summary.mcmcarray, i.e. lists with members:

mean

mean, if order>=1.

var

variance, if order>=2.

skew

skewness, if order>=3.

kurt

kurtosis, if order>=4.

probs

vector of quantile probabilities.

quant

list of quantile values, if probs is not empty.

mode

most frequent values for discrete components.

The method biips_table returns univariate marginal frequency tables or probability mass estimates of discrete variables. The output innermost members are objects of class table.mcmcarray.

The method biips_density returns univariate marginal kernel density estimates. The output innermost members are objects of class density.mcmcarray.

The method summary is an alias for biips_summary.

The method density is an alias for biips_density.

The method hist is an alias for biips_hist.

See Also

density

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
modelfile <- system.file('extdata', 'hmm.bug', package = 'rbiips')
stopifnot(nchar(modelfile) > 0)
cat(readLines(modelfile), sep = '\n')

#' # PIMH algorithm
data <- list(tmax = 10, p = c(.5, .5), logtau_true = log(1), logtau = log(1))
model <- biips_model(modelfile, data, sample_data = TRUE)

n_part <- 50
obj_pimh <- biips_pimh_init(model, c('x', 'c[2:10]'))  # Initialize
out_pimh_burn <- biips_pimh_update(obj_pimh, 100, n_part)  # Burn-in
out_pimh <- biips_pimh_samples(obj_pimh, 100, n_part)  # Samples

#' Manipulate `mcmcarray.list` object
is.mcmcarray.list(out_pimh)
names(out_pimh)
out_pimh
biips_summary(out_pimh)

#' Manipulate `mcmcarray` object
is.mcmcarray(out_pimh$x)
out_pimh$x
summ_pimh_x <- biips_summary(out_pimh$x, order = 2, probs = c(0.025, 0.975))
summ_pimh_x
dens_pimh_x <- biips_density(out_pimh$x)
par(mfrow = c(2, 2))
plot(dens_pimh_x)
par(mfrow = c(2, 2))
biips_hist(out_pimh$x)

is.mcmcarray(out_pimh[['c[2:10]']])
out_pimh[['c[2:10]']]
summ_pimh_c <- biips_summary(out_pimh[['c[2:10]']])
summ_pimh_c
table_pimh_c <- biips_table(out_pimh[['c[2:10]']])
par(mfrow = c(2, 2))
plot(table_pimh_c)

#' # PMMH algorithm
data <- list(tmax = 10, p = c(.5, .5), logtau_true = log(1))
model <- biips_model(modelfile, data)

n_part <- 50
obj_pmmh <- biips_pmmh_init(model, 'logtau', latent_names = c('x', 'c[2:10]'),
                            inits = list(logtau = -2))  # Initialize
out_pmmh_burn <- biips_pmmh_update(obj_pmmh, 100, n_part)  # Burn-in
out_pmmh <- biips_pmmh_samples(obj_pmmh, 100, n_part, thin = 1)  # Samples

#' Manipulate `mcmcarray.list` object
is.mcmcarray.list(out_pmmh)
names(out_pmmh)
out_pmmh
biips_summary(out_pmmh)

#' Manipulate `mcmcarray` object
is.mcmcarray(out_pmmh$logtau)
out_pmmh$logtau
summ_pmmh_lt <- biips_summary(out_pmmh$logtau, order = 2, probs = c(0.025, 0.975))
dens_pmmh_lt <- biips_density(out_pmmh$logtau)
par(mfrow = c(2, 1))
plot(dens_pmmh_lt)
biips_hist(out_pmmh$logtau)

is.mcmcarray(out_pmmh$x)
out_pmmh$x
summ_pmmh_x <- biips_summary(out_pmmh$x, order = 2, probs = c(0.025, 0.975))
dens_pmmh_x <- biips_density(out_pmmh$x)
par(mfrow = c(2, 2))
plot(dens_pmmh_x)
par(mfrow = c(2, 2))
biips_hist(out_pmmh$x)

is.mcmcarray(out_pmmh[['c[2:10]']])
out_pmmh[['c[2:10]']]
summ_pmmh_c <- biips_summary(out_pmmh[['c[2:10]']])
table_pmmh_c <- biips_table(out_pmmh[['c[2:10]']])
par(mfrow = c(2, 2))
plot(table_pmmh_c)

biips/rbiips documentation built on Nov. 28, 2020, 2:12 p.m.