MVN_GibbsSampler: Gibbs sampler for MVN distribution

Description Usage Arguments Details Value See Also Examples

Description

Generating random vectors on the basis of a given MVN distribution, through Gibbs sampling algorithm.

Usage

1
2
3
4
5
# Bayesian posteriori as data
# data <- MVN_BayesianPosteriori(dataset1)

# Using Gibbs sampler to generate random vectors based on Bayesian posteriori:
MVN_GibbsSampler(n, data, initial, reject_rate, burn)

Arguments

n

A positive integer. The numbers of random vectors to be generated.

data

A double level list which contains the mean vector (data$mean) and the covariance matrix (data$var) of a given MVN distribution.

initial

Initial vector where Markov chain starts. Default value use a random vector generated by rmvnorm().

reject_rate

A numeric to control burn-in period by ratio. Default value is 0.2, namely the first 20% generated vectors will be rejected. If this arg was customized, the next arg burn should maintain the default value.

burn

A numeric to control burn-in period by numbers. If this arg was customized, final result will be generated by this manner in which it will drop the first n numbers (n=burn).

Details

There're also some literatures suggest using the mean or mode of priori as initial vector. Users can customize this setting according to their own needs.

Value

return a series random vectors in the basis of given MVN distribution.

See Also

MVN_FConditional, MatrixAlternative

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
library(mvtnorm)

# Get parameters of Bayesian posteriori multivariate normal distribution
BPos <- MVN_BayesianPosteriori(dataset1)
BPos

# Using previous result (BPos) to generate random vectors through Gibbs
# sampling: 7000 observations, start from c(1,1,2), use 0.3 burning rate
BPos_Gibbs <- MVN_GibbsSampler(7000, BPos, initial=c(1,1,2), 0.3)
tail(BPos_Gibbs)

# Check for convergence of Markov chain
BPos$mean
colMeans(BPos_Gibbs)
BPos$var
var(BPos_Gibbs)

# 3d Visulization:
library(rgl)
fac1 <- BPos_Gibbs[,1]
fac2 <- BPos_Gibbs[,2]
fac3 <- BPos_Gibbs[,3]
plot3d(x=fac1, y=fac2, z=fac3, col="red", size=2)

CubicZebra/MVNBayesian documentation built on May 17, 2019, 2:14 a.m.