R/coefmat.R

Defines functions coefmat

Documented in coefmat

#' Generate AR coefficient matrix
#'
#' @description Generate a tridiagonal matrix. To be used for generating blockly correlated VAR series, \code{XgenCorr}.
#'
#' @param dimension a number. Size of the matrix, should agree with the number of AR series
#' @param ondiag a number. Value of main diagonal, this represents AR coefficient within each one series
#' @param offdiag a number. Value of first diagonal above and below the main diagonal, this specifies the cross-correlation with the next neighbor series
#'
#' @return a tridiagonal matrix.
#' @export
#'
#' @examples
#' A11 <- coefmat(dimension = 3, ondiag = 0.4, offdiag = 0.15)


coefmat <- function(dimension, ondiag, offdiag){

  coefmat <- diag(ondiag, dimension)
  diag(coefmat[-1,])<-rep(offdiag, (dimension-1))
  diag(coefmat[,-1])<-rep(offdiag, (dimension-1))

  return(coefmat = coefmat)
}
yymmhaha/PackPaper1 documentation built on May 24, 2019, 8:55 a.m.