Learn R Programming

oeli (version 0.7.8)

dwishart_cpp: Wishart distribution

Description

The function dwishart() computes the density of a Wishart distribution.

The function rwishart() samples from a Wishart distribution.

The functions with suffix _cpp perform no input checks, hence are faster.

Usage

dwishart_cpp(x, df, scale, log = FALSE, inv = FALSE)

rwishart_cpp(df, scale, inv = FALSE)

dwishart(x, df, scale, log = FALSE, inv = FALSE)

rwishart(n = 1, df, scale, inv = FALSE)

Value

For dwishart(): The density value.

For rwishart(): If n = 1 a matrix of dimension p times p, else an array of dimension p times p times n with the draws as slices.

Arguments

x

[matrix()]
A covariance matrix of dimension p.

df

[numeric(1)]
The degrees of freedom, at least p.

scale

[matrix()]
The scale covariance matrix of dimension p.

log

[logical(1)]
Return the logarithm of the density value?

inv

[logical(1)]
Use this inverse Wishart distribution?

n

[integer(1)]
The number of requested samples.

See Also

Other simulation helpers: Simulator, correlated_regressors(), ddirichlet_cpp(), dmixnorm_cpp(), dmvnorm_cpp(), dtnorm_cpp(), gaussian_tv(), simulate_markov_chain()

Examples

Run this code
x <- diag(2)
df <- 6
scale <- matrix(c(1, -0.3, -0.3, 0.8), ncol = 2)

# compute density
dwishart(x = x, df = df, scale = scale)
dwishart(x = x, df = df, scale = scale, log = TRUE)
dwishart(x = x, df = df, scale = scale, inv = TRUE)

# sample
rwishart(df = df, scale = scale)
rwishart(df = df, scale = scale, inv = TRUE)

# expectation of Wishart is df * scale
apply(rwishart(n = 100, df = df, scale = scale), 1:2, mean)
df * scale

# expectation of inverse Wishart is scale / (df - p - 1)
apply(rwishart(n = 100, df = df, scale = scale, inv = TRUE), 1:2, mean)
scale / (df - 2 - 1)

Run the code above in your browser using DataLab