SigmaVARPlot: Psi-Plot: Plot of Psi / SigmaVAR

View source: R/SigmaVAR-plot.R

SigmaVARPlotR Documentation

Psi-Plot: Plot of Psi / SigmaVAR

Description

This function makes a plot of Psi(DeltaT) / SigmaVAR(DeltaT), the residual covariance matrix of the discrete-time model, for a range of time intervals based on its underlying drift matrix. There is also an interactive web application on my website to create a Phi-plot: Phi-and-Psi-Plots and Find DeltaT (https://www.uu.nl/staff/RMKuiper/Websites%20%2F%20Shiny%20apps).

Usage

SigmaVARPlot(
  DeltaT = 1,
  Phi = NULL,
  SigmaVAR = NULL,
  Drift = NULL,
  Sigma = NULL,
  Gamma = NULL,
  AddGamma = 1,
  Stand = 0,
  Min = 0,
  Max = 10,
  Step = 0.05,
  WhichElements = NULL,
  Labels = NULL,
  Col = NULL,
  Lty = NULL,
  Title = NULL
)

Arguments

DeltaT

Optional. The time interval used. By default, DeltaT = 1.

Phi

Matrix of size q times q of (un)standardized lagged effects of the first-order discrete-time vector autoregressive (DT-VAR(1)) model. It also takes a fitted object from the classes "varest" (from the VAR() function in vars package) and "ctsemFit" (from the ctFit() function in the ctsem package); see example below. From such an object, the (standardized) Phi/Drift and SigmaVAR/Sigma matrices are calculated/extracted.

SigmaVAR

Residual covariance matrix of the first-order discrete-time vector autoregressive (DT-VAR(1)) model.

Drift

Optional (either Phi or Drift). Underling first-order continuous-time lagged effects matrix (i.e., Drift matrix) of the discrete-time lagged effects matrix Phi(DeltaT).

Sigma

Optional (either SigmaVAR, Sigma, or Gamma). Residual covariance matrix of the first-order continuous-time (CT-VAR(1)) model, that is, the diffusion matrix.

Gamma

Optional (either SigmaVAR, Sigma, or Gamma). Stationary covariance matrix, that is, the contemporaneous covariance matrix of the data. Note that if Phi and SigmaVAR (or Drift and Sigma) are known, Gamma can be calculated; hence, only one out of SigmaVAR, Sigma, and Gamma is needed as input.

AddGamma

Optional. Indicator (0/1) for including horizontal lines at the values for Gamma in the plot. By default, AddGamma = 1. Note that SigmaVAR converges to Gamma, so the time-interval dependent curves of SigmaVAR will converge for large time-intervals to the Gamma-lines.

Stand

Optional. Indicator for whether Phi (or Drift) and SigmaVAR (or Sigma) should be standardized (1) or not (0). By default, Stand = 0.

Min

Optional. Minimum time interval used in the Phi-plot. By default, Min = 0.

Max

Optional. Maximum time interval used in the Phi-plot. By default, Max = 10.

Step

Optional. The step-size taken in the time intervals. By default, Step = 0.05. Hence, using the defaults, the Phi-plots is based on the values of Phi(DeltaT) for DeltaT = 0, 0.05, 0.10, ..., 10. Note: Especially in case of complex eigenvalues, this step size should be very small (then, the oscillating behavior can be seen best).

WhichElements

Optional. Matrix of same size as Drift denoting which element/line should be plotted (1) or not (0). By default, WhichElements = NULL. Note that even though not all lines have to be plotted, the full Phi/Drift and Sigma(VAR)/Gamma matrices are needed to determine the selected lines.

Labels

Optional. Vector with (character) labels of the lines to be plotted. The length of this vector equals the number of 1s in WhichElements (or equals q*(q+1)/2). Note, if AddGamma = 1, then twice this number is needed. By default, Labels = NULL, which renders labels with Greek letter of SigmaVAR (as a function of the time-interval); and, if AddGamma, also for Gamma.

Col

Optional. Vector with color values (integers) of the lines to be plotted. The length of this vector equals the number of 1s in WhichElements (or equals q*(q+1)/2, the unique elements in the symmetric matrix SigmaVAR). By default, Col = NULL, which renders the same color for effects that belong to the same outcome variable (i.e. a row in the SigmaVAR matrix). See https://www.statmethods.net/advgraphs/parameters.html for more information about the values.

Lty

Optional. Vector with line type values (integers) of the lines to be plotted. The length of this vector equals the number of 1s in WhichElements (or equals q*(q+1)/2). By default, Lty = NULL, which renders solid lines for the variances and the same type of dashed line for the covariances. See https://www.statmethods.net/advgraphs/parameters.html for more information about the values.

Title

Optional. A character or a list consisting of maximum 3 character-strings or 'expression' class objects that together represent the title of the Phi-plot. By default, Title = NULL, then the following code will be used for the title: as.list(expression(Sigma[VAR](Delta[t])~plot), "How do the VAR(1) (co)variance parameters vary", "as a function of the time-interval").

Value

This function returns a Psi/SigmaVAR-plot for a range of time intervals.

Examples


# library(CTmeta)

### Make Psi-plot/SigmaVAR-plot ###

## Example 1 ##

# Phi(DeltaT)
DeltaT <- 1
Phi <- myPhi[1:2,1:2]
q <- dim(Phi)[1]
SigmaVAR <- diag(q) # for ease
#
# or
Drift <- myDrift
q <- dim(Drift)[1]
Sigma <- diag(q) # for ease. Note that this is not the CT-equivalent of SigmaVAR.

# Example 1.1: unstandardized Phi&SigmaVAR #
#
# Make plot of SigmaVAR (3 examples):
SigmaVARPlot(DeltaT, Phi, SigmaVAR)
SigmaVARPlot(DeltaT, Phi, SigmaVAR, Min = 0, Max = 10, Step = 0.01)                # Specifying range x-axis and precision
SigmaVARPlot(DeltaT, Drift = Drift, Sigma = Sigma, Min = 0, Max = 10, Step = 0.01) # Using Drift&Sigma instead of Phi&SigmaVAR


# Example 1.2: standardized Phi&SigmaVAR #
SigmaVARPlot(DeltaT, Phi, SigmaVAR, Stand = 1)


## Example 2: input from fitted object of class "varest" ##

DeltaT <- 1
data <- myData
if (!require("vars")) install.packages("vars")
library(vars)
out_VAR <- VAR(data, p = 1)

# Example 2.1: unstandardized Phi #
SigmaVARPlot(DeltaT, out_VAR)

# Example 2.2: standardized Phi #
SigmaVARPlot(DeltaT, out_VAR, Stand = 1)


## Example 3: Change plot options ##
DeltaT <- 1
Phi <- myPhi[1:2,1:2]
q <- dim(Phi)[1]
SigmaVAR <- diag(q) # for ease
#
WhichElements <- matrix(1, ncol = q, nrow = q) # Now, all elements are 1
diag(WhichElements) <- 0 # Now, the covariances are excluded by setting the diagonals to 0.
Lab <- c("12", "21")
LabelsS <- NULL
LabelsG <- NULL
for(i in 1:length(Lab)){
 e <- bquote(expression(Sigma[VAR](Delta[t])[.(Lab[i])]))
 LabelsS <- c(LabelsS, eval(e))
 e <- bquote(expression(Gamma[.(Lab[i])]))
 LabelsG <- c(LabelsG, eval(e))
}
Labels <- c(LabelsS, LabelsG)
Col <- c(1,2,1,2)
Lty <- c(1,2,1,2)
# Standardized Phi and SigmaVAR
SigmaVARPlot(DeltaT, Phi, SigmaVAR, Stand = 1, Min = 0, Max = 10, Step = 0.05, WhichElements = WhichElements, Labels = Labels, Col = Col, Lty = Lty)


rebeccakuiper/CTmeta documentation built on Oct. 17, 2023, 7:01 a.m.