| Title: | Factor-Augmented Regression Scenarios |
|---|---|
| Description: | Provides a comprehensive framework in R for modeling and forecasting economic scenarios based on multi-level dynamic factor model. The package enables users to: (i) extract global and group-specific factors using a flexible multi-level factor structure; (ii) compute asymptotically valid confidence regions for the estimated factors, accounting for uncertainty in the factor loadings; (iii) obtain estimates of the parameters of the factor-augmented quantile regressions together with their standard deviations; (iv) recover full predictive conditional densities from estimated quantiles; (v) obtain risk measures based on extreme quantiles of the conditional densities; (vi) estimate the conditional density and the corresponding extreme quantiles when the factors are stressed. |
| Authors: | Gian Pietro Bellocca [aut, cre], Ignacio Garrón [aut], Vladimir Rodríguez-Caballero [aut], Esther Ruiz [aut] |
| Maintainer: | Gian Pietro Bellocca <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 0.8.0 |
| Built: | 2026-05-18 09:18:28 UTC |
| Source: | https://github.com/cran/FARS |
fars ObjectComputes AIC values for each quantile regression stored in a
fars object.
## S3 method for class 'fars' AIC(object, ..., k = 2)## S3 method for class 'fars' AIC(object, ..., k = 2)
object |
An object of class |
... |
Additional arguments passed to the underlying |
k |
Numeric. Penalty per parameter (default 2), as in |
A named numeric vector of AIC values, one per quantile level.
fars_result <- compute_fars(dep_variable = rnorm(100), factors = matrix(rnorm(100 * 3), ncol = 3)) AIC(fars_result)fars_result <- compute_fars(dep_variable = rnorm(100), factors = matrix(rnorm(100 * 3), ncol = 3)) AIC(fars_result)
fars ObjectComputes BIC values for each quantile regression stored in a
fars object.
The number of observations used in the BIC penalty term is computed as
periods - h, reflecting the effective sample size of the
h-step-ahead dynamic quantile regression.
## S3 method for class 'fars' BIC(object, ...)## S3 method for class 'fars' BIC(object, ...)
object |
An object of class |
... |
Additional arguments passed to the underlying |
A named numeric vector of BIC values, one per quantile level.
fars_result <- compute_fars( dep_variable = rnorm(100), factors = matrix(rnorm(100 * 3), ncol = 3), h = 1 ) BIC(fars_result)fars_result <- compute_fars( dep_variable = rnorm(100), factors = matrix(rnorm(100 * 3), ncol = 3), h = 1 ) BIC(fars_result)
fars ObjectReturns a matrix of estimated coefficients from all quantile regressions stored in a fars object.
## S3 method for class 'fars' coef(object, ...)## S3 method for class 'fars' coef(object, ...)
object |
An object of class |
... |
Additional arguments (ignored). |
A numeric matrix with one column per quantile level and one row per coefficient.
Column names correspond to quantile levels (e.g. 0.05, 0.25, ...),
and row names to coefficient names.
fars_result <- compute_fars(dep_variable = rnorm(100), factors = matrix(rnorm(100 * 3), ncol = 3)) coef(fars_result)fars_result <- compute_fars(dep_variable = rnorm(100), factors = matrix(rnorm(100 * 3), ncol = 3)) coef(fars_result)
Computes the skew-t density from a matrix of quantiles. It allows for both linear and nonlinear optimization methods.
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 )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 )
quantiles |
A matrix of quantiles. Each row represents a time observation, and each column corresponds to 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. The number of evaluation points for the estimated density (default: 512). |
random_samples |
Integer. The 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 |
nl |
Logical. If |
seed |
Optional integer to set the random seed for reproducibility. |
An object of class "fars_density", which is a list containing:
A matrix of estimated densities for each time period (rows) across estimation points (columns).
A matrix of random draws from the fitted skew-t distribution for each time period.
The optimization method used (either 'nloptr' or 'optim').
The sequence of evaluation points used to compute the density. Useful for plotting.
quantiles <- matrix(rnorm(500, mean = 0, sd = 1), nrow = 100, ncol = 5) density_result <- compute_density(quantiles, seed = 42)quantiles <- matrix(rnorm(500, mean = 0, sd = 1), nrow = 100, ncol = 5) density_result <- compute_density(quantiles, seed = 42)
Performs quantile regressions of a dependent variable on factors estimates.
compute_fars(dep_variable, factors, h = 1, edge = 0.05)compute_fars(dep_variable, factors, h = 1, edge = 0.05)
dep_variable |
Numeric vector of length T representing the dependent variable (e.g., GDP growth, inflation). |
factors |
Numeric matrix or data frame of dimension T x r, containing factor estimates. |
h |
Integer (>= 1). Lag order used in the regression (default = 1) |
edge |
Numeric value specifying the trimming amount applied to the outermost quantiles. Default is 0.05. |
An object of class fars, which is a list containing:
modelsList of five S3 quantreg::rq fitted objects named tau_0.xx.
hThe forecast horizon used.
levelsThe vector of quantile levels effectively estimated
(c(edge, 0.25, 0.50, 0.75, 1 - edge)).
.
periodsInteger. The number of fitted periods
n_factorsInteger. The number of factors included in the regression.
callThe matched function call.
set.seed(123) T <- 100; r <- 3 Y <- rnorm(T) F <- matrix(rnorm(T * r), T, r) fars_result <- compute_fars(dep_variable = Y, factors = F, h = 1, edge = 0.05)set.seed(123) T <- 100; r <- 3 Y <- rnorm(T) F <- matrix(rnorm(T * r), T, r) fars_result <- compute_fars(dep_variable = Y, factors = F, h = 1, edge = 0.05)
Computes stressed factors.
compute_stressed_factors( dep_variable, factors, ellipsoids, h = 1, qtau = 0.05, direction = c("min", "max") )compute_stressed_factors( dep_variable, factors, ellipsoids, h = 1, qtau = 0.05, direction = c("min", "max") )
dep_variable |
Numeric vector of length T representing the dependent variable (e.g., GDP growth, inflation). |
factors |
Numeric matrix or data frame of dimension T x r, containing factor estimates. |
ellipsoids |
List of matrices. Each matrix represents a stressed ellipsoid for a given time period. |
h |
Integer (>= 1). Lag order used in the regression (default = 1) |
qtau |
Numeric between 0 and 1. The quantile level used in quantile regression (default = 0.05). |
direction |
Character, either "min" or "max". Determines whether to minimize or maximize |
A numeric matrix of dimension T x r containing the stressed factors for each time period.
set.seed(42) T <- 100; r <- 3 Y <- rnorm(T) F <- matrix(rnorm(T * r), T, r) E <- replicate(T, matrix(rnorm(50 * r), nrow = 50, ncol = r), simplify = FALSE) stressed_factors <- compute_stressed_factors(Y, F, E, h = 1, qtau = 0.05, direction = "min")set.seed(42) T <- 100; r <- 3 Y <- rnorm(T) F <- matrix(rnorm(T * r), T, r) E <- replicate(T, matrix(rnorm(50 * r), nrow = 50, ncol = r), simplify = FALSE) stressed_factors <- compute_stressed_factors(Y, F, E, h = 1, qtau = 0.05, direction = "min")
This function identifies and corrects outliers in a dataset using principal component analysis (PCA). It scales the data, performs PCA, computes idiosyncratic components, and replaces values that fall outside a defined outlier threshold with the median of 5 previous values. The outlier threshold is determined using the interquartile range (IQR) method.
correct_outliers(data, r)correct_outliers(data, r)
data |
A numeric matrix or data frame where rows represent observations and columns represent variables. |
r |
An integer specifying the number of principal components to use for PCA. |
A list containing:
data |
A matrix with corrected data where outliers are replaced by the median of previous values. |
outliers |
A binary matrix (same dimensions as the input data) indicating the position of outliers. |
data <- matrix(rnorm(100), nrow = 10, ncol = 10) result <- correct_outliers(data, r = 3) corrected_data <- result$data outliers_matrix <- result$outliersdata <- matrix(rnorm(100), nrow = 10, ncol = 10) result <- correct_outliers(data, r = 3) corrected_data <- result$data outliers_matrix <- result$outliers
Constructs hyperellipsoids around MLDFM factor estimates using subsampling. These regions capture estimation uncertainty and allow for the simulation of stressed scenarios.
create_scenario(model, subsamples, alpha = 0.95, fpr = FALSE)create_scenario(model, subsamples, alpha = 0.95, fpr = FALSE)
model |
An object of class |
subsamples |
An object of class |
alpha |
Numeric. Confidence level for the hyperellipsoids (e.g., 0.95). |
fpr |
Logical. If |
An object of class fars_scenario, which is a list containing:
List of matrices defining the hyperellipsoids at each time.
Matrix of factor estimates (centers of the ellipsoids).
List of covariance matrices used to define the ellipsoids.
Number of time observations.
Number of points used to define each ellipsoid.
Confidence level for the hyperellipsoids.
Function call.
data <- matrix(rnorm(100*300), nrow = 100, ncol = 300) block_ind <- c(150, 300) global = 1 local <- c(1, 1) mldfm_result <- mldfm(data, blocks = 2, block_ind = block_ind, global = global, local = local) mldfm_subsampling_result <- mldfm_subsampling(data, blocks = 2, block_ind = block_ind, global = global, local = local, n_samples = 100, sample_size = 0.9) scenario <- create_scenario(mldfm_result, mldfm_subsampling_result, alpha = 0.95)data <- matrix(rnorm(100*300), nrow = 100, ncol = 300) block_ind <- c(150, 300) global = 1 local <- c(1, 1) mldfm_result <- mldfm(data, blocks = 2, block_ind = block_ind, global = global, local = local) mldfm_subsampling_result <- mldfm_subsampling(data, blocks = 2, block_ind = block_ind, global = global, local = local, n_samples = 100, sample_size = 0.9) scenario <- create_scenario(mldfm_result, mldfm_subsampling_result, alpha = 0.95)
Quarterly US GDP growth series used as the dependent variable in the replication.
data(dep_variable)data(dep_variable)
A time series object with 59 quarterly observations.
The original series contains quarterly GDP levels for 63 countries.
For replication, all series are converted to log-differenced annualized growth rates
(diff(log(x)) * 400). From this dataset, the U.S. series is extracted
and the first observation dropped to obtain 59 observations in total.
Replication materials of González-Rivera et al. (2024).
Generic Function to Extract Estimated Factors
factors(x, ...)factors(x, ...)
x |
An object from which to extract the estimated factors. |
... |
Additional arguments. |
A matrix of estimated factors.
mldfm ObjectExtract Estimated Factors from a mldfm Object
## S3 method for class 'mldfm' factors(x, ...)## S3 method for class 'mldfm' factors(x, ...)
x |
An object of class |
... |
Further arguments (ignored). |
A matrix containing the estimated factors.
mldfm_result <- mldfm(data = matrix(rnorm(100 * 5), 100, 5), blocks = 1, global = 2) factors(mldfm_result)mldfm_result <- mldfm(data = matrix(rnorm(100 * 5), 100, 5), blocks = 1, global = 2) factors(mldfm_result)
fars ObjectReturns a matrix of fitted values from all quantile regressions stored in a fars object.
## S3 method for class 'fars' fitted(object, ...)## S3 method for class 'fars' fitted(object, ...)
object |
An object of class |
... |
Additional arguments (ignored). |
A numeric matrix with one column per quantile level and as many rows as observations used in the fit.
fars_result <- compute_fars(dep_variable = rnorm(100), factors = matrix(rnorm(100 * 3), ncol = 3)) fitted(fars_result)fars_result <- compute_fars(dep_variable = rnorm(100), factors = matrix(rnorm(100 * 3), ncol = 3)) fitted(fars_result)
mldfm ObjectExtract Fitted Values from a mldfm Object
## S3 method for class 'mldfm' fitted(object, ...)## S3 method for class 'mldfm' fitted(object, ...)
object |
An object of class |
... |
Further arguments (ignored). |
A matrix containing the fitted values.
mldfm_result <- mldfm(data = matrix(rnorm(100 * 5), 100, 5), blocks = 1, global = 2) fitted(mldfm_result)mldfm_result <- mldfm(data = matrix(rnorm(100 * 5), 100, 5), blocks = 1, global = 2) fitted(mldfm_result)
Generic Function to Extract Distribution
get_distribution(object, ...)get_distribution(object, ...)
object |
An object from which to extract the distribution. |
... |
Additional arguments (ignored). |
A matrix containing the random draws from the fitted skew-t distribution.
fars_density_result <- compute_density( quantiles = matrix(rnorm(100 * 5), nrow = 100, ncol = 5) ) get_distribution(fars_density_result)fars_density_result <- compute_density( quantiles = matrix(rnorm(100 * 5), nrow = 100, ncol = 5) ) get_distribution(fars_density_result)
fars_density ObjectExtracts the distribution from a fars_density object.
## S3 method for class 'fars_density' get_distribution(object, ...)## S3 method for class 'fars_density' get_distribution(object, ...)
object |
An object of class |
... |
Further arguments (ignored). |
A matrix containing the random draws from the fitted skew-t distribution if available, otherwise NULL.
fars_density_result <- compute_density(quantiles = matrix(rnorm(100 * 5), nrow = 100, ncol = 5)) get_distribution(fars_density_result)fars_density_result <- compute_density(quantiles = matrix(rnorm(100 * 5), nrow = 100, ncol = 5)) get_distribution(fars_density_result)
Generic Function to Extract Ellipsoids
get_ellipsoids(x, ...)get_ellipsoids(x, ...)
x |
An object from which to extract the ellipsoids |
... |
Additional arguments. |
A list of matrices defining the ellipsoids at each time.
fars_scenario Object.Returns the list of ellipsoids from a fars_scenario object.
## S3 method for class 'fars_scenario' get_ellipsoids(x, ...)## S3 method for class 'fars_scenario' get_ellipsoids(x, ...)
x |
An object of class |
... |
Additional arguments (ignored). |
A list of matrices defining the ellipsoids at each time.
Generic Function to Extract List of MLDFMs
get_mldfm_list(x, ...)get_mldfm_list(x, ...)
x |
An object from which to extract the MLDFMs. |
... |
Additional arguments. |
A list of mldfm objects
mldfm_subsample ObjectReturns the list of all mldfm stored in a mldfm_subsample object.
## S3 method for class 'mldfm_subsample' get_mldfm_list(x, ...)## S3 method for class 'mldfm_subsample' get_mldfm_list(x, ...)
x |
An object of class |
... |
Additional arguments (ignored). |
A list of mldfm objects.
mldfm ObjectGeneric Function to Extract a Specific mldfm Object
get_mldfm_model(x, index, ...)get_mldfm_model(x, index, ...)
x |
An object from which to extract a |
index |
Integer. The position of the desired model |
... |
Additional arguments. |
A single mldfm object.
mldfm Object from a mldfm_subsample ObjectReturns the mldfm object at the specified position in a mldfm_subsample object.
## S3 method for class 'mldfm_subsample' get_mldfm_model(x, index, ...)## S3 method for class 'mldfm_subsample' get_mldfm_model(x, index, ...)
x |
An object of class |
index |
Integer. The position of the desired model (between 1 and |
... |
Additional arguments (ignored). |
A single mldfm object.
Generic Function to Extract Quantile Levels
get_quantile_levels(x, ...)get_quantile_levels(x, ...)
x |
An object from which to extract the quantile levels |
... |
Additional arguments. |
A vector of quantile levels.
fars ObjectReturns the quantile levels from an object of class fars.
## S3 method for class 'fars' get_quantile_levels(x, ...)## S3 method for class 'fars' get_quantile_levels(x, ...)
x |
An object of class |
... |
Additional arguments (ignored). |
A vector of quantile levels stored within the fars object.
fars_result <- compute_fars(dep_variable = rnorm(100), factors = matrix(rnorm(100 * 3), ncol = 3)) get_quantile_levels(fars_result)fars_result <- compute_fars(dep_variable = rnorm(100), factors = matrix(rnorm(100 * 3), ncol = 3)) get_quantile_levels(fars_result)
rq ObjectGeneric Function to Extract a Specific rq Object
get_rq_model(x, tau, ...)get_rq_model(x, tau, ...)
x |
An object from which to extract a |
tau |
Numeric scalar in (0, 1) indicating the desired quantile. |
... |
Additional arguments. |
A single rq object.
rq Object from a fars ObjectReturns the rq fit stored inside a fars object at the requested quantile.
## S3 method for class 'fars' get_rq_model(x, tau, ...)## S3 method for class 'fars' get_rq_model(x, tau, ...)
x |
An object of class |
tau |
Numeric scalar in (0, 1) indicating the desired quantile. |
... |
Additional arguments (ignored). |
A single rq object.
fars_result <- compute_fars(dep_variable = rnorm(100), factors = matrix(rnorm(100 * 3), ncol = 3)) get_rq_model(fars_result, tau = 0.05)fars_result <- compute_fars(dep_variable = rnorm(100), factors = matrix(rnorm(100 * 3), ncol = 3)) get_rq_model(fars_result, tau = 0.05)
Returns the list of covariance matrices used to construct the ellipsoids.
get_sigma_list(x, ...) get_sigma_list(x, ...)get_sigma_list(x, ...) get_sigma_list(x, ...)
x |
An object of class |
... |
Additional arguments (ignored). |
A list of covariance matrices.
A list of covariance matrices (one per period).
Monthly inflation series for 38 European countries
data(inflation_data)data(inflation_data)
A numeric matrix with 239 rows and 38 columns.
Derived from the Excel file inflation.xlsx included in inst/extdata/.
The original series contains monthly HCPI series for 38 European countries.
For replication, HCPI prices are transformed into annualized month-on-month (mom)
inflation, with each inflation series sequentially cleaned of seasonal effects and outliers
Ha, Kose, and Ohnsorge (2023)
Generic Function to Extract Factor Loadings
loadings(x, ...)loadings(x, ...)
x |
An object from which to extract the factor loadings. |
... |
Additional arguments. |
A matrix of factor loadings.
mldfm ObjectExtract Factor Loadings from a mldfm Object
## S3 method for class 'mldfm' loadings(x, ...)## S3 method for class 'mldfm' loadings(x, ...)
x |
An object of class |
... |
Further arguments (ignored). |
A matrix containing the estimated factor loadings.
mldfm_result <- mldfm(data = matrix(rnorm(100 * 5), 100, 5), blocks = 1, global = 2) loadings(mldfm_result)mldfm_result <- mldfm(data = matrix(rnorm(100 * 5), 100, 5), blocks = 1, global = 2) loadings(mldfm_result)
fars ObjectReturns the log-likelihood for a single quantile regression
stored in a fars object (selected via tau).
## S3 method for class 'fars' logLik(object, tau, ...)## S3 method for class 'fars' logLik(object, tau, ...)
object |
An object of class |
tau |
Numeric. Quantile level to select (e.g. 0.50). |
... |
Additional arguments (ignored). |
An object of class "logLik", as returned by the
underlying quantile regression model.
fars_result <- compute_fars(dep_variable = rnorm(100), factors = matrix(rnorm(100 * 3), ncol = 3)) logLik(fars_result, tau = 0.50)fars_result <- compute_fars(dep_variable = rnorm(100), factors = matrix(rnorm(100 * 3), ncol = 3)) logLik(fars_result, tau = 0.50)
Macro-financial variables used in the replication exercise.
data(mf_data)data(mf_data)
A numeric matrix with 59 rows and 519 columns.
The original dataset contains 624 variables. For replication, the first 519 variables
are selected, converted to a numeric matrix, and outliers are corrected using
the function correct_outliers(..., threshold = 5) provided in FARS.
Replication materials of González-Rivera et al. (2024).
Estimates a Multi-Level Dynamic Factor Modelfrom time series data. Supports both Single-bBlock (DFM) and hierarchical Multi-Block (MLDFM) structures with customizable factor extraction settings.
mldfm( data, blocks = 1, block_ind = NULL, global = 1, local = NULL, middle_layer = NULL, method = 0, tol = 1e-06, max_iter = 1000, center = TRUE, scale = TRUE, verbose = TRUE )mldfm( data, blocks = 1, block_ind = NULL, global = 1, local = NULL, middle_layer = NULL, method = 0, tol = 1e-06, max_iter = 1000, center = TRUE, scale = TRUE, verbose = TRUE )
data |
A numeric matrix or data frame containing the time series data. Rows represent time points; columns represent observed variables. |
blocks |
Integer. Number of blocks into which the data is divided. |
block_ind |
Integer vector. End column indices for each block. Must be of length |
global |
Integer. Number of global factors extracted from the entire dataset. |
local |
Integer vector of length |
middle_layer |
Named list. Each name is a string specifying a group of blocks (e.g., |
method |
Integer. Method used to initialize the factors: |
tol |
Numeric. The tolerance level for the residual sum of squares (RSS) minimization process. Used as a convergence criterion. |
max_iter |
Integer. The maximum number of iterations allowed for the RSS minimization process. |
center |
Logical. If |
scale |
Logical. If |
verbose |
Logical. If |
An object of class mldfm, which is a list containing:
Matrix of estimated factors.
Matrix of factor loadings.
Matrix of residuals.
Matrix of fitted values.
Initialization method used (CCA or PCA).
Number of iterations before convergence.
List of estimated factors for each node.
Function call.
mldfm_result <- mldfm(data = matrix(rnorm(100 * 5), 100, 5), blocks = 1, global = 2)mldfm_result <- mldfm(data = matrix(rnorm(100 * 5), 100, 5), blocks = 1, global = 2)
Applies the MLDFM estimation to randomly drawn subsamples of the input data.
mldfm_subsampling( data, blocks = 1, block_ind = NULL, global = 1, local = NULL, middle_layer = NULL, method = 0, tol = 1e-06, max_iter = 1000, center = TRUE, scale = TRUE, n_samples = 10, sample_size = 0.9, seed = NULL )mldfm_subsampling( data, blocks = 1, block_ind = NULL, global = 1, local = NULL, middle_layer = NULL, method = 0, tol = 1e-06, max_iter = 1000, center = TRUE, scale = TRUE, n_samples = 10, sample_size = 0.9, seed = NULL )
data |
A numeric matrix or data frame containing the time series data. Rows represent time points; columns represent observed variables. |
blocks |
Integer. The number of blocks into which the data is divided. |
block_ind |
A vector of integers indicating the end index of each block. Must be of length |
global |
Integer. Number of global factors extracted from the entire dataset. |
local |
Integer vector of length |
middle_layer |
Named list. Each name is a string specifying a group of blocks (e.g., |
method |
Integer. The method used to initialize the factors: |
tol |
Numeric. The tolerance level for the residual sum of squares (RSS) minimization process. Used as a convergence criterion. |
max_iter |
Integer. The maximum number of iterations allowed for the RSS minimization process. |
center |
Logical. If |
scale |
Logical. If |
n_samples |
Number of subsamples to generate. |
sample_size |
Proportion of the original sample to retain (e.g., 0.9 for 90%). |
seed |
Optional integer. Seed for reproducibility of the subsampling process. If |
An object of class mldfm_subsample, which is a list containing:
models: A list of mldfm objects, one for each subsample.
n_samples: Number of subsamples generated.
sample_size: Proportion of the sample used for each subsample.
seed: Seed used for random sampling (if any).
call: Function call.
data <- matrix(rnorm(1000), nrow = 100, ncol = 100) block_ind <- c(50,100) local <- c(1, 1) result <- mldfm_subsampling(data, blocks = 2, block_ind = block_ind, global = 1, local = local, n_samples = 100, sample_size = 0.9)data <- matrix(rnorm(1000), nrow = 100, ncol = 100) block_ind <- c(50,100) local <- c(1, 1) result <- mldfm_subsampling(data, blocks = 2, block_ind = block_ind, global = 1, local = local, n_samples = 100, sample_size = 0.9)
fars ObjectGenerates a line plot of the estimated quantiles from a fars object.
If newdata is NULL, the function plots in-sample fitted quantiles; otherwise,
it plots predictions computed on newdata. The x-axis can be indexed by a provided
dates vector; if missing, an integer index is used.
## S3 method for class 'fars' plot(x, newdata = NULL, dates = NULL, ...)## S3 method for class 'fars' plot(x, newdata = NULL, dates = NULL, ...)
x |
An object of class |
newdata |
Optional matrix or data frame with one column for the lagged dependent variable
and |
dates |
Optional vector of dates (as |
... |
Additional arguments (ignored). |
Invisibly returns a ggplot object.
fars_density ObjectPlots the evolution of the estimated density over time as a 3D surface.
## S3 method for class 'fars_density' plot(x, time_index = NULL, ...)## S3 method for class 'fars_density' plot(x, time_index = NULL, ...)
x |
An object of class |
time_index |
Optional vector for the time axis (default is 1:nrow). |
... |
Additional arguments (ignored). |
fars_scenario ObjectPlots the hyperellipsoid for a given time observation (only for 1D or 2D cases).
## S3 method for class 'fars_scenario' plot(x, obs = 1, ...)## S3 method for class 'fars_scenario' plot(x, obs = 1, ...)
x |
An object of class |
obs |
Integer. Time index to plot (default = 1). |
... |
Additional arguments (ignored). |
Dispatches to specific plot functions for factors, loadings, or residuals.
## S3 method for class 'mldfm' plot( x, which = "factors", dates = NULL, var_names = NULL, flip = NULL, fpr = FALSE, ... )## S3 method for class 'mldfm' plot( x, which = "factors", dates = NULL, var_names = NULL, flip = NULL, fpr = FALSE, ... )
x |
An object of class |
which |
What to plot: one of |
dates |
Optional vector of dates (as |
var_names |
Optional vector of variable names to label loadings and residual axis. |
flip |
Optional vector of length equal to the number of factors. Set 1 to flip sign for a specific factor (and related loadings); 0 to leave unchanged. |
fpr |
Logical. If |
... |
Additional arguments (ignored) |
No return value. Called for plots generation.
mldfm_subsample ObjectPlots a histogram of the number of iterations used in each subsample estimation.
## S3 method for class 'mldfm_subsample' plot(x, ...)## S3 method for class 'mldfm_subsample' plot(x, ...)
x |
An object of class |
... |
Additional arguments (ignored). |
A ggplot object (invisibly).
fars ObjectComputes predictions from all quantile regressions in a fars object.
newdata must contain (in this order) the lagged dependent variable column
followed by the factor columns. Column names are generated internally as
LagY, F1, F2, ..., Fr.
## S3 method for class 'fars' predict(object, newdata, ...)## S3 method for class 'fars' predict(object, newdata, ...)
object |
An object of class |
newdata |
A matrix or data frame with one column for the lagged dependent variable
and |
... |
Additional arguments (ignored). |
A numeric matrix with one column per quantile level and one row per observation in newdata.
fars ObjectPrints a short summary of the fars object.
## S3 method for class 'fars' print(x, ...)## S3 method for class 'fars' print(x, ...)
x |
An object of class |
... |
Additional arguments (ignored). |
The input fars object, returned invisibly.
fars_density ObjectDisplays a brief summary of the fars_density object.
## S3 method for class 'fars_density' print(x, ...)## S3 method for class 'fars_density' print(x, ...)
x |
An object of class |
... |
Additional arguments (ignored). |
The input fars_density object, invisibly.
fars_scenario ObjectPrints a short summary of the FARS scenario object.
## S3 method for class 'fars_scenario' print(x, ...)## S3 method for class 'fars_scenario' print(x, ...)
x |
An object of class |
... |
Additional arguments (ignored). |
The input fars_scenario object, invisibly.
mldfm ObjectPrints a short summary of the MLDFM object.
## S3 method for class 'mldfm' print(x, ...)## S3 method for class 'mldfm' print(x, ...)
x |
An object of class |
... |
Additional arguments (ignored). |
The input mldfm object, invisibly.
mldfm_subsample ObjectPrints a brief summary of the mldfm_subsample object.
## S3 method for class 'mldfm_subsample' print(x, ...)## S3 method for class 'mldfm_subsample' print(x, ...)
x |
An object of class |
... |
Additional arguments (ignored). |
The input object object, invisibly.
fars_density ObjectComputes the conditional quantile (e.g., 5th percentile) from a simulated skew-t distribution, The result corresponds to the risk measure (e.g., Growth-at-Risk, Growth-in-Stress etc.).
quantile_risk(density, qtau = 0.05)quantile_risk(density, qtau = 0.05)
density |
An object of class |
qtau |
A numeric value between 0 and 1 indicating the quantile to extract (e.g., 0.05 for the 5th percentile). Default is 0.05. |
A numeric vector of conditional quantiles (one observation for each time period).
quantiles <- matrix(rnorm(500), ncol = 5) fars_density <- compute_density(quantiles, seed = 42) GaR <- quantile_risk(fars_density, qtau = 0.05)quantiles <- matrix(rnorm(500), ncol = 5) fars_density <- compute_density(quantiles, seed = 42) GaR <- quantile_risk(fars_density, qtau = 0.05)
fars ObjectReturns a matrix of residuals from all quantile regressions stored in a fars object.
## S3 method for class 'fars' residuals(object, ...)## S3 method for class 'fars' residuals(object, ...)
object |
An object of class |
... |
Additional arguments (ignored). |
A numeric matrix with one column per quantile level and as many rows as observations used in the fit.
fars_result <- compute_fars(dep_variable = rnorm(100), factors = matrix(rnorm(100 * 3), ncol = 3)) residuals(fars_result)fars_result <- compute_fars(dep_variable = rnorm(100), factors = matrix(rnorm(100 * 3), ncol = 3)) residuals(fars_result)
mldfm ObjectExtract Residuals from a mldfm Object
## S3 method for class 'mldfm' residuals(object, ...)## S3 method for class 'mldfm' residuals(object, ...)
object |
An object of class |
... |
Further arguments (ignored). |
A matrix containing the residuals.
mldfm_result <- mldfm(data = matrix(rnorm(100 * 5), 100, 5), blocks = 1, global = 2) residuals(mldfm_result)mldfm_result <- mldfm(data = matrix(rnorm(100 * 5), 100, 5), blocks = 1, global = 2) residuals(mldfm_result)
fars ObjectDisplays summaries of all quantile regressions stored in a fars object.
## S3 method for class 'fars' summary(object, ...)## S3 method for class 'fars' summary(object, ...)
object |
An object of class |
... |
Additional arguments (ignored). |
The input fars object, returned invisibly.
fars_density ObjectDisplays a complete summary of the fars_density object.
## S3 method for class 'fars_density' summary(object, ...)## S3 method for class 'fars_density' summary(object, ...)
object |
An object of class |
... |
Additional arguments (ignored). |
The input fars_density object, invisibly.
fars_scenario ObjectProvides a detailed summary of the FARS scenario object.
## S3 method for class 'fars_scenario' summary(object, ...)## S3 method for class 'fars_scenario' summary(object, ...)
object |
An object of class |
... |
Additional arguments (ignored). |
The input fars_scenario object, invisibly.
mldfm ObjectProvides a complete summary of the MLDFM object.
## S3 method for class 'mldfm' summary(object, ...)## S3 method for class 'mldfm' summary(object, ...)
object |
An object of class |
... |
Additional arguments (ignored). |
The input mldfm object, invisibly.
mldfm_subsample ObjectProvides a structured summary of a mldfm_subsample object.
## S3 method for class 'mldfm_subsample' summary(object, ...)## S3 method for class 'mldfm_subsample' summary(object, ...)
object |
An object of class |
... |
Additional arguments (ignored). |
The input object object, invisibly.