Description Usage Arguments Details Value Examples
Calculates a variety of statistics from the duos
density estimate.
1 |
duos_output |
The list returned by |
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. |
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
.
"mean" or "m"
: The E[x] is calculated as in the details section for each iteration, and the average of this result is returned as the mean.
"var" or "v"
: The Var[x] is calculated as in the details section for each iteration, and the average of this result is returned as the variance.
"quant" or "q"
: Returns the quantiles specified in 'p' using the inverse CDF described in the details section.
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.
duos_stat
the statistic of choice and the credible intervals associated with it.
If 'mean' or 'm' is specified for stat
:
|
The E[X] from the details is calculated at each iteration and the mean of these is returned. |
|
The credible intervals for E[X] calculated using the 0.025th and 0.975th quantiles. |
If 'var' or 'v' is specified for stat
:
|
The Var[X] from the details is calculated at each iteration and the mean of these is returned. |
|
The credible intervals for Var[X] calculated using the 0.025th and 0.975th quantiles. |
If 'quant' or 'q' is specified for stat
:
|
The quantiles specified in 'p' is calculated using the inverse CDF in the details at each iteration and the mean of these is returned. |
|
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
.
|
Contains the mean, the variance, or a vector of the quantile values from |
|
Contains the credible intervals for the requested statistics. |
|
Contains a matrix of the posterior simulations for the requested statistic. |
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))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.