Learn R Programming

APRScenario (version 0.0.3.0)

plot_cond_histo: plot_cond_histo function

Description

This function uses the conditional probability calculations (eg scenarios) and plots the histogram of the selected variable

Usage

plot_cond_histo(
  variable = NULL,
  horizon = 1,
  threshold = NULL,
  data = NULL,
  above = TRUE,
  size = 5
)

Value

ggplot object (plot)

Arguments

variable

(character) Name of variable to be plotted

horizon

(numeric) At which horizon (horizon<=h)

threshold

(numeric,optional) If present compute P(x>threshold)

data

data of conditional forecasts

above

(logical,optional): if TRUE then compute probability above threshold

size

(optional) size of annotation text in the plot

Examples

Run this code
# Example with simulated conditional forecast data
# Create sample forecast data matrix
set.seed(123)
n_sims <- 500
horizons <- 3
variables <- c("GDP", "CPI", "FFR")

# Create column names in the expected format (variable.horizon)
col_names <- outer(variables, 1:horizons, paste, sep = ".")

# Generate random forecast data
forecast_data <- matrix(rnorm(n_sims * length(col_names)), 
                       nrow = n_sims, ncol = length(col_names))
colnames(forecast_data) <- as.vector(col_names)

# Plot histogram for GDP at horizon 2
p <- plot_cond_histo(data = t(forecast_data), 
                     variable = "GDP", 
                     horizon = 2,
                     threshold = 0.5, 
                     above = TRUE)

Run the code above in your browser using DataLab