I am planning a second edition of this book.
I would love to hear any comments that you might have.
I am also exploring the possibility of taking on a coauthor to assist with revisions.
Email me if you are interested. Dan
Rowe, D.B. (2003).
Multivariate Bayesian Statistics: Models for Source Separation and
Signal Unmixing. CRC Press, Boca Raton, FL, USA. ISBN: 1584883189.
Available from CRC
Press,
Amazon.com, or
BN.com.
Here is the CRC flyer.
(The source separation model is what is called an overparameterized model.
That is, if we write down the likelihood, differentiate it with respect
to the mixing parameters and the unobservable sources, set the result equal
to zero, the resulting equations do not have a unique solution. There are
two approaches to remedy this problem. The first is to impose constraints on
the model and likelihood such as independence of sources. The second which
is adopted in this text is to incorporate available information into the
inference with the use of Bayesian statistics. Thus an independence
constraint is not imposed and dependent sources are estimated.)
This is a place where I have put information on this book. You may also be interested in
this BSS webpage or
this BFA webpage.
BAYESIAN ESTIMATION METHODS
Marginal Posterior Mean
Matrix Integration
Gibbs Sampling
Gibbs Sampling Convergence
Normal Variate Generation
Wishart and Inverted Wishart Variate Generation
Factorization
Rejection Sampling
Maximum a Posteriori
Matrix Differentiation
Iterated Conditional Modes (ICM)
Advantages of ICM over Gibbs Sampling
Advantages of Gibbs Sampling over ICM
REGRESSION Introduction
Normal Samples
Simple Linear Regression
Multiple Linear Regression
Multivariate Linear Regression
Part II: II Models
BAYESIAN REGRESSION (Multivariate)
Introduction
The Bayesian Regression Model
Likelihood
Conjugate Priors and Posterior
Conjugate Estimation and Inference
Generalized Priors and Posterior
Generalized Estimation and Inference
Interpretation
Discussion
BAYESIAN FACTOR ANALYSIS
Introduction
The Bayesian Factor Analysis Model
Likelihood
Conjugate Priors and Posterior
Conjugate Estimation and Inference
Generalized Priors and Posterior
Generalized Estimation and Inference
Interpretation Discussion
BAYESIAN SOURCE SEPARATION
Introduction
Source Separation Model
Source Separation Likelihood
Conjugate Priors and Posterior
Conjugate Estimation and Inference
Generalized Priors and Posterior
Generalized Estimation and Inference
Interpretation Discussion
UNOBSERVABLE AND OBSERVABLE SOURCE SEPARATION
Introduction
Model
Likelihood
Conjugate Priors and Posterior
Conjugate Estimation and Inference
Generalized Priors and Posterior
Generalized Estimation and Inference
Interpretation
Discussion
FMRI CASE STUDY
Introduction
Model
Priors and Posterior
Estimation and Inference
Simulated FMRI Experiment
Real FMRI Experiment
FMRI Conclusion
Part III: Generalizations
DELAYED SOURCES AND DYNAMIC COEFFICIENTS
Introduction Model
Delayed Constant Mixing
Delayed Nonconstant Mixing
Instantaneous Nonconstant Mixing
Likelihood
Conjugate Priors and Posterior
Conjugate Estimation and Inference
Generalized Priors and Posterior
Generalized Estimation and Inference
Interpretation
Discussion
CORRELATED OBSERVATION AND SOURCE VECTORS
Introduction Model
Likelihood
Conjugate Priors and Posterior
Conjugate Estimation and Inference
Posterior Conditionals
Generalized Priors and Posterior
Generalized Estimation and Inference
Interpretation
Discussion
CONCLUSION
Appendix A FMRI Activation Determination
Appendix B FMRI Hyperparameter Assessment
Bibliography
Index
% Copyright (c) 2002, Daniel B. Rowe
% This Matlab program performs the computations
% for a Multivariate Regression.
% It reads in the data file 'regdata.txt' and
% computes estimates the parameters as in Rowe 2002.
% There are references listed at the end.
clear
% Have data arranged so that n is the number
% of rows and p+q+1 is the number of columns
% Each row is an observation vector.
n=32;
p=3;
q=2;
disp(' ')
disp('Reading in the data matrix')
load 'regdata.txt' % Reads in data from regdata.txt
X=regdata(:,1:p)
U=regdata(:,p+1:p+q+1)
clear regdata
% Computing estimated regression coefficients, MLE
disp(' ')
disp('Computing estimated regression coefficients')
Bhat=X'*U*inv(U'*U)
% Computing estimated error covariance matrix, MLE
disp(' ')
disp('Computing estimated error covariance matrix')
G=(X-U*Bhat')'*(X-U*Bhat')
Sigmahat=G/n
W=zeros(q+1,q+1);
W=inv(U'*U);
disp(' ')
disp('Computing marginal posterior statistics')
% Computing marginal t-statistics for each coefficient
t=zeros(p,q+1);
for col=1:q+1
for row=1:p
t(row,col)=Bhat(row,col)/sqrt(W(col,col)*G(row,row)/(n-q-1)) ;
end
end
t
%save reg
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% References %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Rowe, D.B. (2003). Multivariate Bayesian Statistics:
% Models for Source Separation and Signal Unmixing.
% CRC Press, Boca Raton, Florida.
% Rowe, D.B. and Morgan, S.W. (2002). Computing FMRI
% Activations: Coefficients and t-Statistics by Detrending
% and Multiple Regression. Technical Report 39, Division
% of Biostatistics, Medical College of Wisconsin, Milwaukee
% Wisconsin, 53226.
% Press, S. J. (1982). Applied Multivariate Analysis: Using
% Bayesian and Frequentist Methods of Inference. Robert E. Krieger
% Publishing Company, Malabar, Florida.
% Copyright (c) 2002, Daniel B. Rowe
% This Matlab program performs the computations
% for a Bayesian Multivariate Regression.
% Conjugate prior distributions are used.
% This program will work on the student version.
% It reads in the data file 'sugar.txt' and
% computes estimates the parameters as in Rowe 2002.
% Data is available to assess the hyperparameters from,
% the file which contains it is sugar0.txt.
% There are references listed at the end.
clear
n=36;
p=6;
q=3;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Hyperparameter assessment %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
assess='previus';
%assess='subject';
%%%%
if assess=='subject',
%%%%
disp('Subjectively Assessed Hyperparameters')
B0=[
101.0000, 0.0556, -0.3889, 0.8889;
58.6944, 0.2500, 0.5833, 1.0278;
66.3889, 2.5556, -2.8889, 0.6111;
76.9444, 3.0556, -6.6111, -0.9444;
95.5278, 2.6944, -6.3056, 1.5278;
100.2222, 2.6111, -2.5556, 2.7222]
D=[0.0278, 0, 0, 0;
0, 0.0278, 0, 0;
0, 0, 0.0278, 0;
0, 0, 0, 0.0278]
Q=[ 109.20, 29.28, -21.31, 10.26, 69.04, 66.89;
29.28, 233.31, 201.53, 200.37, 107.54, 81.99;
-21.31, 201.53, 289.36, 269.59, 107.33, 74.90;
10.26, 200.37, 269.59, 461.22, 297.59, 205.36;
69.04, 107.54, 107.33, 297.59, 478.62, 271.07;
66.89, 081.99, 74.90, 205.36, 271.07, 248.49]
nu=36
%%%%
else
%%%%
disp('Assessing hyperparameters from previous data.')
% Reads in data from sugar0.txt
% Have data arranged so that n0 is the number
% of rows and p+q+1 is the number of columns
% and is of the form [X,U].
% Each row is an observation vector.
disp(' ')
disp('Reading in the previous data matrix')
load 'sugar0.txt'; % Reads in the data from sugar0.txt
disp(' ')
disp('The data matrix X0 is')
X0=sugar0(:,1:p);
sizeX0=size(X0);
nu=sizeX0(1,1)
p=sizeX0(1,2)
disp(' ')
disp('The design matrix U is')
U0=sugar0(:,p+1:p+q+1);
sizeU0=size(U0);
nu=sizeU0(1,1)
clear sugar0
% Assessing prior hyperparameters B0 and D
% for regression coefficient matrix
disp(' ')
disp('Assessing prior mean B0 for regression coefficients')
B0=X0'*U0*inv(U0'*U0)
D=inv(U0'*U0)
% Assessing prior hyperparameter matrix Q
% for error covariance matrix
disp(' ')
disp('Assessing prior scale matrix Q for error covariance matrix')
Q=(X0-U0*B0')'*(X0-U0*B0')
%%%%
end
%%%%
Dinv=zeros(q+1,q+1);
Dinv=inv(D);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Computing marginal posterior mean estimates %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp('Computing marginal posterior mean estimates')
% Reads in data from bregdata.txt
disp(' ')
disp('Reading in the data')
load 'sugar.txt' % Reads in the data from sugar.txt
disp(' ')
disp('The data matrix X is')
X=sugar(:,1:p)
disp(' ')
disp('The design matrix U is')
U=sugar(:,p+1:p+q+1)
clear sugar
disp(' ')
disp('Computing marginal posterior mean estimates')
% Computing marginal mean posterior estimates
% for the regression coefficient matrix
W=zeros(q+1,q+1);
W=inv(Dinv+U'*U);
Bbar=(X'*U+B0*Dinv)*W
% Computing marginal mean posterior estimates
% for the error covariance matrix
G=Q+X'*X+B0*Dinv*B0'-(X'*U+B0*Dinv)*W*(X'*U+B0*Dinv)';
Sigmabar=G/(n+nu-2*p-2)
disp(' ')
disp('Computing marginal posterior statistics')
% Computing marginal t-statistics for each coefficient
t=zeros(p,q+1);
for col=1:q+1
for row=1:p
t(row,col)=Bbar(row,col)/sqrt(W(col,col)*G(row,row)/(n+nu-q-2*p+1)) ;
end
end
t
disp(' ')
disp('Computing maximum a posteriori estimates')
% Computing maximum a posteriori estimate
% for the regression coefficient matrix
Btilde=Bbar
% Computing maximum a posteriori estimate
% for the error covariance matrix
Sigmatilde=G/(n+nu+q+1)
disp(' ')
disp('Computing marginal conditional posterior statistics')
% Computing marginal z-statistics for each coefficient
z=zeros(p,q+1);
for col=1:q+1
for row=1:p
z(row,col)=Btilde(row,col)/sqrt(W(col,col)*G(row,row)/(n+nu+q+1)) ;
end
end
z
%save bregnat
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% References %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Rowe, D.B. (2003). Multivariate Bayesian Statistics:
% Models for Source Separation and Signal Unmixing.
% CRC Press, Boca Raton, Florida.
% Rowe, D.B. (2001). A Bayesian Unobservable/Observable
% Source Separation Model and Activation Determination in
% FMRI. Social Science Working Paper 1120, Division of
% Humanities and Social Sciences, California Institute
% of Technology, Pasadena, CA 91125.
% Press S. J. (1989). Bayesian Statistics: Principles Models,
% and Applications, John Wiley and Sons, New York.
% Press, S. J. (1982). Applied Multivariate Analysis: Using
% Bayesian and Frequentist Methods of Inference. Robert E. Krieger
% Publishing Company, Malabar, Florida.
Chapter 9: Bayesian Factor Analysis
Program bfanat.m
% Copyright (c) 2002, Daniel B. Rowe
% This Matlab program performs the computations
% for Bayesian Factor Analysis as described
% in Rowe 2002 with conjugate priors.
% This program will work on the student version.
% It reads in the data file 'applicant.txt' and
% with the hyperparameters in this program
% estimates the parameters.
% There are references listed at the end.
clear
% Have data arranged so that n is the number
% of rows and p is the number of columns
% Each row is an observation vector.
load 'applicant.txt' % Reads in data from applicant.txt
[n,p]=size(applicant);
X=applicant;
clear applicant
xdsigma=sqrt(diag(cov(X))); % needed to scale data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Hyperparameter assessment %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp('Subjectively Assessed Hyperparameters')
mu0=zeros(p,1);
mu0=7.5*ones(p,1);
m=4;
Lambda0=zeros(p,m); % Lambda0 is a correlation matrix
Lambda0=.7 * [
0, 0, 1, 0;
0, 0, 0, 0;
0, 1, 0, 0;
0, 0, 0, 1;
1, 0, 0, 0;
1, 0, 0, 0;
0, 0, 0, 1;
1, 0, 0, 0;
0, 0, 1, 0;
1, 0, 0, 0;
1, 0, 0, 0;
1, 0, 0, 0;
1, 0, 0, 0;
0, 0, 0, 0;
0, 0, 1, 0];
C0=zeros(p,m);
C0=[mu0,Lambda0];
C0(:,1)=C0(:,1)./xdsigma; % Scale the prior mean
D0=1/10;
D=D0*eye(m+1);
nu=33; % nu must be a positive integer
q0=0.200;
Q=q0*eye(p);
% These numbers can be changed depending on the data set.
ICMiterations=25000; % # of ICM iterations
Gibbsburn=10000; % # of burn in variates
Gibbsiterations=25000; % # of samples for estimates
% Do not change any thing below here.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Estimation %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Dinv=zeros(m+1,m+1);
Dinv=inv(D);
% Both the ICM and Gibbs sampling techniques need
% initial starting values.
% Press/Shigemasu 1989 BFA estimates of parameters
muPS89=mean(X);
FPS89=zeros(n,m);
XmuPS89=X-ones(n,1)*muPS89;
XmuPS89=XmuPS89./(ones(n,1)*xdsigma');
W=XmuPS89'*XmuPS89+Q+Lambda0*inv(D(2:m+1,2:m+1))*Lambda0';
FPS891=(eye(n)-XmuPS89*inv(XmuPS89'*XmuPS89-W)*XmuPS89');
FPS89=FPS891*XmuPS89*inv(W)*Lambda0*inv(D(2:m+1,2:m+1))
LambdaPS89=(XmuPS89'*FPS89+Lambda0*inv(D(2:m+1,2:m+1)))*inv(inv(D(2:m+1,2:m+1))+FPS89'*FPS89)
PsiPS89mean=((XmuPS89-FPS89*LambdaPS89')'*(XmuPS89-FPS89*LambdaPS89')+(LambdaPS89-Lambda0)*inv(D(2:m+1,2:m+1))*(LambdaPS89-Lambda0)'+Q)/(n+m+nu-2*p-2)
PsiPS89mode=PsiPS89mean*(n+m+nu-2*p-2)/(n+m+nu)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ICM algorithm estimates %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Initialize variables
FICM=zeros(n,m);
ZICM=zeros(n,m+1);
CICM=zeros(p,m+1);
SigmaICM=zeros(p,p);
% Initial value
FICM=FPS89;
% Scale X matrix
X=X./(ones(n,1)*xdsigma');
for count=1:ICMiterations
ZICM=[ones(n,1),FICM];
CICM= (X'*ZICM+C0*Dinv)*inv(Dinv+ZICM'*ZICM);
SigmaICM=[(X-ZICM*CICM')'*(X-ZICM*CICM')+(CICM-C0)*Dinv*(CICM-C0)'+Q]/(n+nu+m+1);
FICM1=(X-ones(n,1)*CICM(:,1)')*inv(SigmaICM)*CICM(:,2:m+1);
FICM=FICM1*inv(eye(m)+CICM(:,2:m+1)'*inv(SigmaICM)*CICM(:,2:m+1));
end
CICM(:,1)=CICM(:,1).*xdsigma; % Rescale the posterior mean
CICM % Posterior estimate of Lambda0 is a matrix of correlations
SigmaICM
FICM
%%%ICM Significance
ZICM=[ones(n,1),FICM];
CICM(:,1)=CICM(:,1)./xdsigma; % Scale the posterior mean
WICM=zeros(m+1,m+1);
WICM=inv(Dinv+ZICM'*ZICM);
disp(' ')
disp('Computing marginal conditional posterior statistics')
% Computing marginal t-statistics for each coefficient
zICM=zeros(p,m+1);
for col=1:m+1
for row=1:p
zICM(row,col)=CICM(row,col)/sqrt(WICM(col,col)*SigmaICM(row,row)) ;
end
end
zICM
CICM(:,1)=CICM(:,1).*xdsigma; % Rescale the posterior mean
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Gibbs sampling algorithm estimates %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Initialize variables
% The starting values don't matter
% But convergence is faster with good values
FGibbs=FICM;
CGibbs=CICM;
SigmaGibbs=SigmaICM;
ZGibbs=[ones(n,1),FGibbs];
Ftot=zeros(n,m);
Ctot=zeros(p,m+1);
C2tot=zeros(p*(m+1),p*(m+1));
Sigmatot=zeros(p,p);
YC = zeros(p,m+1);
YP = zeros(n+nu+m+1+p+1,p);
FGibbs=zeros(n,m);
WGibbs=zeros(m+1,m+1);
WGibbs=inv(Dinv+ZGibbs'*ZGibbs);
for count=1:Gibbsburn+Gibbsiterations
MC=(C0*Dinv+X'*ZGibbs)*WGibbs;
YC = randn(p,m+1);
AtC=chol(SigmaGibbs);
BtC=chol(WGibbs);
CGibbs=AtC'*YC*BtC+MC;
YP = randn(n+nu+m+1+p+1,p);
AtP=chol((X-ZGibbs*CGibbs')'*(X-ZGibbs*CGibbs')+(CGibbs-C0)*Dinv*(CGibbs-C0)'+Q);
SigmaGibbs=AtP'*inv(YP'*YP)*AtP;
MF1=(X-ones(n,1)*CGibbs(:,1)')*inv(SigmaGibbs)*CGibbs(:,2:m+1);
MF=MF1*inv(eye(m)+CGibbs(:,2:m+1)'*inv(SigmaGibbs)*CGibbs(:,2:m+1));
FGibbs=randn(n,m);
BtF=chol(inv(eye(m)+CGibbs(:,2:m+1)'*inv(SigmaGibbs)*CGibbs(:,2:m+1)));
FGibbs=FGibbs*BtF+MF;
ZGibbs=[ones(n,1),FGibbs];
WGibbs=inv(Dinv+ZGibbs'*ZGibbs);
if count>Gibbsburn
Ftot=Ftot+FGibbs;
Ctot=Ctot+CGibbs;
C2tot=C2tot+vec(CGibbs)*vec(CGibbs)';
Sigmatot=Sigmatot+SigmaGibbs;
end
end
FGibbs=Ftot/Gibbsiterations
CGibbs=Ctot/Gibbsiterations;
DeltaGibbs=C2tot/Gibbsiterations-vec(CGibbs)*vec(CGibbs)';
CGibbs(:,1)=CGibbs(:,1).*xdsigma; % unscale the mean
CGibbs
SigmaGibbs=Sigmatot/Gibbsiterations
%%%Gibbs Significance
disp(' ')
disp('Computing marginal posterior statistics')
% Computing marginal z-statistics for each coefficient
zGibbs=zeros(p,m+1);
for col=1:m+1
for row=1:p
zGibbs(row,col)=CGibbs(row,col)/sqrt(DeltaGibbs(p*(col-1)+row,p*(col-1)+row));
end
end
zGibbs
%save bfanat
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% References %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Rowe, D.B. (2003). Multivariate Bayesian Statistics:
% Models for Source Separation and Signal Unmixing.
% CRC Press, Boca Raton, Florida.
% Rowe, D. B. (2003). On Using the Sample Mean in Bayesian
% Factor Analysis. Forthcoming in the Journal of
% Interdisciplinary Mathematics, Vol. 6, No. 3, pp. 319-329.
% Rowe, D.B. (2001). A Model for Bayesian Factor
% Analysis with Jointly Distributed Means and Loadings.
% Social Science Working Paper 1108, Division of Humanities
% and Social Sciences, California Institute of Technology,
% Pasadena, CA 91125.
% Rowe, D. B. (2000). Incorporating Prior Knowlege Regarding
% the Mean in Bayesian Factor Analysis. Social Science Working
% Paper 1097, Division of Humanities and Social Sciences,
% California Institute of Technology, Pasadena, CA 91125.
% Rowe, D. B. (2000). On Estimating the Mean in Bayesian
% Factor Analysis. Social Science Working Paper 1096,
% Division of Humanities and Social Sciences, California
% Institute of Technology, Pasadena, CA 91125.
% Rowe, D. B. and Press, S. J. (1998). Gibbs Sampling
% and Hill Climbing in Bayesian Factor Analysis. Technical
% Report No. 255 Department of Statistics, University of
% California, Riverside.
% Press, S. J. and Shigemasu, K. (1997). Bayesian inference in
% Factor Analysis-Revised. Technical Report No. 243, Department
% of Statistics, University of California, Riverside.
% Press, S. J. and Shigemasu, K. (1989). Bayesian inference in
% Factor Analysis. In Contributions to Probability and
% Statistics, Chapter 15, Springer-Verlag.
% Press S. J. (1989). Bayesian Statistics: Principles Models,
% and Applications, John Wiley and Sons, New York.
% Press, S. J. (1982). Applied Multivariate Analysis: Using
% Bayesian and Frequentist Methods of Inference. Robert E.
% Krieger Publishing Company, Malabar, Florida.
% Geman, S. and Geman, D. (1984). Stochastic relaxation,
% Gibbs distributions and the Bayesian restoration of images.
% IEEE Trans. on pattern analysis and machine intelligence
% 6, 721-741.
% Lindley, D. V. and Smith, A. F. M. (1972). Bayes estimates for
% the linear model, Journal of the Royal Statistical Society B,
% Volume 34, No. 1.
% O'Hagan, Anthony (1994). Kendall's Advanced Theory
% of Statistics, Volume 2B Bayesian Inference. John Wiley
% and Sons, Inc., New York.
Chapter 10: Bayesian Source Separation
Program bssnat.m
% Copyright (c) 2002, Daniel B. Rowe
% This Matlab program performs the computations
% for Bayesian Source Separation as described
% in Rowe 2002 with conjugate priors.
% There are references listed at the end.
clear
fignum=0;
% Have data arranged so that n is the number
% of rows and p is the number of columns
% Each row is an observation vector.
load 'plankton.txt' % Reads in data from plankton.txt
[nn,p]=size(plankton);
n0=nn/2;
n=nn/2;
for i=1:n0
X0(i,1:p)=plankton(2*(i-1)+1,1:p);
end
for i=1:n
X(i,1:p)=plankton(2*i,1:p);
end
clear plankton
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Hyperparameter assessment %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp('Assessed Hyperparameters')
[pc,score,latent,tsquare] = princomp(X0);
S0=score(:,1:5)
m=5;
D=zeros(m+1,m+1);
D=inv([ones(n0,1),S0]'*[ones(n0,1),S0])
C0=zeros(p,m+1);
C0=X0'*[ones(n0,1),S0]*D
mu0=zeros(p,1);
Lambda0=zeros(p,m);
mu0=C0(:,1:1);
Lambda0=C0(:,2:m+1);
nu=n0 % nu must be a positive integer
Q=(X-[ones(n0,1),S0]*C0')'*(X-[ones(n0,1),S0]*C0')
eta=n0;
V=S0'*S0;
% These numbers can be changed depending on the data set.
ICMiterations=25000; % # of ICM iterations
Gibbsburn=10000; % # of burn in variates
Gibbsiterations=25000; % # of samples for estimates
% Do not change anything below here.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Estimation %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Dinv=zeros(m+1,m+1);
Dinv=inv(D);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ICM algorithm estimates %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Initialize variables
SICM=zeros(n,m);
ZICM=zeros(n,m+1);
CICM=zeros(p,m+1);
RICM=zeros(m,m);
SigmaICM=zeros(p,p);
ZICM=[ones(n,1),SICM];
% Initial value
SICM=randn(n,m);
for count=1:ICMiterations
ZICM=[ones(n,1),SICM];
CICM=(X'*ZICM+C0*Dinv)*inv(Dinv+ZICM'*ZICM);
SigmaICM=[(X-ZICM*CICM')'*(X-ZICM*CICM')+(CICM-C0)*Dinv*(CICM-C0)'+Q]/(n+nu+m+1);
RICM=((SICM-S0)'*(SICM-S0)+V)/(n+eta);
SICM1=S0*inv(RICM)+(X-ones(n,1)*CICM(:,1)')*inv(SigmaICM)*CICM(:,2:m+1);
SICM=SICM1*inv(inv(RICM)+CICM(:,2:m+1)'*inv(SigmaICM)*CICM(:,2:m+1));
end
CICM
SigmaICM
RICM
SICM
%%%ICM Significance
WICM=zeros(m+1,m+1);
WICM=inv(Dinv+ZICM'*ZICM);
disp(' ')
disp('Computing marginal conditional posterior statistics')
% Computing marginal t-statistics for each coefficient
zICM=zeros(p,m+1);
for col=1:m+1
for row=1:p
zICM(row,col)=CICM(row,col)/sqrt(WICM(col,col)*SigmaICM(row,row)) ;
end
end
zICM
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Gibbs sampling algorithm estimates %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Initialize variables
% The starting values don't matter
% But convergence is faster with good values
SGibbs=SICM;
CGibbs=CICM;
RGibbs=RICM;
SigmaGibbs=SigmaICM;
ZGibbs=[ones(n,1),SGibbs];
WGibbs=zeros(m+1,m+1);
WGibbs=inv(Dinv+ZGibbs'*ZGibbs);
Stot=zeros(n,m);
Ctot=zeros(p,m+1);
C2tot=zeros(p*(m+1),p*(m+1));
Rtot=zeros(m,m);
Sigmatot=zeros(p,p);
YC = zeros(p,m+1);
YSig = zeros(n+nu+m+1+p+1,p);
SGibbs=zeros(n,m);
YR = zeros(n+eta+m+1,m);
for count=1:Gibbsburn+Gibbsiterations
MC=(C0*Dinv+X'*ZGibbs)*WGibbs;
YC = randn(p,m+1);
AtC=chol(SigmaGibbs);
BtC=chol(WGibbs);
CGibbs=AtC'*YC*BtC+MC;
YSig = randn(n+nu+m+1+p+1,p);
AtSig=chol((X-ZGibbs*CGibbs')'*(X-ZGibbs*CGibbs')+(CGibbs-C0)*Dinv*(CGibbs-C0)'+Q);
SigmaGibbs=AtSig'*inv(YSig'*YSig)*AtSig;
YR = randn(n+eta+m+1,m);
AtR=chol((SGibbs-S0)'*(SGibbs-S0)+V);
RGibbs=AtR'*inv(YR'*YR)*AtR;
MS1=S0*inv(RGibbs)+(X-ones(n,1)*CGibbs(:,1)')*inv(SigmaGibbs)*CGibbs(:,2:m+1);
MS=MS1*inv(inv(RGibbs)+CGibbs(:,2:m+1)'*inv(SigmaGibbs)*CGibbs(:,2:m+1));
SGibbs=randn(n,m);
BtS=chol(inv(inv(RGibbs)+CGibbs(:,2:m+1)'*inv(SigmaGibbs)*CGibbs(:,2:m+1)));
SGibbs=SGibbs*BtS+MS;
ZGibbs=[ones(n,1),SGibbs];
WGibbs=inv(Dinv+ZGibbs'*ZGibbs);
if count>Gibbsburn
Stot=Stot+SGibbs;
Ctot=Ctot+CGibbs;
C2tot=C2tot+vec(CGibbs)*vec(CGibbs)';
Rtot=Rtot+RGibbs;
Sigmatot=Sigmatot+SigmaGibbs;
end
end
SGibbs=Stot/Gibbsiterations
CGibbs=Ctot/Gibbsiterations
DeltaGibbs=C2tot/Gibbsiterations-vec(CGibbs)*vec(CGibbs)';
RGibbs=Rtot/Gibbsiterations
SigmaGibbs=Sigmatot/Gibbsiterations
%%%Gibbs Significance
disp(' ')
disp('Computing marginal posterior statistics')
% Computing marginal z-statistics for each coefficient
zGibbs=zeros(p,m+1);
for col=1:m+1
for row=1:p
zGibbs(row,col)=CGibbs(row,col)/sqrt(DeltaGibbs(p*(col-1)+row,p*(col-1)+row));
end
end
zGibbs
fignum=fignum+1;
figure(fignum)
subplot(9,2,1)
plot(1:n,X(:,1),'k')
axis tight
subplot(9,2,3)
plot(1:n,X(:,2),'k')
axis tight
subplot(9,2,5)
plot(1:n,X(:,3),'k')
axis tight
subplot(9,2,7)
plot(1:n,X(:,4),'k')
axis tight
subplot(9,2,9)
plot(1:n,X(:,5),'k')
axis tight
subplot(9,2,11)
plot(1:n,X(:,6),'k')
axis tight
subplot(9,2,13)
plot(1:n,X(:,7),'k')
axis tight
subplot(9,2,15)
plot(1:n,X(:,8),'k')
axis tight
subplot(9,2,17)
plot(1:n,X(:,9),'k')
axis tight
subplot(9,2,6)
plot(1:n,SGibbs(:,1),'k--',1:n,SICM(:,1),'k:')
axis tight
subplot(9,2,8)
plot(1:n,SGibbs(:,2),'k--',1:n,SICM(:,2),'k:')
axis tight
subplot(9,2,10)
plot(1:n,SGibbs(:,3),'k--',1:n,SICM(:,3),'k:')
axis tight
subplot(9,2,12)
plot(1:n,SGibbs(:,4),'k--',1:n,SICM(:,4),'k:')
axis tight
subplot(9,2,14)
plot(1:n,SGibbs(:,5),'k--',1:n,SICM(:,5),'k:')
axis tight
%save bssnat
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% References %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Rowe, D.B. (2003). Multivariate Bayesian Statistics:
% Models for Source Separation and Signal Unmixing.
% CRC Press, Boca Raton, Florida.
% Rowe, D.B. (2003). Bayesian Source Separation of
% Functional Sources. Journal of Interdisciplinary
% Mathematics, Vol. 6, No. 2, pp. 129-138.
% Rowe, D.B. (2002). Jointly Distributed Mean and
% Mixing Coefficients for Bayesian Source Separation
% using MCMC and ICM. Monte Carlo Methods and Applications,
% Vol. 8, No. 4, pp. 395-403.
% Rowe, D.B. (2001). Bayesian Source Separation for
% Reference Function Determination in fMRI. Magnetic
% Resonance in Medicine, Volume 46, Issue 2, pp. 374-378.
% Rowe, D.B. (2002). A Bayesian Approach to Blind
% Source Separation. Journal of Interdisciplinary
% Mathematics, Vol. 5, No. 1, pp. 49-76.
% Rowe, D.B. (2001). Bayesian Source Separation with
% Jointly Distributed Mean and Mixing Coefficients
% via MCMC and ICM. Social Science Working Paper 1119,
% Division of Humanities and Social Sciences, California
% Institute of Technology, Pasadena, CA 91125.
% Rowe, D.B. (2001). A Model for Bayesian Source
% Separation With The Overall Mean. Social Science
% Working Paper 1118, Division of Humanities and Social
% Sciences, California Institute of Technology, Pasadena,
% CA 91125.
% Rowe, D. B. and Press, S. J. (1998). Gibbs Sampling
% and Hill Climbing in Bayesian Factor Analysis.
% Technical Report No. 255 Department of Statistics,
% University of California, Riverside.
% Geman, S. and Geman, D. (1984). Stochastic relaxation,
% Gibbs distributions and the Bayesian restoration of images.
% IEEE Trans. on pattern analysis and machine intelligence
% 6, 721-741.
% Lindley, D. V. and Smith, A. F. M. (1972). Bayes estimates
% for the linear model, Journal of the Royal Statistical
% Society B, Volume 34, No. 1.
% O'Hagan, Anthony (1994). Kendall's Advanced Theory
% of Statistics, Volume 2B Bayesian Inference. John Wiley
% and Sons, Inc., New York.
% Copyright (c) 2000, Daniel B. Rowe
% Performs the vectorization operation
% Takes a matrix and turns it into a vector
% by stacking its columns.
function [ vector ] = vec(matrix)
[p,m]=size(matrix);
vector=zeros(p*m,1);
for cols=1:m
for rows=1:p
vector(rows+p*(cols-1),1 )=matrix(rows,cols);
end
end
Program tr.m
% Copyright (c) 2000, Daniel B. Rowe
% Performs the trace operation
% Adds the diagonal elements of a square matrix.
function [ trace ] = tr(matrix)
[p,p]=size(matrix);
trace=0;
for diagelemt=1:p
trace=trace+matrix(diagelemt,diagelemt);
end
Supplementary Material
Corrections and Clarifications
Page 12: Equation 2.1.12, should be
"()
=(-1)
(-1)."
Page 13: Equation 2.1.18, should have the term "1/(b-a)."
Page 18: Equation 2.1.59, should have "g~W(-2,1,)."
Page 18: Equation 2.1.63, numerator term
"-
"
should be "."
Page 21: Equation 2.2.7, "x ~ N(µ ,-2)"
should be "x ~ N(µ ,
-2Ip)".
Page 21: Equation 2.2.9, "W" should be "|W|".
Page 21: Equation 2.2.11, numerator term
"(2)-/2"
should be "(2)/2."
Page 22: Second to last line, "where x=(X') ..."
should be "where x=vec(X') ..."
Page 24: Equation 2.3.37, "W" should be "|W|".
Page 96: Equation 7.3.22, numerator term "(U'U)"
should be "(U'U)-1."
Updated by Daniel B.Rowe.