JiscMail Logo
Email discussion lists for the UK Education and Research communities

Help for BUGS Archives


BUGS Archives

BUGS Archives


BUGS@JISCMAIL.AC.UK


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

BUGS Home

BUGS Home

BUGS  2002

BUGS 2002

Options

Subscribe or Unsubscribe

Subscribe or Unsubscribe

Log In

Log In

Get Password

Get Password

Subject:

Multivariate Normal Posterior Predictive Discrimination

From:

"Paul, David A" <[log in to unmask]>

Reply-To:

Paul, David A

Date:

Thu, 3 Jan 2002 14:36:35 +0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (282 lines)

At the end of this messageI have pasted code I developed to perform MVNormal
Posterior
Predictive Discriminant Analysis (PPDA).  I validated the code by applying
it to a data set found
in G.A.F. Seber's book, "Multivariate Observations", p. 295.  The expected
value(s) for the
posterior distributions of the population means matched Seber's analysis
exactly, while the
values obtained for the covariance matrix entries are slightly different,
but still close.
The two "new" observations I used in forming ratios of posterior predictive
distributions were
made up by me.

It is always possible that this code doesn't work like it should, and I
would be especially grateful
for any comments and criticisms.  I would be particularly interested if
anyone were to find
errors in the manner I calculated the exponents for the posterior predictive
distributions.

It is my hope that this program benefits those of you who are interested in
Discriminant
Analysis.

Regards,

David Alan Paul, Ph.D.
Battelle Memorial Institute - SDAS
[log in to unmask]
614-424-3176
614-424-4611 (fax)
http://www.battelle.org/statistics


#The ultimate goal is to create a posterior predictive density for each of
two
#populations and use these predictive distributions to form a ratio, on
which we
#shall base the assignment of new observations to one of the two
populations.
#The theory for this approach is given in G.A.F. Seber's book, "Multivariate

#Observations", on pages 292 and 301.  (Wiley)

#In this program, N1 represents the total number of multivariate
observations from
#Group1, N2 represents the total number of multivariate observations from
Group2,
#and N3 represents the total number of new observations to be classified.

#The likelihoods being formed correspond to the multivariate normal
distribution,
#and the example data represents the Flea-Beetles data, page 295, Seber (see

#comments before the actual data list for more information).

#It is assumed that the covariance structures of the two populations are
unequal,
#so that our Bayesian analysis corresponds most closely to Quadratic
Discriminant
#Analysis in the frequentist context.  Forcing tau to be the same for both
groups
#would not be difficult to do.

#The assignment of new observations to one or the other of the multivariate
#populations is made based on the variable 'criterion'.  The classification
rule is
#to assign an observation to Group 1 if the ratio
#(posterior predictive for group 1)/(posterior predictive for group 2)
#is greater than some specified constant, c.  In its most general form, this

#constant is given by (p2 * C[1|2]) / (p1 * C[2|1]).  Assuming equal prior
#probability of group membership and equal costs of misclassification, c=1.

model
        {

                for(i in 1:N1)

                        {

                                FleaBeetles[i,1:4] ~ dmnorm(mu[1,] ,
tau[1,,])

                        }

                for(i in (N1+1):(N1+N2))

                        {

                                FleaBeetles[i,1:4] ~ dmnorm(mu[2,] ,
tau[2,,])

                        }

#The most difficult part of implementing multivariate predictive posterior
#methods in WinBUGS is that you have to be able to express the posterior
#predictive distribution(s) at the data point(s) of interest - that is,
observed
#values of as-yet unclassified beetles.  Since WinBUGS does not yet support
#much in the way of matrix algebra, we are stuck with writing out the
exponent
#of the multivariate normal distribution in longhand.  The trick is to be
able
#to use the inprod(v1,v2) function to express this exponent in a convenient
#way.  Note:
#
# (1)   The vector [ (x[k,1]-mu1), (x[k,2]-mu2), (x[k,3]-mu3), (x[k,4]-mu4)
], where
#       the x[k,j] - values come from the new observation(s), is designated
as
#       Vec[k,,].  Note that k indicates the relevant population, either 1
or 2.
#
# (2)   The columns of the posterior covariance matrices are designated
using
#       tau[ population#, row# , column# ].  Thus, tau[1,,2] designates the
second
#       column of the posterior precision matrix for population 1.
#
#With these conventions, in mind, the following code calculates the ratios
#of the posterior predictive multivariate normal distributions evaluated at
#the new observations of interest.  Of course, the reader will have to
modify
#this code to accommodate data with higher or lower dimensionality.  The
form
#of the exponent in a multivariate normal distribution is given as
#(-.5)(x-mu)*V(x-mu) where * indicates a transpose, and V represents the
#precision matrix.  Note that V=Inverse(Covariance Matrix).  To express
#this exponent using sums of squares, we need to determine the vector
#(x - mu) and then assign vectors to each of the columns of the posterior
#precision matrix.  Once this is done, by using the inprod(v1,v2) function
#we can express this exponent rather simply, using the following code:

for(i in 1:N3)  #Loop for the number of observations to be classified

        {

                for(j in 1:4)   #Loop for the number of variables in the
data set

                        {

                                x.mu.1.vec[i,j] <- Predict[i,j] - mu[1,j]

                                x.mu.2.vec[i,j] <- Predict[i,j] - mu[2,j]

                        }

                for(k in 1:4)   #Loop through a dummy index, necessary for
the
                                #"matrix multiplication" we are doing


                        }

                                temp.1.vec[i,k] <- inprod( x.mu.1.vec[i,] ,
tau[1,,k] )
                                temp.2.vec[i,k] <- inprod( x.mu.2.vec[i,] ,
tau[2,,k] )

                        }

exponent1[i] <- inprod( temp.1.vec[i,] , x.mu.1.vec[i,] )
exponent2[i] <- inprod( temp.2.vec[i,] , x.mu.2.vec[i,] )

top[i] <- pow( (2*Pi), -2 ) * pow(  exp( logdet( tau[1,,]) ) , .5) * exp(-.5
* exponent1[i])

bot[i] <- pow( (2*Pi), -2 ) * pow(  exp( logdet( tau[2,,]) ) , .5) * exp(-.5
* exponent2[i])

criterion[i] <- top[i]/bot[i]

                        }

        for(i in 1:4)
                {
                        for(j in 1:4)
                                {
                                        sigma1[i,j] <- inverse( tau[1,,] , i
, j )
                                        sigma2[i,j] <- inverse( tau[2,,] , i
, j )
                                }
                }

                mu[1, 1:4] ~ dmnorm(mean[1:4], precision[1:4, 1:4])
                mu[2, 1:4] ~ dmnorm(mean[1:4], precision[1:4, 1:4])
                tau[1, 1:4, 1:4] ~ dwish(R[1:4, 1:4], 4)
                tau[2, 1:4, 1:4] ~ dwish(R[1:4, 1:4], 4)

        }

#In the following data list, note that the original data, reproduced on page
295 of
#Seber's book (taken from Lubischew's study of flea beetle measurements,
1962), is
#in the form
#
#        x1      x2      x3      x4
#       189     245     137     163
#       192     260     132     217
#         .     .       .       .
#
#and so on.  We have stacked the 19 data points for the haltica oleracea on
top of
#the 20 data points for the haltica carduorum, for a grand total of 39 data
points.
#WinBUGS requires that data in this sort of structure be listed by rows.
The .DIM
#statements at the end of the data structures specify (#rows, #columns).
The
#FleaBeetles structure corresponds to the actual data, while the Predict
structure
#corresponds to two new flea beetle observations we wish to classify.

list(FleaBeetles= structure(.Data = c(189., 245.,137., 163.,192., 260.,
132., 217.,217.,
276., 141., 192.,221., 299., 142., 213.,171., 239., 128., 158.,192., 262.,
147., 173.,213.,
278., 136., 201.,192., 255., 128., 185.,170., 244., 128., 192.,201., 276.,
146., 186.,195.,
242., 128., 192.,205., 263., 147., 192.,180., 252., 121., 167.,192., 283.,
138., 183.,200.,
294., 138., 188.,192., 277., 150., 177.,200., 287., 136., 173.,181., 255.,
146., 183.,192.,
287., 141., 198.,181., 305., 184., 209.,158., 237., 133., 188.,184., 300.,
166., 231.,171.,
273., 162., 213.,181., 297., 163., 224.,181., 308., 160., 223.,177., 301.,
166., 221.,198.,
308., 141., 197.,180., 286., 146., 214.,177., 299., 171., 192.,176., 317.,
166., 213.,192.,
312., 166., 209.,176., 285., 141., 200.,169., 287., 162., 214.,164., 265.,
147., 192.,181.,
308., 157., 204.,192., 276., 154., 209.,181., 278., 149., 235.,175., 271.,
140., 192.,197.,
303., 170., 205.) , .Dim=c(39,4)),

#The reader will notice that the data values to be used for prediction
purposes
#lead to some very interesting (and sharp) posterior distributions.

Predict = structure(.Data=c(160, 280, 140, 193, 187, 278, 160, 197),
.Dim=c(2,4)),

N1=19, N2=20, N3=2, Pi=3.14159,

mean = c(186.8 , 279.2 , 147.5 , 197.9),

# We are specifying a precision matrix for the means that implies low
# precision for them, and relative independence (the means do not
# covary)

precision = structure(.Data = c(1.0E-6, 0, 0, 0, 0,1.0E-6, 0, 0, 0,
0,1.0E-6, 0, 0, 0,0,1.0E-6),
.Dim = c(4,4)),

#According to the .5 WinBUGS manual, it is best to think of R as a prior
#estimate of the magnitude of the covariance matrix; the numbers in
#this matrix were chosen because they roughly match the pooled covariance
#matrix that Seber obtains.  MCMC updating will be required in any case
#since the correlations are left unspecified.

R = structure(.Data = c(140, 0, 0, 0, 0, 365, 0, 0, 0, 0, 110, 0, 0, 0, 0,
205), .Dim = c(4, 4))
)

#I used the "GenInits" option to get the initial values for this model.

-------------------------------------------------------------------
This list is for discussion of modelling issues and the BUGS software.
For help with crashes and error messages, first mail [log in to unmask]

To mail the BUGS list, mail to [log in to unmask]
Before mailing, please check the archive at www.jiscmail.ac.uk/lists/bugs.html
Please do not mail attachments to the list.

To leave the BUGS list, send LEAVE BUGS to [log in to unmask]
If this fails, mail [log in to unmask], NOT the whole list

Top of Message | Previous Page | Permalink

JiscMail Tools


RSS Feeds and Sharing


Advanced Options


Archives

March 2024
January 2024
December 2023
August 2023
March 2023
December 2022
November 2022
August 2022
May 2022
March 2022
February 2022
December 2021
November 2021
October 2021
September 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
December 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
May 2017
April 2017
March 2017
February 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
2006
2005
2004
2003
2002
2001
2000
1999
1998


JiscMail is a Jisc service.

View our service policies at https://www.jiscmail.ac.uk/policyandsecurity/ and Jisc's privacy policy at https://www.jisc.ac.uk/website/privacy-notice

For help and support help@jisc.ac.uk

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager