posteriorDiscard.GaussianNIW: Update a "GaussianNIW" object with sample sufficient...

Description Usage Arguments Value References See Also Examples

View source: R/Gaussian_Inference.r

Description

For the 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.
Contrary to posterior(), this function will update (m,k,v,S) by removing the information of observed samples x. The model structure and prior parameters are stored in a "GaussianNIW" object, the prior parameters in this object will be updated after running this function.

Usage

1
2
## S3 method for class 'GaussianNIW'
posteriorDiscard(obj, ss, w = NULL, ...)

Arguments

obj

A "GaussianNIW" object.

ss

Sufficient statistics of x. In Gaussian-NIW case the sufficient statistic of sample x is a object of type "ssGaussian", it can be generated by the function sufficientStatistics().

w

Sample weights,default NULL.

...

Additional arguments to be passed to other inherited types.

Value

None. the gamma stored in "obj" will be updated with the information in "ss".

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,posterior.GaussianNIW

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
## generate some random Gaussian samples
x <- rGaussian(1000,mu = c(1,1),Sigma = matrix(c(1,0.5,0.5,3),2,2))
w <- runif(1000)
## add information to 'obj' then remove them one by one
obj <- GaussianNIW(gamma=list(m=c(0.2,3),k=1,v=2,S=diag(2)))
ss <- sufficientStatistics_Weighted(obj = obj,x=x,w=w,foreach = TRUE)
for(i in 1L:length(ss)) posterior(obj = obj,ss=ss[[i]])
obj
for(i in 1L:length(ss)) posteriorDiscard(obj = obj,ss=ss[[i]])
obj
## add information to 'obj' then remove them as a whole
obj <- GaussianNIW(gamma=list(m=c(0.2,3),k=1,v=2,S=diag(2)))
ssAll <- sufficientStatistics_Weighted(obj = obj,x=x,w=w,foreach = FALSE)
posterior(obj = obj,ss = ssAll)
obj
posteriorDiscard(obj = obj,ss = ssAll)
obj

bbricks documentation built on July 8, 2020, 7:29 p.m.