View source: R/biv.norm.post.R
biv.norm.post | R Documentation |
A function to calculate posterior quantities of the bivariate normal. See page 94.
biv.norm.post(data.mat,alpha,beta,m,n0=5)
data.mat |
A matrix with two columns of normally distributed data |
alpha |
Wishart first (scalar) parameter |
beta |
Wishart second (matrix) parameter |
m |
prior mean for mu |
n0 |
prior confidence parameter |
Returns
mu2 |
posterior mean, dimension 1 |
sig1 |
posterior mean, dimension 2 |
sig2 |
posterior variance, dimension 1 |
rho |
posterior variance, dimension 2 |
Jeff Gill
rwishart <- function(df, p = nrow(SqrtSigma), SqrtSigma = diag(p)) { if((Ident <- missing(SqrtSigma)) && missing(p)) stop("either p or SqrtSigma must be specified") Z <- matrix(0, p, p) diag(Z) <- sqrt(rchisq(p, df:(df-p+1))) if(p > 1) { pseq <- 1:(p-1) Z[rep(p*pseq, pseq) + unlist(lapply(pseq, seq))] <- rnorm(p*(p-1)/2) } if(Ident) crossprod(Z) else crossprod(Z %*% SqrtSigma) } data.n10 <- rmultinorm(10, c(1,3), matrix(c(1.0,0.7,0.7,3.0),2,2)) rep.mat <- NULL; reps <- 1000 for (i in 1:reps){ rep.mat <- rbind(rep.mat, biv.norm.post(data.n10,3, matrix(c(10,5,5,10),2,2),c(2,2))) } round(normal.posterior.summary(rep.mat),3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.