sample_fSAN {SANple} | R Documentation |
Sample fSAN
Description
sample_fSAN
is used to perform posterior inference under the finite shared atoms nested (fSAN) model with Gaussian likelihood (originally proposed in D'Angelo et al., 2023).
The model uses Dirichlet mixtures with an unknown number of components (following the specification of Frühwirth-Schnatter et al., 2021) at both the observational and distributional level.
Usage
sample_fSAN(nrep, burn, y, group,
maxK = 50, maxL = 50,
m0 = 0, tau0 = 0.1, lambda0 = 3, gamma0 = 2,
hyp_alpha1 = 6, hyp_alpha2 = 3,
hyp_beta1 = 6, hyp_beta2 = 3,
eps_alpha = NULL, eps_beta = NULL,
alpha = NULL, beta = NULL,
warmstart = TRUE, nclus_start = NULL,
mu_start = NULL, sigma2_start = NULL,
M_start = NULL, S_start = NULL,
alpha_start = NULL, beta_start = NULL,
progress = TRUE, seed = NULL)
Arguments
nrep |
Number of MCMC iterations. |
burn |
Number of discarded iterations. |
y |
Vector of observations. |
group |
Vector of the same length of y indicating the group membership (numeric). |
maxK |
Maximum number of distributional clusters |
maxL |
Maximum number of observational clusters |
m0 , tau0 , lambda0 , gamma0 |
Hyperparameters on |
hyp_alpha1 , hyp_alpha2 , eps_alpha |
If a random |
hyp_beta1 , hyp_beta2 , eps_beta |
If a random |
alpha |
Distributional Dirichlet parameter if fixed (optional). The distribution is Dirichlet( |
beta |
Observational Dirichlet parameter if fixed (optional). The distribution is Dirichlet( |
warmstart , nclus_start |
Initialization of the observational clustering.
|
mu_start , sigma2_start , M_start , S_start , alpha_start , beta_start |
Starting points of the MCMC chains (optional).
|
progress |
show a progress bar? (logical, default TRUE.) |
seed |
set a fixed seed. |
Details
Data structure
The finite common atoms mixture model is used to perform inference in nested settings, where the data are organized into groups.
The data should be continuous observations
, where each
contains the
observations from group
, for
.
The function takes as input the data as a numeric vector
y
in this concatenated form. Hence y
should be a vector of length
. The
group
parameter is a numeric vector of the same size as y
indicating the group membership for each
individual observation.
Notice that with this specification the observations in the same group need not be contiguous as long as the correspondence between the variables
y
and group
is maintained.
Model
The data are modeled using a univariate Gaussian likelihood, where both the mean and the variance are observational-cluster-specific, i.e.,
where is the observational cluster indicator of observation
in group
.
The prior on the model parameters is a Normal-Inverse-Gamma distribution
,
i.e.,
,
(shape, rate).
Clustering
The model performs a clustering of both observations and groups.
The clustering of groups (distributional clustering) is provided by the allocation variables , with
The distribution of the probabilities is .
Moreover, the dimension
is random (see Frühwirth-Schnatter et al., 2021).
The clustering of observations (observational clustering) is provided by the allocation variables , with
The distribution of the probabilities is for all
.
Moreover, the dimension
is random (see Frühwirth-Schnatter et al., 2021).
Value
sample_fSAN
returns four objects:
-
model
: name of the fitted model. -
params
: list containing the data and the parameters used in the simulation. Details below. -
sim
: list containing the simulated values (MCMC chains). Details below. -
time
: total computation time.
Data and parameters:
params
is a list with the following components:
nrep
Number of MCMC iterations.
y, group
Data and group vectors.
maxK, maxL
Maximum number of distributional and observational clusters.
m0, tau0, lambda0, gamma0
Model hyperparameters.
- (
hyp_alpha1, hyp_alpha2, eps_alpha
) oralpha
Either the hyperparameters on
and MH step size (if
random), or the value for
(if fixed).
- (
hyp_beta1, hyp_beta2, eps_beta
) orbeta
Either the hyperparameters on
and MH step size (if
random), or the value for
(if fixed).
Simulated values:
sim
is a list with the following components:
mu
Matrix of size (
nrep
,maxL
). Each row is a posterior sample of the mean parameter for each observational cluster.
sigma2
Matrix of size (
nrep
,maxL
). Each row is a posterior sample of the variance parameter for each observational cluster.
obs_cluster
Matrix of size (
nrep
, n), with n =length(y)
. Each row is a posterior sample of the observational cluster allocation variables.
distr_cluster
Matrix of size (
nrep
, J), with J =length(unique(group))
. Each row is a posterior sample of the distributional cluster allocation variables.
pi
Matrix of size (
nrep
,maxK
). Each row is a posterior sample of the distributional cluster probabilities.
omega
3-d array of size (
maxL
,maxK
,nrep
). Each slice is a posterior sample of the observational cluster probabilities. In each slice, each columnis a vector (of length
maxL
) observational cluster probabilitiesfor distributional cluster
.
alpha
Vector of length
nrep
of posterior samples of the parameter.
beta
Vector of length
nrep
of posterior samples of the parameter.
K_plus
Vector of length
nrep
of posterior samples of the number of distributional clusters.L_plus
Vector of length
nrep
of posterior samples of the number of observational clusters.K
Vector of length
nrep
of posterior samples of the distributional Dirichlet dimension.L
Vector of length
nrep
of posterior samples of the observational Dirichlet dimension.
References
D’Angelo, L., Canale, A., Yu, Z., and Guindani, M. (2023). Bayesian nonparametric analysis for the detection of spikes in noisy calcium imaging data. Biometrics, 79(2), 1370–1382. <doi:10.1111/biom.13626>
Frühwirth-Schnatter, S., Malsiner-Walli, G. and Grün, B. (2021). Generalized mixtures of finite mixtures and telescoping sampling. Bayesian Analysis, 16(4), 1279–1307. <doi:10.1214/21-BA1294>
Examples
set.seed(123)
y <- c(rnorm(40,0,0.3), rnorm(20,5,0.3))
g <- c(rep(1,30), rep(2, 30))
plot(density(y[g==1]), xlim = c(-5,10))
lines(density(y[g==2]), col = 2)
out <- sample_fSAN(nrep = 500, burn = 200,
y = y, group = g,
nclus_start = 2,
maxK = 20, maxL = 20,
alpha = 1, beta = 1)
out