Learn R Programming

MVNBayesian (version 0.0.8-11)

MVN_BayesianPosteriori: Calculate Bayesian posteriori MVN distribution

Description

The function to export the mean vector and covariance matrix of Bayesian posteriori MVN distribution in the basis of given priori information (priori MVN) and observation data (a design matrix containing all variables).

Usage

# Given the data as design matrix, priori mean vector and priori covariance
# matrix, this function will export a list which contains mean ($mean) and
# covariance ($var) of Bayesian posteriori multivariate normal distribution.

MVN_BayesianPosteriori(data, pri_mean, pri_var)

Arguments

data

A data.frame or matrix-like data: obervations should be arrayed in rows while variables should be arrayed in columns.

pri_mean

A numeric vector to assign priori mean for MVN. Default value applies colMeans() to data.

pri_var

A matrix-like parameter to assign priori covariance matrix. Default value uses unit matrix.

Value

return a double level list containing:

mean

mean vector of Bayesian posteriori MVN distribution

var

covariance of Bayesian posteriori MVN distribution

Examples

Run this code
# NOT RUN {
# Demo using dataset1:
head(dataset1)
BPos <- MVN_BayesianPosteriori(dataset1, c(80,16,3))
BPos$mean
BPos$var

# Singular system caused by insufficient data
eigen(var(dataset1[1:3,]))$values
rcond(var(dataset1[1:3,]))
eigen(var(dataset1[1:6,]))$values
rcond(var(dataset1[1:6,]))

# Singular system caused by improper degree of freedom
K <- cbind(dataset1, dataset1[,3]*(-2)+3)
eigen(var(K[,2:4]))$values
rcond(var(K[,2:4]))
# }

Run the code above in your browser using DataLab