Learn R Programming

bbricks (version 0.1.4)

sufficientStatistics_Weighted.GaussianNIW: Weighted sufficient statistics for a "GaussianNIW" object

Description

For following Gaussian-NIW model structure: $$mu,Sigma|m,k,v,S \sim NIW(m,k,v,S)$$ $$x|mu,Sigma \sim Gaussian(mu,Sigma)$$ Where NIW() is the Normal-Inverse-Wishart distribution, Gaussian() is the Gaussian distribution. See ?dNIW and dGaussian for the definitions of these distribution. The sufficient statistics of a set of samples x (each row of x is a sample) and weights w are:

  • the effective number of samples N=sum(w)

  • the sample sum xsum = colSums(x*w)

  • the uncentered scatter matrix S = t(w*x)

Usage

# S3 method for GaussianNIW
sufficientStatistics_Weighted(obj, x, w, foreach = FALSE, ...)

Arguments

obj

A "GaussianNIW" object.

x,

matrix, Gaussian samples, when x is a matrix, each row is a sample of dimension ncol(x). when x is a vector, x is length(x) samples of dimension 1.

w

numeric, sample weights.

foreach

logical, if foreach=TRUE, will return a list of sufficient statistics for each row of x, otherwise will return the sufficient statistics of x as a whole.

...

Additional arguments to be passed to other inherited types.

Value

If foreach=TRUE, will return a list of sufficient statistics for each row of x, otherwise will return the sufficient statistics of x as a whole.

References

Murphy, Kevin P. "Conjugate Bayesian analysis of the Gaussian distribution." def 1.22 (2007): 16.

Gelman, Andrew, et al. "Bayesian Data Analysis Chapman & Hall." CRC Texts in Statistical Science (2004).

See Also

GaussianNIW, sufficientStatistics.GaussianNIW

Examples

Run this code
# NOT RUN {
x <- rGaussian(10,mu = c(-1.5,1.5),Sigma = matrix(c(0.1,0.03,0.03,0.1),2,2))
obj <- GaussianNIW()                    #an GaussianNIW object
w <- runif(10)
sufficientStatistics_Weighted(obj=obj,x=x,w=w,foreach = FALSE)
sufficientStatistics_Weighted(obj=obj,x=x,w=w,foreach = TRUE)
# }

Run the code above in your browser using DataLab