PhiPlot: Phi-plot of Phi based on its underlying drift matrix This...

View source: R/Phi-plot.R

PhiPlotR Documentation

Phi-plot of Phi based on its underlying drift matrix This function makes a Phi-plot of Phi(DeltaT) 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).

Description

Phi-plot of Phi based on its underlying drift matrix This function makes a Phi-plot of Phi(DeltaT) 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

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

Arguments

DeltaT

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

Phi

Matrix of size q times q of (un)standardized lagged effects. Note that the Phi (or Drift) matrix should be standardized to make a fair comparison between cross-lagged effects. 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) Drift matrix is calculated/extracted.

Drift

Optional (either Phi or Drift). Underlying continuous-time lagged effects matrix (i.e., Drift matrix) of the discrete-time lagged effects matrix Phi(DeltaT). By default, input for Phi is used; only when Phi = NULL, Drift will be used.

Stand

Optional. Indicator for whether Phi (or Drift) should be standardized (1) or not (0). In case Stand = 1, one of the following matrices should be input as well: SigmaVAR, Sigma, or Gamma (or it is subtracted from a varest or ctsemFit object). By default, Stand = 0.

SigmaVAR

Optional (if Stand = 1, then either SigmaVAR, Sigma, or Gamma needed). Residual covariance matrix of the first-order discrete-time vector autoregressive (DT-VAR(1)) model.

Sigma

Optional (if Stand = 1, then either SigmaVAR, Sigma, or Gamma needed). 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.

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 Drift matrix is 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). By default, Labels = NULL, which renders labels with Greek letter of Phi (as a function of the time interval) together with the indices (of outcome and predictor variables).

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). By default, Col = NULL, which renders the same color for effects that belong to the same outcome variable (i.e. a row in the Drift 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). By default, Lty = NULL, which renders solid lines for the autoregressive effects and the same type of dashed line for reciprocal effects (i.e., same type for Phi_ij as for Phi_ji). 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(Phi(Delta[t])~plot), "How do the lagged parameters vary", "as a function of the time interval?").

MaxMinPhi

Optional. An indicator (TRUE/FALSE) whether vertical lines for the optimum (maximum or minimum) should be added to the plot (TRUE) or not (FALSE). These values are obtained by the function MaxDeltaT(). By default, MaxMinPhi = FALSE; hence, by default, no vertical lines are added.

Value

This function returns a Phi-plot for a range of time intervals.

Examples


# library(CTmeta)

### Make Phi-plot ###

## Example 1 ##

# Phi(DeltaT)
DeltaT <- 1
Phi <- myPhi[1:2,1:2]
# or: Drift
Drift <- myDrift

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


# Example 1.2: standardized Phi #
q <- dim(Phi)[1]
SigmaVAR <- diag(q) # for ease
PhiPlot(DeltaT, Phi, Stand = 1, SigmaVAR = SigmaVAR)
#
# Including minimum or maximum of Phi
PhiPlot(DeltaT, Phi, Stand = 1, SigmaVAR = SigmaVAR, MaxMinPhi = TRUE)


## 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 #
PhiPlot(DeltaT, out_VAR)

# Example 2.2: standardized Phi #
PhiPlot(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 autoregressive parameters are excluded by setting the diagonals to 0.
Lab <- c("12", "21")
Labels <- NULL
for(i in 1:length(Lab)){
 e <- bquote(expression(Phi(Delta[t])[.(Lab[i])]))
 Labels <- c(Labels, eval(e))
}
Col <- c(1,2)
Lty <- c(1,2)
# Standardized Phi
PhiPlot(DeltaT = 1, Phi, Stand = 1, SigmaVAR = SigmaVAR, Min = 0, Max = 10, Step = 0.05, WhichElements = WhichElements, Labels = Labels, Col = Col, Lty = Lty)


rebeccakuiper/CTmeta documentation built on Nov. 2, 2024, 4:42 p.m.