create_weights: Create Weight Matrices

View source: R/create_weights.R

create_weightsR Documentation

Create Weight Matrices

Description

Produces a matrix of fixed or an array of time varying country-specific weights for a GVAR model.

Usage

create_weights(weight_data, period, country_data = NULL)

Arguments

weight_data

a named list of named time-series objects or a named matrix containing data for the construction of weights. See 'Details'.

period

either an integer for time varying weights or a numeric vector specifying the number of past periods in weight_data that should be used to calculate constant weights. See 'Details'.

country_data

a named list of time-series objects containing country data. Only requried if period is an integer.

Details

The function assists in the creation of country-specific weight matrices. If a numeric vector is provided as period, the function calculates country weights based on the sums over the specified periods. If an integer is proved, the weights are constructed from rolling sums over the last period periods. If a country series begins earlier than its corresponding weight series, the sums over the first period observations of weight_data are used until the periods match.

If weight_data is a list, its elements should be time-series objects, where colums should be named after the trading partner. The names of the list elements should match the country names in country_data. If a matrix is provided, its rows should contain the name of the reference country and the columns should be named after the trading partner. All cells should contain zeros when the reference country and the trading partner are the same, i.e. row and column names are equal.

Value

A named matrix or an array containing country-specific weight matrices.

Examples

# Load data
data("gvar2019")

# Data objects
country_data <- gvar2019[["country_data"]]
weight_data <- gvar2019[["weight_data"]]

weight_data <- create_weights(weight_data = weight_data, period = 3,
                              country_data = country_data)


franzmohr/bgvars documentation built on Sept. 2, 2023, 12:45 p.m.