Title: | Bayesian Multivariate Receptor Modeling |
---|---|
Description: | Bayesian analysis of multivariate receptor modeling. The package consists of implementations of the methods of Park and Oh (2015) <doi:10.1016/j.chemolab.2015.08.021>.The package uses 'JAGS'(Just Another Gibbs Sampler) to generate Markov chain Monte Carlo samples of parameters. |
Authors: | Man-Suk Oh [aut, cre], Eun-Kyung Lee [aut], Eun Sug Park [aut] |
Maintainer: | Man-Suk Oh <[email protected]> |
License: | GPL (>= 2) |
Version: | 2.4.0 |
Built: | 2024-11-07 06:42:10 UTC |
Source: | CRAN |
Call Shiny to show the results of Bayesian analysis of multivariate receptor modeling in a web-based application. This object contains
plots of the posterior means and 95% posterior intervals of parameters in
an object of class bmrm
.
tables of the posterior means of parameters in
an object of class bmrm
.
tables of the posterior quantiles of parameters in
an object of class bmrm
, for prob=(0.025, 0.05, 0.25, 0.5, 0.75, 0.95, 0.975).
tables of convergence diagnostics of parameters in
an object of class bmrm
.
3-dimensional dynamic principal component plots of data (Y) and
source profiles (rows of the estimated source composition matrix P)
in an object of class bmrm
. The plot can be rotated by moving the cursor.
trace plots and ACF plots of the first 6 elements of a parameter in an
object of class bmrm
.
bayesMRMApp(x)
bayesMRMApp(x)
x |
an object of class |
shiny App
Generate posterior samples of the source
composition matrix P, the source contribution matrix A,
and the error variance using 'JAGS', and computes
estimates of A,P,
.
bmrm(Y, q, muP,errdist="norm", df=4, varP.free=100, xi=NULL, Omega=NULL, a0=0.01, b0=0.01, nAdapt=1000, nBurnIn=5000, nIter=5000, nThin=1, P.init=NULL, A.init=NULL, Sigma.init=NULL,...)
bmrm(Y, q, muP,errdist="norm", df=4, varP.free=100, xi=NULL, Omega=NULL, a0=0.01, b0=0.01, nAdapt=1000, nBurnIn=5000, nIter=5000, nThin=1, P.init=NULL, A.init=NULL, Sigma.init=NULL,...)
Y |
data matrix |
q |
number of sources. It must be a positive integer. |
muP |
(q,ncol(Y))-dimensional prior mean matrix for the source composition matrix P, where q is the number of sources. Zeros need to be assigned to prespecified elements of muP to satisfy the identifiability condition C1. For the remaining free elements, any nonnegative numbers (between 0 and 1 preferably) can be assigned. If no or an insufficient number of zeros are preassigned in muP, estimation can still be performed but the resulting estimates may be subject to rotational ambiguities. (default=0.5 for nonzero elements ). |
errdist |
error distribution: either "norm" for normal distribution or "t" for t distribution (default="norm") |
df |
degrees of freedom of a t-distribution when errdist="t" (default=4) |
varP.free |
scalar value of the prior variance of the free (nonzero) elements of the source composition matrix P (default=100) |
xi |
prior mean vector of the q-dimensional source contribution vector at time t (default=vector of 1's) |
Omega |
diagonal matrix of the prior variance of the q-dimensional source contribution vector at time t (default=identity matrix) |
a0 |
shape parameter of the Inverse Gamma prior of the error variance (default=0.01) |
b0 |
scale parameter of the Inverse Gamma prior of the error variance (default=0.01) |
nAdapt |
number of iterations for adaptation in 'JAGS' (default=1000) |
nBurnIn |
number of iterations for the burn-in period in MCMC (default=5000) |
nIter |
number of iterations for monitoring samples from MCMC
(default=5000). |
nThin |
thinning interval for monitoring samples from MCMC (default=1) |
P.init |
initial value of the source composition matrix P. If omitted, zeros are assigned to the elements corresponding to zero elements in muP and the nonzero elements of P.init will be randomly generated from a uniform distrbution. |
A.init |
initial value of the source contribution matrix A. If omitted, it will be calculated from Y and P.init. |
Sigma.init |
initial value of the error variance. If omitted, it will be calculated from Y, A.init and P.init. |
... |
arguments to be passed to methods |
Model
The basic model for Bayesian multivariate receptor model is as follows:
,
where
is a vector of observations of
variables at time
,
.
is a
source composition
matrix in which the
-th row represents the
-th source
composition profiles,
,
is the number of sources.
is a
dimensional source contribution vector at time
,
.
is an error term
for the
-th observations,
following
or
,
independently for
, where
.
Priors
Prior distribution of is given as
a truncated multivariate normal distribution,
, independently for
.
Prior distribution of (the
-th element of the source
composition matrix
) is given as
, for free (nonzero)
,
, for zero
,
independently for .
Prior distribution of is
, i.e.,
, having mean
,
independently for
.
Notes
We use the prior
that is practically equal
to the point mass at 0 to simplify the model building in 'JAGS'.
The MCMC samples of A and P are post-processed (rescaled) before saving
so that for each
(the identifiablity
condition C3 of Park and Oh (2015).
in bmrm
object
number of sources
number of observations in data Y
number of variables in data Y
observed data matrix
prior mean of the source composition matrix P
error distribution
degrees of freedom when errdist="t"
posterior mean of the source contribution matrix A
posterior mean of the source composition matrix P
posterior mean of the error variance Sigma
posterior standard deviation of the source contribution matrix A
posterior standard deviation of the source composition matrix P
posterior standard deviation of the error variance Sigma
posterior quantlies of A for prob=(0.025, 0.05, 0.25, 0.5, 0.75, 0.95, 0.975)
posterior quantiles of P for prob=(0.025, 0.05, 0.25, 0.5, 0.75, 0.95, 0.975)
posterior quantiles of Sigma for prob=(0.025, 0.05, 0.25, 0.5, 0.75, 0.95, 0.975)
predicted value of Y computed from A.hat*P.hat
Y-Y.hat
MCMC posterior samples of A, P, and in class "mcmc.list"
number of MCMC iterations per chain for monitoring samples from MCMC
number of iterations for the burn-in period in MCMC
thinning interval for monitoring samples from MCMC
Park, E.S. and Oh, M-S. (2015), Robust Bayesian Multivariate Receptor Modeling, Chemometrics and intelligent laboratory systems, 149, 215-226.
Plummer, M. 2003. JAGS: A program for analysis of Bayesian graphical models using Gibbs sampling. Proceedings of the 3rd international workshop on distributed statistical computing, pp. 125. Technische Universit at Wien, Wien, Austria.
Plummer, M. 2015. 'JAGS' Version 4.0.0 user manual.
data(Elpaso); Y=Elpaso$Y ; muP=Elpaso$muP ; q=nrow(muP) out.Elpaso <- bmrm(Y,q,muP) summary(out.Elpaso) plot(out.Elpaso)
data(Elpaso); Y=Elpaso$Y ; muP=Elpaso$muP ; q=nrow(muP) out.Elpaso <- bmrm(Y,q,muP) summary(out.Elpaso) plot(out.Elpaso)
bmrm
Compute convergence diagnostics of Geweke (1992), Heidelberger and Welch (1983), Raftery and Lewis(1992).
convdiag_bmrm(x , var="P", convdiag="geweke",print=TRUE,...)
convdiag_bmrm(x , var="P", convdiag="geweke",print=TRUE,...)
x |
an object of class |
var |
name of a variable to which convergence disagnostics apply. It should be one of "A" (source contribution matrix), "P" (source composition or profile matrix), "Sigma" (error variance). |
convdiag |
vector of convergence diagnostic methods. It should be any subvector of ("geweke", "heidel","raftery" ) (default="geweke"). |
print |
TRUE/FALSE, print convergence diagnostics results (default=TRUE) |
... |
arguments to be passed to methods |
Geweke's convergence diagnostic for Markov chains is based on
a test for equality of the means of the first and last part of a Markov chain
(by default the first 10% and the last 50%).
If the samples are drawn from the stationary distribution of the chain,
the two means should be equal and Geweke's statistic has an asymptotically
standard normal distribution. We use the function geweke.diag
in coda
package (with default option) which provides the test statistics
(standard Z-scores) and the upper bound of
and p-values.
Heidelberger and Welch's convergence diagnostic tests the
null hypothesis that the sampled values come from a stationary distribution.
The test is successively applied, firstly to the whole chain, then after
discarding the first 10%, 20%, ... of the chain until either
the null hypothesis is accepted, or 50% of the chain has been discarded.
We use the function heidel.diag
(with default option)
which provides the staionary test results and p-values.
Raftery and Lewis's diagnostic estimates the minimum number of iterations, burn-in,
thinning interval for zero autocorrelation, satisfying specified conditions
regarding quantile of parameters of interest. The conditions are
specified by a posterior quantile
of parameters, an acceptable
tolerance (accuracy)
for
, a probability
of being
within the interval
.
We use the function
raftery.diag
(with default option).
A list of convergence diagnostics results
selected convergence diagnostic methods
Geweke's z-scores and p-values if convdiag
includes "geweke", NULL if convdiag
does not include "geweke"
Heidelberger and Welch's stationary test results
and p-values if convdiag
includes "heidel"; NULL if
convdiag
does not include "heidel"
Raftery and Lewis's estimates of burn-in, minimum number of iterations,
and thinning if convdiag
includes "raftery"; NULL if
convdiag
does not include "raftery"
Geweke, J.(1992) Evaluating the accuracy of sampling-based approaches to calculating posterior moments. In Bayesian Statistics 4 (ed JM Bernado, JO Berger, AP Dawid and AFM Smith). Clarendon Press.
Heidelberger P, and Welch PD. (1981) A spectral method for confidence interval generation and run length control in simulations. Comm. ACM. 24, 233-245.
Heidelberger P. and Welch PD.(1983) Simulation run length control in the presence of an initial transient. Opns Res., 31, 1109-44,Oxford, UK.
Plummer, M., Best, N., Cowles, K. and Vines K. (2006) CODA: Convergence Diagnosis and Output Analysis for MCMC, R News, Vol 6, pp. 7-11.
Raftery, A.E. and Lewis, S.M. (1992). One long run with diagnostics: Implementation strategies for Markov chain Monte Carlo. Statistical Science, 7, 493-497.
Raftery, A.E. and Lewis, S.M. (1995). The number of iterations, convergence diagnostics and generic Metropolis algorithms. In Practical Markov Chain Monte Carlo (W.R. Gilks, D.J. Spiegelhalter and S. Richardson, eds.). London, U.K.: Chapman and Hall.
data(Elpaso) Y=Elpaso$Y ; muP=Elpaso$muP q=nrow(muP) out.Elpaso <- bmrm(Y,q,muP, nAdapt=1000,nBurnIn=5000,nIter=5000,nThin=1) conv1<-convdiag_bmrm(out.Elpaso,var="P",convdiag="raftery" ) conv2<-convdiag_bmrm(out.Elpaso,var="A", convdiag="geweke") conv3<-convdiag_bmrm(out.Elpaso,var="Sigma", convdiag=c("geweke","heidel")) conv4<-convdiag_bmrm(out.Elpaso,var="Sigma", convdiag=c("geweke","heidel", "raftery"))
data(Elpaso) Y=Elpaso$Y ; muP=Elpaso$muP q=nrow(muP) out.Elpaso <- bmrm(Y,q,muP, nAdapt=1000,nBurnIn=5000,nIter=5000,nThin=1) conv1<-convdiag_bmrm(out.Elpaso,var="P",convdiag="raftery" ) conv2<-convdiag_bmrm(out.Elpaso,var="A", convdiag="geweke") conv3<-convdiag_bmrm(out.Elpaso,var="Sigma", convdiag=c("geweke","heidel")) conv4<-convdiag_bmrm(out.Elpaso,var="Sigma", convdiag=c("geweke","heidel", "raftery"))
The data frame has the following components:
Y 224 by 15 matrix of 224 observations on 15 PM2.5 species. PM 2.5 was measured every three days during the time period of 1/2/2006 ~ 4/7/2009 from the Chamizal station in the city of El Paso, USA. Out of the 58 original PM 2.5 species, 15 species were selected. After removing any observations with missig values, the final data consists of 224 complete observatins on the following 15 PM2.5 species:
Aluminum
Calcium
Chlorine
EC CSN
Iron
Potassium ion
Magnanese
Non-volatile nitrate
Ammonium ion
Sodium
OC CSN unadjusted
Sulfate
Silicon
Titanium
Zinc
muP 4 by 15 matrix of the prior mean of the source composition matrix P for data. Zero values are assigned for some elements of muP to satisfy the identifiability conditions C1-C2 in Park and Oh (2015). The remaining nonzero elements of muP have value 0.5. Note that the number of sources (the number of rows in muP) is presumed to be 4 here.
Park, E.S. and Oh, M-S. (2016), Bayesian Quantile Multivariate Receptor Modeling, Chemometrics and intelligent laboratory systems, 159, 174-180.
data(Elpaso) Y=Elpaso$Y muP=Elpaso$muP
data(Elpaso) Y=Elpaso$Y muP=Elpaso$muP
Check the identifiability conditions C1-C2 of Park and Oh (2015).
idCond_check(P)
idCond_check(P)
P |
source composition matrix in multivariate receptor model |
idCond TRUE if all the conditions are satisfied, FALSE otherwise
Draw principal component plots of data (Y) and source profiles (rows) of the estimated source composition matrix P.hat (and P0 if there is another source composition matrix P0 to compare, e.g., P0 could be the true P in simulation or P0 could be another estimate of P)
pcplot(x, P0, G3D=FALSE,...)
pcplot(x, P0, G3D=FALSE,...)
x |
an object of class |
P0 |
estimated value of P (in simulation it can be the true value of P) |
G3D |
TRUE/FALSE, dynamic 3D plot (default=FALSE) |
... |
arguments to be passed to methods |
plot
data(Elpaso) Y=Elpaso$Y ; muP=Elpaso$muP q=nrow(muP) out.Elpaso <- bmrm(Y,q,muP, nAdapt=1000,nBurnIn=5000,nIter=5000,nThin=1) pcplot(out.Elpaso) pcplot(out.Elpaso,G3D=TRUE)
data(Elpaso) Y=Elpaso$Y ; muP=Elpaso$muP q=nrow(muP) out.Elpaso <- bmrm(Y,q,muP, nAdapt=1000,nBurnIn=5000,nIter=5000,nThin=1) pcplot(out.Elpaso) pcplot(out.Elpaso,G3D=TRUE)
Produce plots of the estimated
posterior mean and 95% posterior intervals of A,P, Sigma
based on the MCMC samples in bmrm
.
## S3 method for class 'bmrm' plot(x, type = "both", ...)
## S3 method for class 'bmrm' plot(x, type = "both", ...)
x |
an object of class |
type |
name of a variable (default="P"). It should be one of "P"(source composition or profile matrix P), "A"(source contribution matrix A), "both" (both P and A), "Sigma" (error variance). |
... |
arguments to be passed to methods |
The following types of plots are drawn depending on the selected parameters:
P: bar plots of the posterior means with 95% posterior intervals of elements for each row of P
A: time series plots of posterior means with 95% posterior intervals elements for each column of A
Sigma: posterior means with error bars for 95% posterior intervals of elements of Sigma
plot
bmrm
functionAn S3 method that summarizes the
output of the bmrm
function in an object of class bmrm
. This object
contains
the posterior mean, the posterior standard deviation, and
(0.025, 0.05,0.25, 0.5, 0.75,0.95, 0.975) posterior quantiles
of A, P, . It also contains other
relevant information about the MCMC procedure such as the burn-in iterations,
the number of MCMC chains, etc.
## S3 method for class 'bmrm' summary(object, digits = 3, ...)
## S3 method for class 'bmrm' summary(object, digits = 3, ...)
object |
an object of class |
digits |
integer indicating the humber of signifiant digits |
... |
arguments to be passed to methods |
summary of bmrm class (output of bmrm function)
bmrm
objectProduce trace and Auto-Correlation Function plots (along with Effective sample size) of MCMC samples of elements of A, nonzero elements of P, elements of Sigma.
trace_ACF_plot(x,var="P", ACF=FALSE, nplot=0,irow=1, icol=1, saveFile=FALSE,...)
trace_ACF_plot(x,var="P", ACF=FALSE, nplot=0,irow=1, icol=1, saveFile=FALSE,...)
x |
an object of class |
var |
name of a variable to which the plots apply. It should be one of "A" (source contribution matrix), "P" (source composition matrix), "Sigma" (error variance). |
ACF |
TRUE/FALSE if TRUE ACF plots will be provided along with effective sample sizes(dafault: FALSE) |
nplot |
number of elements of 'var' for trace and/or ACF plots. If 'nplot' is smaller than the total number of elements of 'var' then plots of 'nplot' selected elements will be drawn. Otherwise, trace and/or ACF plots of all elements will be drawn. (default=0 implies that all elements will be selected if var="P" or "Sigma", and the first 12 elements will be selected if var="A") |
irow |
row index of A/P matrix or index of element of Sigma vector. Plots of 'nplot' elements starting from (irow, icol) element of A/P or elements starting from irow element of Sigma will be drawn (default=1). |
icol |
column number of A/P matrix. Plots of 'nplot' elements starting from (irow, icol) element of A/P will be drawn (default=1). |
saveFile |
TRUE/FALSE, save the plots in file 'var'-trace.pdf (default=FALSE) |
... |
arguments to be passed to methods |
plot
data(Elpaso); Y=Elpaso$Y ; muP=Elpaso$muP ; q=nrow(muP) out.Elpaso <- bmrm(Y,q,muP, nAdapt=1000,nBurnIn=5000,nIter=5000,nThin=1) trace_ACF_plot(out.Elpaso,"Sigma", ACF=TRUE) trace_ACF_plot(out.Elpaso,"P", ACF=TRUE) trace_ACF_plot(out.Elpaso,"A",ACF=TRUE, nplot=12, irow=2, icol=3)
data(Elpaso); Y=Elpaso$Y ; muP=Elpaso$muP ; q=nrow(muP) out.Elpaso <- bmrm(Y,q,muP, nAdapt=1000,nBurnIn=5000,nIter=5000,nThin=1) trace_ACF_plot(out.Elpaso,"Sigma", ACF=TRUE) trace_ACF_plot(out.Elpaso,"P", ACF=TRUE) trace_ACF_plot(out.Elpaso,"A",ACF=TRUE, nplot=12, irow=2, icol=3)