duos_stat: Statistics for 'duos'

Description Usage Arguments Details Value Examples

Description

Calculates a variety of statistics from the duos density estimate.

Usage

1
duos_stat(duos_output, stat = "m", p = NA, burnin = NA)

Arguments

duos_output

The list returned by duos containing the density estimate results.

stat

A value indicating choice of statistic (see details).

p

A list of quantiles if quantiles are requested (see details).

burnin

The desired burnin to discard from the results. If no value is entered, the default is half the number of iterations.

print

By default, the posterior mean values and their credible intervals are printed. Change to FALSE if no printing is desired.

Details

The form of the density is below:

f(x) =

(π_1) / (γ_1) , 0 ≤ x < γ_1

(π_2) / (γ_2-γ_1) , γ_1 ≤ x < γ_2

(π_3) / (γ_3-γ_2) , γ_2 ≤ x < γ_3

... , ... ≤ x < ...

(π_k) / (γ_k-γ_{k-1}) , γ_{k-1} ≤ x < γ_k

(π_{k+1}) / (1-γ_k) , γ_k ≤ x < 1

where γ_1 < γ_2 < ... < γ_k is in (0,1) and π_1 + π_2 + ... + π_{k+1} = 1

E[X] = ∑_{i=1}^{k+1} ((γ_i+γ_{i-1}) * π_i) / 2

Var[X] = ∑_{i=1}^{k+1} ((γ_i^3-γ_{i-1}^3) / 3) * π_i / (γ_i-γ_{i-1}) - (E[x])^2

The inverse CDF is specified below:

F^{-1}(x) =

x * (γ_1) / (π_1) , 0 ≤ x < π_1

(x - π_1) * (γ_2 - γ_1) / (π_2) + γ_1 , π_1 ≤ x < π_1 + π_2

(x - π_1 + π_2) * (γ_3-γ_2) / (π_3) + γ_2 , π_1 + π_2 ≤ x < π_1 + π_2 + π_3

... , ... ≤ x < ...

(x - ∑_{i=1}^{k-1} π_i) * (γ_k - γ_{k-1}) / (π_k) + γ_{k-1} , ∑_{i=1}^{k-1} π_i ≤ x < ∑_{i=1}^{k} π_i

(x - ∑_{i=1}^{k} π_i) * (1 - γ_{k}) / (π_{k+1}) + γ_{k} , ∑_{i=1}^{k} π_i ≤ x < 1

Options for stat

Several of the standard statistics are available through the function duos_stat.

Options for p

Default is NA if quantiles are not the desired statistics. If 'quant' is specified for stat, p is a single value or vector of values between 0 and 1.

Value

duos_stat the statistic of choice and the credible intervals associated with it.

If 'mean' or 'm' is specified for stat:

mean

The E[X] from the details is calculated at each iteration and the mean of these is returned.

cri

The credible intervals for E[X] calculated using the 0.025th and 0.975th quantiles.

If 'var' or 'v' is specified for stat:

variance

The Var[X] from the details is calculated at each iteration and the mean of these is returned.

cri

The credible intervals for Var[X] calculated using the 0.025th and 0.975th quantiles.

If 'quant' or 'q' is specified for stat:

quantiles

The quantiles specified in 'p' is calculated using the inverse CDF in the details at each iteration and the mean of these is returned.

cri

The credible intervals for the quantiles calculated using the 0.025th and 0.975th quantiles.

duos_pdf returns a list of the PDF results from duos.

"mean", "var", or "quantiles"

Contains the mean, the variance, or a vector of the quantile values from duos_stat.

cri

Contains the credible intervals for the requested statistics.

mat

Contains a matrix of the posterior simulations for the requested statistic.

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
## --------------------------------------------------------------------------------
## Beta Distribution
## --------------------------------------------------------------------------------

# First run 'duos' on data sampled from a Beta(2, 6) distribution with 100 data points.
y <- rbeta(100, 2, 6)
duos_beta <- duos(y = y, k = 5, MH_N = 20000)

# Get an estimate of the mean and its credible intervals
beta_mean <- duos_stat(duos_beta, stat = "mean")

#Look at a histogram of the posterior simulations of the mean
hist(beta_mean$mat)

# Get an estimate of the variance and its credible intervals
beta_var <- duos_stat(duos_beta, stat = "var")

## --------------------------------------------------------------------------------
## Normal Distribution
## --------------------------------------------------------------------------------

# First run 'duos' on data sampled from a Normal(0, 1) distribution with 200 data points.
y <- rnorm(200, 0, 1)
duos_norm <- duos(y = y, k = 7, MH_N = 20000)

# Get an estimate of the mean and credible intervals
mean_norm <- duos_stat(duos_norm, stat = "m")

#Get an estimate of the quantiles and their credible intervals
quant_norm <- duos_stat(duos_norm, stat = "q", p = c(0.1, 0.5, 0.9))

reykp/biRd documentation built on May 17, 2019, 8:16 p.m.