samps_to_scens: Generate multivariate forecasts

View source: R/samps_to_scens.R

samps_to_scensR Documentation

Generate multivariate forecasts

Description

This function produces a list of multivariate scenario forecasts in the marginal domain from the spatial/temporal/spatiotemporal gaussian covariance matrices and marginal distributions

Usage

samps_to_scens(
  copulatype,
  no_samps,
  marginals,
  sigma_kf,
  mean_kf,
  control,
  mcmapply_cores = 1L,
  mvnfast_cores = 1L,
  chunk_dir = NULL,
  ...
)

Arguments

copulatype

As string, either "spatial" or "temporal", note that spatio-temporal can be generated via "temporal" setting.

no_samps

Number of scenarios to sample

marginals

a named list of marginal distributions, e.g. if class is MultiQR, list(<<name>> = <<MultiQR object>>). Multiple margins are possible for multiple locations (see examples) although they must be the same class (MultiQR or distribution predictions from a PPD object). If parametric class supply a list of the distribution parameters here and the corresponding quantile function in control (see below). The ordering of this list is important for multiple locations — it should be ordered according to the row/columns in each member of sigma_kf.

sigma_kf

a named list of the covariance matrices with elements corresponding to cross-validation folds.

mean_kf

a named list of the mean vectors with elements corresponding to cross-validation folds.

control

a named list of with nested control parameters (named according to marginals). Each named list should contain kfold, issue_ind, and horiz_ind which are the cross-validation folds, issue time, and lead time vectors corresponding to the margins of the copula, respectively. If margins are MultiQR class also define PIT_method and list CDFtails, which are passed to the PIT function. If the margins are distribution parameter predictions then define q_fun, which transforms the columns of marginals through the quantile function — see example for more details.

mcmapply_cores

Defaults to 1. Warning, only change if not using Windows OS — see the parallel::mcmapply help page for more info. Speed improvements possible when generating sptio-temporal scenarios, set to the number of locations if possible.

mvnfast_cores

defaults to 1. See mvnfast::rmvn

chunk_dir

a character string containing a directory for storing temporary chunked datasets per fold. Useful for very high dimensional distributions or many samples. Defaults to NULL, i.e. no chunking. Only valid for Multi.QR type marginals for now...

...

extra arguments to contCDF to be applied to all marginals.

Details

This is a sampling function for the Gaussian copula with marginals specified by MultiQR or PPD objects and user-specified covariance matrix.

Value

A list of data.table objects containing multivariate forecasts.

Note

For spatio-temporal scenarios, each site must have the same number of inputs to the governing covariance matrix.

For multiple locations the ordering of the lists of the margins & control, and the structure of the covariance matrices is very important: if the columns/rows in each covariance matrix are ordered loc1_h1, loc1_h2,..., loc2_h1, loc2_h_2,..., loc_3_h1, loc_3_h2,... i.e. location_leadtime — then the list of the marginals should be in the same order loc1, loc2, loc3,....

Ensure cross-validation fold names in the control list do not change within any issue time — i.e. make sure the issue times are unique to each fold.

Author(s)

Ciaran Gilbert, ciaran.gilbert@strath.ac.uk

Examples

## Not run: 
# for parametric type marginals with a Generalized Beta type 2 family
scens <- samps_to_scens(copulatype = "temporal",no_samps = 100,marginals = list(loc_1 = param_margins),sigma_kf = cvm,mean_kf = mean_vec,
                        control=list(loc_1 = list(kfold = loc_1data$kfold, issue_ind = loc_1data$issue_time, horiz_ind = loc_1data$lead_time,
                                                  q_fun = gamlss.dist::qGB2)))

## End(Not run)
## Not run: 
# for MQR type marginals
scens <- samps_to_scens(copulatype = "temporal",no_samps = 100,marginals = list(loc_1 = mqr_gbm_1),sigma_kf = cvm,mean_kf = mean_vec,
                        control=list(loc_1 = list(kfold = loc_1data$kfold, issue_ind = loc_1data$issue_time, horiz_ind = loc_1data$lead_time,
                                                  PIT_method = "linear",CDFtails= list(method = "interpolate", L=0,U=1))))

## End(Not run)
## Not run: 
# for spatio-temporal scenarios with MQR type marginals
scens <- samps_to_scens(copulatype = "temporal", no_samps = 100,marginals = list(loc_1 = mqr_gbm,loc_2 = mqr_gbm_2),sigma_kf = cvm_2,mean_kf = mean_vec_2,
                        control=list(loc_1 = list(kfold = loc_1data$kfold, issue_ind = loc_1data$issue_time, horiz_ind = loc_1data$lead_time,
                                                  PIT_method = "linear",CDFtails= list(method = "interpolate", L=0,U=1)),
                                     loc_2 = list(kfold = loc_2data$kfold, issue_ind = loc_2data$issue_time, horiz_ind = loc_2data$lead_time,
                                                  PIT_method = "linear", CDFtails = list(method = "interpolate", L=0, U=1))))

## End(Not run)

jbrowell/ProbCast documentation built on July 20, 2024, 1:53 p.m.