Title: | Bayesian Nonparametric Mixture Models |
---|---|
Description: | Functions to perform Bayesian nonparametric univariate and multivariate density estimation and clustering, by means of Pitman-Yor mixtures, and dependent Dirichlet process mixtures for partially exchangeable data. See Corradin et al. (2021) <doi:10.18637/jss.v100.i15> for more details. |
Authors: | Riccardo Corradin [aut, cre], Antonio Canale [ctb], Bernardo Nipoti [ctb] |
Maintainer: | Riccardo Corradin <[email protected]> |
License: | LGPL-3 | file LICENSE |
Version: | 1.0.2 |
Built: | 2024-10-31 06:59:45 UTC |
Source: | CRAN |
A constructor for the BNPdens
class. The class BNPdens
is a named list containing
the output generated by a specified Bayesian nonparametric mixture model implemented by means of
a specified MCMC strategy, as in PYdensity
, DDPdensity
, and PYregression
.
BNPdens( density = NULL, data = NULL, grideval = NULL, grid_x = NULL, grid_y = NULL, clust = NULL, mean = NULL, beta = NULL, sigma2 = NULL, probs = NULL, niter = NULL, nburn = NULL, tot_time = NULL, univariate = TRUE, regression = FALSE, dep = FALSE, group_log = NULL, group = NULL, wvals = NULL )
BNPdens( density = NULL, data = NULL, grideval = NULL, grid_x = NULL, grid_y = NULL, clust = NULL, mean = NULL, beta = NULL, sigma2 = NULL, probs = NULL, niter = NULL, nburn = NULL, tot_time = NULL, univariate = TRUE, regression = FALSE, dep = FALSE, group_log = NULL, group = NULL, wvals = NULL )
density |
a matrix containing the values taken by the density at the grid points; |
data |
a dataset; |
grideval |
a set of values where to evaluate the density; |
grid_x |
regression grid, independent variable; |
grid_y |
regression grid, dependent variable; |
clust |
a ( |
mean |
values for the location parameters; |
beta |
coefficients for regression model (only for |
sigma2 |
values of the scale parameters; |
probs |
values for the mixture weights; |
niter |
number of MCMC iterations; |
nburn |
number of MCMC iterations to discard as burn-in; |
tot_time |
total execution time; |
univariate |
logical, |
regression |
logical, |
dep |
logical, |
group_log |
group allocation for each iteration (only for |
group |
vector, allocation of observations to strata (only for |
wvals |
values of the processes weights (only for |
data_toy <- c(rnorm(100, -3, 1), rnorm(100, 3, 1)) grid <- seq(-7, 7, length.out = 50) est_model <- PYdensity(y = data_toy, mcmc = list(niter = 100, nburn = 10, nupd = 100), output = list(grid = grid)) str(est_model) class(est_model)
data_toy <- c(rnorm(100, -3, 1), rnorm(100, 3, 1)) grid <- seq(-7, 7, length.out = 50) est_model <- PYdensity(y = data_toy, mcmc = list(niter = 100, nburn = 10, nupd = 100), output = list(grid = grid)) str(est_model) class(est_model)
The method BNPdens2coda
converts a BNPdens
object into a coda
mcmc object.
## S3 method for class 'BNPdens' BNPdens2coda(object, dens = FALSE)
## S3 method for class 'BNPdens' BNPdens2coda(object, dens = FALSE)
object |
a BNPdens object; |
dens |
logical, it can be TRUE only for models estimated with |
an mcmc object
data_toy <- cbind(c(rnorm(100, -3, 1), rnorm(100, 3, 1)), c(rnorm(100, -3, 1), rnorm(100, 3, 1))) grid <- expand.grid(seq(-7, 7, length.out = 50), seq(-7, 7, length.out = 50)) est_model <- PYdensity(y = data_toy, mcmc = list(niter = 200, nburn = 100), output = list(grid = grid)) coda_mcmc <- BNPdens2coda(est_model) class(coda_mcmc)
data_toy <- cbind(c(rnorm(100, -3, 1), rnorm(100, 3, 1)), c(rnorm(100, -3, 1), rnorm(100, 3, 1))) grid <- expand.grid(seq(-7, 7, length.out = 50), seq(-7, 7, length.out = 50)) est_model <- PYdensity(y = data_toy, mcmc = list(niter = 200, nburn = 100), output = list(grid = grid)) coda_mcmc <- BNPdens2coda(est_model) class(coda_mcmc)
A constructor for the BNPpart
class. The class BNPpart
is a named list containing
the output of partition estimation methods.
BNPpart(partitions = NULL, scores = NULL, psm = NULL)
BNPpart(partitions = NULL, scores = NULL, psm = NULL)
partitions |
a matrix, each row is a visited partition; |
scores |
a vector, each value is the score of a visited partition; |
psm |
a matrix, posterior similarity matrix. |
data_toy <- c(rnorm(100, -3, 1), rnorm(100, 3, 1)) grid <- seq(-7, 7, length.out = 50) est_model <- PYdensity(y = data_toy, mcmc = list(niter = 100, nburn = 10, nupd = 100), output = list(grid = grid)) part <- partition(est_model) class(part)
data_toy <- c(rnorm(100, -3, 1), rnorm(100, 3, 1)) grid <- seq(-7, 7, length.out = 50) est_model <- PYdensity(y = data_toy, mcmc = list(niter = 100, nburn = 10, nupd = 100), output = list(grid = grid)) part <- partition(est_model) class(part)
The method dBNPdens
provides an approximated evaluation of estimated univariate densities at a given point, for a BNPdens
class object.
## S3 method for class 'BNPdens' dBNPdens(object, x)
## S3 method for class 'BNPdens' dBNPdens(object, x)
object |
a |
x |
the point where to evaluate the density. |
a numeric value
data_toy <- c(rnorm(100, -3, 1), rnorm(100, 3, 1)) grid <- seq(-7, 7, length.out = 50) est_model <- PYdensity(y = data_toy, mcmc = list(niter = 200, nburn = 100), output = list(grid = grid)) x <- 1.4 dBNPdens(est_model, x)
data_toy <- c(rnorm(100, -3, 1), rnorm(100, 3, 1)) grid <- seq(-7, 7, length.out = 50) est_model <- PYdensity(y = data_toy, mcmc = list(niter = 200, nburn = 100), output = list(grid = grid)) x <- 1.4 dBNPdens(est_model, x)
The DDPdensity
function generates posterior density samples for a univariate Griffiths-Milne dependent Dirichlet process mixture model with Gaussian
kernel, for partially exchangeable data. The function implements the importance conditional sampler method.
DDPdensity(y, group, mcmc = list(), prior = list(), output = list())
DDPdensity(y, group, mcmc = list(), prior = list(), output = list())
y |
a vector or matrix giving the data based on which densities are to be estimated; |
group |
vector of length |
mcmc |
list of MCMC arguments:
|
prior |
a list giving the prior information, which contains:
|
output |
a list of arguments for generating posterior output. It contains:
|
This function fits a Griffiths-Milne dependent Dirichlet process (GM-DDP) mixture
for density estimation for partially exchangeable data (Lijoi et al., 2014).
For each observation the group
variable allows the observations to be gathered
into =
length(unique(group))
distinct groups.
The model assumes exchangeability within each group, with observations in the th group marginally
modelled by a location-scale Dirichlet process mixtures, i.e.
where each is a Dirichlet process with total mass
strength
and base measure .
The vector
is assumed to be jointly distributed as a vector of
GM-DDP(
strength
, wei
; ), where
strength
and
are the total mass parameter and the base measure of each
, and
wei
controls the dependence across the components of
. Admissible values for
wei
are in , with the two extremes of the range
corresponding to full exchangeability (
wei
)
and independence across groups (
wei
).
is a normal-inverse gamma base measure, i.e.
Posterior sampling is obtained by implementing the importance conditional sampler (Canale et al., 2019). See Corradin et al. (to appear) for more details.
A BNPdensity
class object containing the estimated densities for each iteration,
the allocations for each iteration; the grid used to evaluate the densities (for each group); the
densities sampled from the posterior distribution (for each group); the groups; the weights of the processes.
The function returns also informations regarding the estimation: the number of iterations, the number
of burn-in iterations and the execution time.
Lijoi, A., Nipoti, B., and Pruenster, I. (2014). Bayesian inference with dependent normalized completely random measures. Bernoulli 20, 1260–1291, doi:10.3150/13-BEJ521
Canale, A., Corradin, R., & Nipoti, B. (2019). Importance conditional sampling for Bayesian nonparametric mixtures. arXiv preprint arXiv:1906.08147
Corradin, R., Canale, A., Nipoti, B. (2021), BNPmix: An R Package for Bayesian Nonparametric Modeling via Pitman-Yor Mixtures, Journal of Statistical Software, doi:10.18637/jss.v100.i15
data_toy <- c(rnorm(50, -4, 1), rnorm(100, 0, 1), rnorm(50, 4, 1)) group_toy <- c(rep(1,100), rep(2,100)) grid <- seq(-7, 7, length.out = 50) est_model <- DDPdensity(y = data_toy, group = group_toy, mcmc = list(niter = 200, nburn = 100, var_MH_step = 0.25), output = list(grid = grid)) summary(est_model) plot(est_model)
data_toy <- c(rnorm(50, -4, 1), rnorm(100, 0, 1), rnorm(50, 4, 1)) group_toy <- c(rep(1,100), rep(2,100)) grid <- seq(-7, 7, length.out = 50) est_model <- DDPdensity(y = data_toy, group = group_toy, mcmc = list(niter = 200, nburn = 100, var_MH_step = 0.25), output = list(grid = grid)) summary(est_model) plot(est_model)
The partition
method estimates the partition of the data based on the output generated by a Bayesian nonparametric mixture
model, according to a specified criterion, for a BNPdens
class object.
## S3 method for class 'BNPdens' partition(object, dist = "VI", max_k = NULL, ...)
## S3 method for class 'BNPdens' partition(object, dist = "VI", max_k = NULL, ...)
object |
an object of class |
dist |
a loss function defined on the space of partitions;
it can be variation of information ( |
max_k |
maximum number of clusters passed to the |
... |
additional arguments to be passed. |
This method returns point estimates for the clustering of the data induced by a nonparametric mixture model.
This result is achieved exploiting two different loss fuctions on the space of partitions: variation of information
(dist = 'VI'
) and Binder's loss (dist = 'Binder'
). The function is based on the mcclust.ext
code by Sara Wade (Wade and Ghahramani, 2018).
The method returns a list containing a matrix with nrow(data)
columns and 3 rows. Each row reports
the cluster labels for each observation according to three different approaches, one per row. The first and second rows
are the output of an agglomerative clustering procedure obtained by applying the function hclust
to the dissimilarity matrix, and by using the complete or average linkage,
respectively. The number of clusters is between 1 and max_k
and is choosen according to a lower bound
on the expected loss, as described in Wade and Ghahramani (2018).
The third row reports the partition visited by the MCMC with the minimum distance dist
from the dissimilarity matrix.
In addition, the list reports a vector with three scores representing the lower bound on the expected loss for the three partitions.
Wade, S., Ghahramani, Z. (2018). Bayesian cluster analysis: Point estimation and credible balls. Bayesian Analysis, 13, 559-626.
data_toy <- c(rnorm(10, -3, 1), rnorm(10, 3, 1)) grid <- seq(-7, 7, length.out = 50) fit <- PYdensity(y = data_toy, mcmc = list(niter = 100, nburn = 10, nupd = 100), output = list(grid = grid)) class(fit) partition(fit)
data_toy <- c(rnorm(10, -3, 1), rnorm(10, 3, 1)) grid <- seq(-7, 7, length.out = 50) fit <- PYdensity(y = data_toy, mcmc = list(niter = 100, nburn = 10, nupd = 100), output = list(grid = grid)) class(fit) partition(fit)
Extension of the plot
method to the BNPdens
class. The method plot.BNPdens
returns suitable plots for a BNPdens
object. See details.
## S3 method for class 'BNPdens' plot( x, dimension = c(1, 2), col = "#0037c4", show_points = F, show_hist = F, show_clust = F, bin_size = NULL, wrap_dim = NULL, xlab = "", ylab = "", band = T, conf_level = c(0.025, 0.975), ... )
## S3 method for class 'BNPdens' plot( x, dimension = c(1, 2), col = "#0037c4", show_points = F, show_hist = F, show_clust = F, bin_size = NULL, wrap_dim = NULL, xlab = "", ylab = "", band = T, conf_level = c(0.025, 0.975), ... )
x |
an object of class |
dimension |
if |
col |
the color of the lines; |
show_points |
if |
show_hist |
if |
show_clust |
if |
bin_size |
if |
wrap_dim |
bivariate vector, if |
xlab |
label of the horizontal axis; |
ylab |
label of the vertical axis; |
band |
if |
conf_level |
bivariate vector, order of the quantiles for the posterior credible bands. Default |
... |
additional arguments to be passed. |
If the BNPdens
object is generated by PYdensity
, the function returns
the univariate or bivariate estimated density plot.
If the BNPdens
object is generated by PYregression
, the function returns
the scatterplot of the response variable jointly with the covariates (up to four), coloured according to the estimated partition.
up to four covariates.
If x
is a BNPdens
object generated by DDPdensity
, the function returns
a wrapped plot with one density per group.
The plots can be enhanced in several ways: for univariate densities, if show_hist = TRUE
,
the plot shows also the histogram of the data; if show_points = TRUE
,
the plot shows also the observed points along the
x-axis; if show_points = TRUE
and show_clust = TRUE
, the points are colored
according to the partition estimated with the partition
function.
For multivariate densities: if show_points = TRUE
,
the plot shows also the scatterplot of the data;
if show_points = TRUE
and show_clust = TRUE
,
the points are colored according to the estimated partition.
A ggplot2
object.
# PYdensity example data_toy <- c(rnorm(100, -3, 1), rnorm(100, 3, 1)) grid <- seq(-7, 7, length.out = 50) est_model <- PYdensity(y = data_toy, mcmc = list(niter = 200, nburn = 100, nupd = 100), output = list(grid = grid)) class(est_model) plot(est_model) # PYregression example x_toy <- c(rnorm(100, 3, 1), rnorm(100, 3, 1)) y_toy <- c(x_toy[1:100] * 2 + 1, x_toy[101:200] * 6 + 1) + rnorm(200, 0, 1) grid_x <- c(0, 1, 2, 3, 4, 5) grid_y <- seq(0, 35, length.out = 50) est_model <- PYregression(y = y_toy, x = x_toy, mcmc = list(niter = 200, nburn = 100), output = list(grid_x = grid_x, grid_y = grid_y)) summary(est_model) plot(est_model) # DDPdensity example data_toy <- c(rnorm(50, -4, 1), rnorm(100, 0, 1), rnorm(50, 4, 1)) group_toy <- c(rep(1,100), rep(2,100)) grid <- seq(-7, 7, length.out = 50) est_model <- DDPdensity(y = data_toy, group = group_toy, mcmc = list(niter = 200, nburn = 100, napprox_unif = 50), output = list(grid = grid)) summary(est_model) plot(est_model)
# PYdensity example data_toy <- c(rnorm(100, -3, 1), rnorm(100, 3, 1)) grid <- seq(-7, 7, length.out = 50) est_model <- PYdensity(y = data_toy, mcmc = list(niter = 200, nburn = 100, nupd = 100), output = list(grid = grid)) class(est_model) plot(est_model) # PYregression example x_toy <- c(rnorm(100, 3, 1), rnorm(100, 3, 1)) y_toy <- c(x_toy[1:100] * 2 + 1, x_toy[101:200] * 6 + 1) + rnorm(200, 0, 1) grid_x <- c(0, 1, 2, 3, 4, 5) grid_y <- seq(0, 35, length.out = 50) est_model <- PYregression(y = y_toy, x = x_toy, mcmc = list(niter = 200, nburn = 100), output = list(grid_x = grid_x, grid_y = grid_y)) summary(est_model) plot(est_model) # DDPdensity example data_toy <- c(rnorm(50, -4, 1), rnorm(100, 0, 1), rnorm(50, 4, 1)) group_toy <- c(rep(1,100), rep(2,100)) grid <- seq(-7, 7, length.out = 50) est_model <- DDPdensity(y = data_toy, group = group_toy, mcmc = list(niter = 200, nburn = 100, napprox_unif = 50), output = list(grid = grid)) summary(est_model) plot(est_model)
The BNPdens
method prints the type of a BNPdens
object.
## S3 method for class 'BNPdens' print(x, ...)
## S3 method for class 'BNPdens' print(x, ...)
x |
an object of class |
... |
additional arguments. |
data_toy <- c(rnorm(100, -3, 1), rnorm(100, 3, 1)) grid <- seq(-7, 7, length.out = 50) est_model <- PYdensity(y = data_toy, mcmc = list(niter = 100, nburn = 10, napprox = 10), output = list(grid = grid)) class(est_model) print(est_model)
data_toy <- c(rnorm(100, -3, 1), rnorm(100, 3, 1)) grid <- seq(-7, 7, length.out = 50) est_model <- PYdensity(y = data_toy, mcmc = list(niter = 100, nburn = 10, napprox = 10), output = list(grid = grid)) class(est_model) print(est_model)
The function PYcalibrate
elicits the strength parameter of the Pitman-Yor
process, given the discount parameter and the prior expected number of clusters.
PYcalibrate(Ek, n, discount = 0)
PYcalibrate(Ek, n, discount = 0)
Ek |
prior expected number of cluster; |
n |
sample size; |
discount |
discount parameter; default is set equal to 0, corresponding to a Dirichlet process prior. |
A named list containingtthe values of strength and discount parameters.
PYcalibrate(5, 100) PYcalibrate(5, 100, 0.5)
PYcalibrate(5, 100) PYcalibrate(5, 100, 0.5)
The PYdensity
function generates a posterior density sample for a selection of univariate and multivariate Pitman-Yor
process mixture models with Gaussian kernels. See details below for the description of the different specifications of the implemented models.
PYdensity(y, mcmc = list(), prior = list(), output = list())
PYdensity(y, mcmc = list(), prior = list(), output = list())
y |
a vector or matrix giving the data based on which the density is to be estimated; |
mcmc |
a list of MCMC arguments:
|
prior |
a list giving the prior information. The list includes
|
output |
a list of arguments for generating posterior output. It contains:
|
This generic function fits a Pitman-Yor process mixture model for density estimation and clustering. The general model is
where is a kernel density with parameter
. Univariate and multivariate Gaussian kernels are implemented with different specifications for the parametric space
, as described below.
The mixing measure
has a Pitman-Yor process prior with strength parameter
,
discount parameter
, and base measure
admitting the specifications presented below. For posterior sampling,
three MCMC approaches are implemented. See details below.
Univariate data
For univariate the function implements both a location and location-scale mixture model. The former assumes
where
is a univariate Gaussian kernel function with mean
and variance
,
and
is an inverse gamma prior. The base measure is specified as
and .
Optional hyperpriors for the base measure's parameters are
The location-scale mixture model, instead, assumes
with normal-inverse gamma base measure
and (optional) hyperpriors
Multivariate data
For multivariate (
-variate) the function implements a location mixture model (with full covariance matrix) and two
different location-scale mixture models, with either full or diagonal covariance matrix. The location mixture model assumes
where
is a
-dimensional Gaussian kernel function with mean vector
and covariance matrix
. The prior on
is inverse Whishart with parameters
and
, while the
base measure is
with optional hyperpriors
The location-scale mixture model assumes
Two possible structures for
are implemented, namely full and diagonal covariance. For the full covariance mixture model, the base measure is
the normal-inverse Wishart
with optional hyperpriors
The second location-scale mixture model assumes a diagonal covariance structure. This is equivalent to write the mixture model as a mixture of products of univariate normal kernels, i.e.
For this specification, the base measure is assumed defined as the product of independent normal-inverse gamma distributions, that is
where
Optional hyperpriors can be added, and, for each component, correspond to the set of hyperpriors considered for the univariate location-scale mixture model.
Posterior simulation methods
This generic function implements three types of MCMC algorithms for posterior simulation.
The default method is the importance conditional sampler 'ICS'
(Canale et al. 2019). Other options are
the marginal sampler 'MAR'
(Neal, 2000) and the slice sampler 'SLI'
(Kalli et al. 2011).
The importance conditional sampler performs an importance sampling step when updating the values of
individual parameters , which requires to sample
m_imp
values from a suitable
proposal. Large values of m_imp
are known to improve the mixing of the chain
at the cost of increased running time (Canale et al. 2019). Two options are available for the slice sampler,
namely the dependent slice-efficient sampler (slice_type = 'DEP'
), which is set as default, and the
independent slice-efficient sampler (slice_type = 'INDEP'
) (Kalli et al. 2011). See Corradin et al. (to appear)
for more details.
A BNPdens
class object containing the estimated density and
the cluster allocations for each iterations. If out_param = TRUE
the output
contains also the kernel specific parameters for each iteration. If mcmc_dens = TRUE
the output
contains also a realization from the posterior density for each iteration. IF mean_dens = TRUE
the output contains just the mean of the realizations from the posterior density. The output contains
also informations as the number of iterations, the number of burn-in iterations, the used
computational time and the type of estimated model (univariate = TRUE
or FALSE
).
Canale, A., Corradin, R., Nipoti, B. (2019), Importance conditional sampling for Bayesian nonparametric mixtures, arXiv preprint, arXiv:1906.08147
Corradin, R., Canale, A., Nipoti, B. (2021), BNPmix: An R Package for Bayesian Nonparametric Modeling via Pitman-Yor Mixtures, Journal of Statistical Software, 100, doi:10.18637/jss.v100.i15
Kalli, M., Griffin, J. E., and Walker, S. G. (2011), Slice sampling mixture models. Statistics and Computing 21, 93-105, doi:10.1007/s11222-009-9150-y
Neal, R. M. (2000), Markov Chain Sampling Methods for Dirichlet Process Mixture Models, Journal of Computational and Graphical Statistics 9, 249-265, doi:10.2307/1390653
data_toy <- cbind(c(rnorm(100, -3, 1), rnorm(100, 3, 1)), c(rnorm(100, -3, 1), rnorm(100, 3, 1))) grid <- expand.grid(seq(-7, 7, length.out = 50), seq(-7, 7, length.out = 50)) est_model <- PYdensity(y = data_toy, mcmc = list(niter = 200, nburn = 100), output = list(grid = grid)) summary(est_model) plot(est_model)
data_toy <- cbind(c(rnorm(100, -3, 1), rnorm(100, 3, 1)), c(rnorm(100, -3, 1), rnorm(100, 3, 1))) grid <- expand.grid(seq(-7, 7, length.out = 50), seq(-7, 7, length.out = 50)) est_model <- PYdensity(y = data_toy, mcmc = list(niter = 200, nburn = 100), output = list(grid = grid)) summary(est_model) plot(est_model)
The PYregression
function generates a posterior sample
for mixtures of linear regression models inspired by the ANOVA-DDP model
introduced in De Iorio et al. (2004). See details below for model specification.
PYregression(y, x, mcmc = list(), prior = list(), output = list())
PYregression(y, x, mcmc = list(), prior = list(), output = list())
y |
a vector of observations, univariate dependent variable; |
x |
a matrix of observations, multivariate independent variable; |
mcmc |
a list of MCMC arguments:
|
prior |
a list giving the prior information. The list includes
|
output |
list of posterior summaries:
|
This function fits a Pitman-Yor process mixture of Gaussian linear regression models, i.e
where is a bivariate vector containing the dependent variable in
x
and a value of 1
for the intercept term.
The mixing measure has a Pitman-Yor process prior with strength
,
discount parameter
. The location model assume a base measures
specified as
while the location-scale model assume a base measures specified as
Optional hyperpriors complete the model specification:
Posterior simulation methods
This generic function implements three types of MCMC algorithms for posterior simulation.
The default method is the importance conditional sampler 'ICS'
(Canale et al. 2019). Other options are
the marginal sampler 'MAR'
(algorithm 8 of Neal, 2000) and the slice sampler 'SLI'
(Kalli et al. 2011).
The importance conditional sampler performs an importance sampling step when updating the values of
individual parameters , which requires to sample
m_imp
values from a suitable
proposal. Large values of m_imp
are known to improve the mixing of the posterior distribution
at the cost of increased running time (Canale et al. 2019). When updateing the individual parameter
, Algorithm 8 of Neal, 2000, requires to sample
m_marginal
values from the base
measure. m_marginal
can be chosen arbitrarily. Two options are available for the slice sampler,
namely the dependent slice-efficient sampler (slice_type = 'DEP'
), which is set as default, and the
independent slice-efficient sampler (slice_type = 'INDEP'
) (Kalli et al. 2011). See Corradin et al. (to appear)
for more details.
A BNPdens
class object containing the estimated density and
the cluster allocations for each iterations. The output contains also the data and
the grids. If out_param = TRUE
the output
contains also the kernel specific parameters for each iteration. If mcmc_dens = TRUE
, the
function returns also a realization from the posterior density for each iteration.
If mean_dens = TRUE
, the output contains just the mean of the densities sampled at each iteration.
The output retuns also the number of iterations,
the number of burn-in iterations, the computational time and the type of model.
Canale, A., Corradin, R., Nipoti, B. (2019), Importance conditional sampling for Bayesian nonparametric mixtures, arXiv preprint, arXiv:1906.08147
Corradin, R., Canale, A., Nipoti, B. (2021), BNPmix: An R Package for Bayesian Nonparametric Modeling via Pitman-Yor Mixtures, Journal of Statistical Software, doi:10.18637/jss.v100.i15
De Iorio, M., Mueller, P., Rosner, G.L., and MacEachern, S. (2004), An ANOVA Model for Dependent Random Measures, Journal of the American Statistical Association 99, 205-215, doi:10.1198/016214504000000205
Kalli, M., Griffin, J. E., and Walker, S. G. (2011), Slice sampling mixture models. Statistics and Computing 21, 93-105, doi:10.1007/s11222-009-9150-y
Neal, R. M. (2000), Markov Chain Sampling Methods for Dirichlet Process Mixture Models, Journal of Computational and Graphical Statistics 9, 249-265, doi:10.2307/1390653
x_toy <- c(rnorm(100, 3, 1), rnorm(100, 3, 1)) y_toy <- c(x_toy[1:100] * 2 + 1, x_toy[101:200] * 6 + 1) + rnorm(200, 0, 1) grid_x <- c(0, 1, 2, 3, 4, 5) grid_y <- seq(0, 35, length.out = 50) est_model <- PYregression(y = y_toy, x = x_toy, mcmc = list(niter = 200, nburn = 100), output = list(grid_x = grid_x, grid_y = grid_y)) summary(est_model) plot(est_model)
x_toy <- c(rnorm(100, 3, 1), rnorm(100, 3, 1)) y_toy <- c(x_toy[1:100] * 2 + 1, x_toy[101:200] * 6 + 1) + rnorm(200, 0, 1) grid_x <- c(0, 1, 2, 3, 4, 5) grid_y <- seq(0, 35, length.out = 50) est_model <- PYregression(y = y_toy, x = x_toy, mcmc = list(niter = 200, nburn = 100), output = list(grid_x = grid_x, grid_y = grid_y)) summary(est_model) plot(est_model)
The summary.BNPdens
method provides summary information on BNPdens
objects.
## S3 method for class 'BNPdens' summary(object, ...)
## S3 method for class 'BNPdens' summary(object, ...)
object |
an object of class |
... |
additional arguments |
data_toy <- c(rnorm(100, -3, 1), rnorm(100, 3, 1)) grid <- seq(-7, 7, length.out = 50) est_model <- PYdensity(y = data_toy, mcmc = list(niter = 100, nburn = 10, napprox = 10), output = list(grid = grid)) class(est_model) summary(est_model)
data_toy <- c(rnorm(100, -3, 1), rnorm(100, 3, 1)) grid <- seq(-7, 7, length.out = 50) est_model <- PYdensity(y = data_toy, mcmc = list(niter = 100, nburn = 10, napprox = 10), output = list(grid = grid)) class(est_model) summary(est_model)