BWishart {Baldur}R Documentation

Wishart Distribution

Description

BWishart produces iid draws from the Wishart Density.

Usage

 BWishart(draws,A0,n0)

Arguments

draws Number of desired draws from the density
A0 n*n Scale Matrix
n0 degree of Freedom parameter

Details

Produces iid draws from the Wishart density. The expected value of the density is given by A0*n0. The expected value for the inverse density is given by $(A0^(-1))/(n0-k-1)$, where k is the dimension of the density.

Value

An array of dimension n*n*draws with iid draws from the Wishart density, where the last dimension is the index for the draws.

Author(s)

Kjell Nygren knygren@us.imshealth.com

Examples


### Wishart Example 

# Set Constants

n0<-20
A<-(0.5+diag(4)+matrix(0.5,4,4))/n0

# Set Number of draws

draws<-1000

# Simulate 10,000 draws 

system.time(out<-BWishart(draws,A,n0))

# Calculate and display means from draws and "known" expectation

outmean<-matrix(0,4,4)

for(i in 1:4){
   for(j in 1:4){
        outmean[i,j]<-mean(out[i,j,1:draws])
                }       
             }

outmean
A*n0

# Calculate Inverse Wishart

outvar<-array(0,c(4,4,draws))

for(k in 1:draws){
        for(i in 1:4){
           for(j in 1:4){
                outvar[1:4,1:4,k]<-solve(out[1:4,1:4,k])
                        }       
                     }
                 }

# Calculate mean, and display simulated and actual mean

outmean2<-matrix(0,4,4)

for(i in 1:4){
   for(j in 1:4){
        outmean2[i,j]<-mean(outvar[i,j,1:draws])
                }       
             }

outmean2

solve(A)/(n0-4-1)


[Package Baldur version 0.0-0 Index]