Last chance! 50% off unlimited learning
Sale ends in
Generate the the density value of the posterior predictive distribution of the following structure:
?dNIW
and dGaussian
for the definitions of these distribution.
The model structure and prior parameters are stored in a "GaussianNIW" object.
Posterior predictive density is p(x|m,k,v,S).
# S3 method for GaussianNIW
dPosteriorPredictive(obj, x, LOG = TRUE, ...)
A "GaussianNIW" object.
matrix, or the ones that can be converted to matrix, each row of x is an observation.
Return the log density if set to "TRUE".
Additional arguments to be passed to other inherited types.
A numeric vector of the same length as nrow(x), the posterior predictive density.
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).
GaussianNIW
, dPosteriorPredictive.GaussianNIW
, marginalLikelihood.GaussianNIW
# NOT RUN {
x <- rGaussian(1000,mu = c(1,1),Sigma = matrix(c(1,0.5,0.5,3),2,2))
obj <- GaussianNIW(gamma=list(m=c(0,0),k=1,v=2,S=diag(2)))
## out1 and out2 it should have the same values:
out1 <- dPosteriorPredictive(obj = obj, x = x,LOG = TRUE)
out2 <- numeric(nrow(x))
for(i in 1:nrow(x))
out2[i] <- marginalLikelihood(obj,x=x[i,,drop=FALSE],LOG = TRUE)
max(abs(out1-out2))
# }
Run the code above in your browser using DataLab