compute_density: Compute Skew-t Densities from Forecasted Quantiles

View source: R/compute_density.R

compute_densityR Documentation

Compute Skew-t Densities from Forecasted Quantiles

Description

Compute Skew-t Densities from Forecasted Quantiles

Usage

compute_density(
  quantiles,
  levels = c(0.05, 0.25, 0.5, 0.75, 0.95),
  est_points = 512,
  random_samples = 5000,
  support = c(-10, 10),
  nl = FALSE,
  seed = NULL
)

Arguments

quantiles

A matrix of forecasted quantiles. Each row is a time observation; each column a quantile level.

levels

A numeric vector of the quantile levels corresponding to the columns of the quantile matrix (default: c(0.05, 0.25, 0.50, 0.75, 0.95)).

est_points

Integer. Number of evaluation points for the estimated density (default: 512).

random_samples

Integer. Number of random samples to draw from the fitted skew-t distribution (default: 5000).

support

Numeric vector of length 2. Defines the lower and upper limits of the density evaluation range. Used with est_points to create the evaluation grid. Default: c(-30, 10).

nl

Logical. If TRUE, uses nonlinear optimization via nloptr; if FALSE, uses linear optimization via optim. Default: FALSE.

seed

Optional integer to set the random seed for reproducibility (default: NULL).

Value

An object of class "fars_density", which is a list containing the following components:

density

A matrix of estimated densities for each time period (rows) across estimation points (columns).

distribution

A matrix of random draws from the fitted skew-t distribution for each time period.

optimization

The optimization method implemented.

x_vals

The sequence of evaluation points used to compute the density. Useful for plotting.

Examples



Quantiles <- matrix(rnorm(500, mean = 0, sd = 1), nrow = 100, ncol = 5)
density_result <- compute_density(Quantiles, seed = 42)



FARS documentation built on Aug. 8, 2025, 7:33 p.m.