smcarray-object: Objects for representing SMC output.

Description Usage Arguments Details Value See Also Examples

Description

A smcarray object is used by the biips_smc_samples function to represent SMC output or particles of a given variable.

A smcarray.fsb object is a named list of smcarray objects with different types of monitoring for the same variable. Members in this list have names f (filtering), s (smoothing) or b (backward smoothing).

A smcarray.fsb.list object is a named list of smcarray.fsb objects for different monitored variables. It might also contain a member named log_marg_like with an estimate of the log marginal likelihood.

The methods apply identically to smcarray, smcarray.fsb or smcarray.fsb.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
is.smcarray(object)

is.smcarray.fsb(object)

is.smcarray.fsb.list(object)

biips_diagnosis(object, ...)

## S3 method for class 'smcarray'
biips_diagnosis(object, ess_thres = 30, quiet = FALSE,
  ...)

## S3 method for class 'smcarray.fsb'
biips_diagnosis(object, type = "fsb", quiet = FALSE,
  ...)

## S3 method for class 'smcarray.fsb.list'
biips_diagnosis(object, type = "fsb",
  quiet = FALSE, ...)

biips_summary(object, ...)

## S3 method for class 'smcarray'
biips_summary(object, probs = c(), order = ifelse(mode,
  0, 1), mode = all(object$discrete), ...)

## S3 method for class 'smcarray.fsb'
biips_summary(object, ...)

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

biips_table(x, ...)

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

biips_density(x, ...)

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

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

## S3 method for class 'smcarray.fsb'
biips_density(x, bw = "nrd0", adjust = 1, ...)

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

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

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

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

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

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

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

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

Arguments

object, x

a smcarray, smcarray.fsb or smcarray.fsb.list object.

...

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

ess_thres

integer. Threshold on the Effective Sample Size (ESS). If all the ESS components are over ess_thres, the diagnostic is 'GOOD', otherwise it is 'BAD'. (default=30).

quiet

logical. Disable message display. (default=FALSE).

type

string containing the characters 'f' (fitering), 's' (smoothing) and/or 'b' (backward smoothing). Select the corresponding members of the input to be analysed. (default = 'fsb').

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)

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')

adjust

scale factor for the bandwidth. the bandwidth used is actually adjust*bw. This makes it easy to specify values like ‘half the default’ bandwidth. (default = 1)

Details

Assuming dim is the dimension of the monitored variable, a smcarray object is a list with the members:

values

array of dimension c(dim, n_part) with the values of the particles.

weights

array of dimension c(dim, n_part) with the weights of the particles.

ess

array of dimension dim with Effective Sample Sizes of the particles set.

discrete

array of dimension dim with logicals indicating discreteness of each component.

iterations

array of dimension dim with sampling iterations of each component.

conditionals

lists of the contitioning variables (observations). Its value is:

  • for filtering: a list of dimension dim. each member is a character vector with the respective conditioning variables of the node array component.

  • for smoothing/backward_smoothing: a character vector, the same for all the components of the node array.

name

string with the name of the variable.

lower

vector with the lower bounds of the variable.

upper

vector with the upper bounds of the variable.

type

string with the type of monitor ('filtering', 'smoothing' or 'backward_smoothing').

For instance, if out_smc is a smcarray.fsb.list object, one can access the values of the smoothing particles for the variable 'x' with: out_smc$x$s$values.

Value

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

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

The function is.smcarray.fsb returns TRUE if the object is of class smcarray.fsb.

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

The method biips_diagnosis prints diagnosis of the SMC output and returns the minimum ESS value.

The method biips_summary returns univariate marginal statistics. The output innermost members are objects of class summary.smcarray. Assuming dim is the dimension of the variable, the summary.smcarray object is a list with the following members:

mean

array of size dim. The mean if order>=1.

var

array of size dim. The variance, if order>=2.

skew

array of size dim. The skewness, if order>=3.

kurt

array of size dim. The kurtosis, if order>=4.

probs

vector of quantile probabilities.

quant

list of arrays of size dim for each probability level in probs. The quantile values, if probs is not empty.

mode

array of size dim. The 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.smcarray.

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

The method summary is an alias for biips_summary.

The method density is an alias for biips_density.

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
modelfile <- system.file('extdata', 'hmm.bug', package = 'rbiips')
stopifnot(nchar(modelfile) > 0)
cat(readLines(modelfile), sep = '\n')

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 <- 100
out_smc <- biips_smc_samples(model, c('x', 'c[2:10]'), n_part, type = 'fs',
                             rs_thres = 0.5, rs_type = 'stratified')

#' Manipulate `smcarray.fsb.list` object
is.smcarray.fsb.list(out_smc)
names(out_smc)
out_smc
biips_diagnosis(out_smc)
biips_summary(out_smc)

#' Manipulate `smcarray.fsb` object
is.smcarray.fsb(out_smc$x)
names(out_smc$x)
out_smc$x
biips_diagnosis(out_smc$x)
summ_smc_x <- biips_summary(out_smc$x, order = 2, probs = c(.025, .975))
summ_smc_x
dens_smc_x <- biips_density(out_smc$x, bw = 'nrd0', adjust = 1, n = 100)
par(mfrow = c(2, 2))
plot(dens_smc_x)

is.smcarray.fsb(out_smc[['c[2:10]']])
names(out_smc[['c[2:10]']])
out_smc[['c[2:10]']]
biips_diagnosis(out_smc[['c[2:10]']])
summ_smc_c <- biips_summary(out_smc[['c[2:10]']])
summ_smc_c
table_smc_c <- biips_table(out_smc[['c[2:10]']])
par(mfrow = c(2, 2))
plot(table_smc_c)

#' Manipulate `smcarray` object
is.smcarray(out_smc$x$f)
names(out_smc$x$f)
out_smc$x$f
out_smc$x$s
biips_diagnosis(out_smc$x$f)
biips_diagnosis(out_smc$x$s)
biips_summary(out_smc$x$f)
biips_summary(out_smc$x$s)
par(mfrow = c(2, 2))
plot(biips_density(out_smc$x$f))
par(mfrow = c(2, 2))
plot(biips_density(out_smc$x$s))

par(mfrow = c(2, 2))
plot(biips_table(out_smc[['c[2:10]']]$f))
par(mfrow = c(2, 2))
plot(biips_table(out_smc[['c[2:10]']]$s))

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