Learn R Programming

mombf (version 3.5.4)

marginalNIW: Marginal likelihood under a multivariate Normal likelihood and a conjugate Normal-inverse Wishart prior.

Description

The argument z can be used to specify cluster allocations. If left missing then the usual marginal likelihood is computed, else it is computed conditional on the clusters (this is equivalent to the product of marginal likelihoods across clusters)

Usage

marginalNIW(x, xbar, samplecov, n, z, g,  mu0=rep(0,ncol(x)),
nu0=ncol(x)+4, S0, logscale=TRUE)

Value

If z is missing the integrated likelihood under a Normal-IW prior. If z was specified then the product of integrated likelihoods across clusters

Arguments

x

Data matrix (individuals in rows, variables in columns). Alternatively you can leave missing and specify xbar, samplecov and n instead

xbar

Either a vector with column means of x or a list where each element corresponds to the column means for each cluster

samplecov

Either the sample covariance matrix cov(x) or a list where each element contains the covariance for each clsuter

n

Either an integer indicating the sample size nrow(x) or a vector indicating the cluster counts table(z)

z

Optional argument specifying cluster allocations

g

Prior dispersion parameter for mu

mu0

Prior mean for mu

nu0

Prior degrees of freedom for Sigma

S0

Prior scale matrix for Sigma, by default set to I/nu0

logscale

set to TRUE to get the log-posterior density

Author

David Rossell

Details

The function computes

p(x)= int p(x | mu,Sigma) p(mu,Sigma) dmu dSigma

where p(x[i])= N(x[i]; mu,Sigma) iid i=1,...,n

p(mu | Sigma)= N(mu; mu0, g Sigma) p(Sigma)= IW(Sigma; nu0, S0)

See Also

dpostNIW for the posterior Normal-IW density.

Examples

Run this code
#Simulate data
x= matrix(rnorm(100),ncol=2)

#Integrated likelihood under correct model
marginalNIW(x,g=1,nu0=4,log=FALSE)

#Integrated likelihood under random cluster allocations
z= rep(1:2,each=25)
marginalNIW(x,z=z,g=1,nu0=4,log=FALSE)

Run the code above in your browser using DataLab