Skip to contents

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(df, scale, inv = FALSE)

Arguments

x

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

df

[integer()]
The degrees of freedom greater of equal 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?

Value

For dwishart(): The density value.

For rwishart(): A matrix, the random draw.

See also

Examples

x <- diag(2)
df <- 4
scale <- diag(2)

# compute density
dwishart(x = x, df = df, scale = scale)
#> [1] 0.01463746
dwishart(x = x, df = df, scale = scale, log = TRUE)
#> [1] -4.224171
dwishart(x = x, df = df, scale = scale, inv = TRUE)
#> [1] 0.01463746

# sample
rwishart(df = df, scale = scale)
#>            [,1]       [,2]
#> [1,]  0.2546863 -0.2105463
#> [2,] -0.2105463  0.5544923
rwishart(df = df, scale = scale, inv = TRUE)
#>           [,1]      [,2]
#> [1,]  1.975689 -1.064355
#> [2,] -1.064355  2.152786