Learn R Programming

TFORGE (version 0.1.16)

fsm: Flat storage of symmetric matrices

Description

The TFORGE_fsm class, short for Flat Symmetric Matrices, is for storing a collection of symmetric matrices with each matrix stored as a row vector according to vech(). The TFORGE_fsm class is itself a thin wrapper of the array class. So, for example, x[1, ] will return the vectorised-form of the first matrix in the collection, and inv_vech(x[1,]) will be the first matrix in non-flat form. The TFORGE_kfsm class is for a collection of multiple TFORGE_fsm. The function as_flat() automatically converts data to either TFORGE_kfsm or TFORGE_fsm.

Usage

as_flat(x, ...)

as_kfsm(x, ...)

as_fsm(x, ...)

Value

An object with class TFORGE_kfsm or TFORGE_fsm.

Arguments

x

For as_fsm() a list of symmetric matrices, or a 2D array of flattened matrices. For as_kfsm() a list of objects that can be passed to as_fsm() (i.e. a list of a lists of matrices, or a list of 2D arrays). For as_flat(), x can be suitable for either as_fsm() or as_kfsm().

...

Passed to isSymmetric() for testing whether matrices are symmetric.

Functions

  • as_flat(): Automatically convert to either a TFORGE_kfsm or a TFORGE_fsm.

  • as_kfsm(): Convert multiple collections of matrices into a kfsm. x must be a list, with each entry of x a separate collection of matrices.

  • as_fsm(): For x a list of symmetric matrices of the same size, flattens x into a 2D array where the ith row is a vectorised version vech(x[[i]]) of the ith matrix of x. If x is already flattened then as_fsm() will check that the number of columns are consistent with a flattened symmetric matrix.

Details

The matrices inside x must all have the same dimension.

The function as_flat() automatically chooses between a TFORGE_kfsm or a TFORGE_fsm:

  • If x is a list of symmetric matrices then it will return a TFORGE_fsm.

  • If x is a list of lists of equal-sized matrices then it returns a TFORGE_kfsm, with each element of the larger list a TFORGE_fsm.

  • If x is a list of 2D arrays, each satisfying as_fsm(), then as_flat() will return a TFORGE_kfsm.

  • In the rare case that x is a list of 2D arrays of flattened matrices, but the 2D arrays happen to be perfectly symmetric (requires size of collections to perfectly relate to the dimension of the matrix observations) then as_flat() will mistakenly treat each element of x as a symmetric matrix and return a TFORGE_fsm.

Examples

Run this code
x <- list(list(matrix(c(1,2,3,2,4,5,3,5,6), 3), 
               matrix(c(2,3,4,3,5,6,4,6,7), 3)),
          list(matrix(c(0.1,0.2,0.3,0.2,0.4,0.5,0.3,0.5,0.6), 3), 
               matrix(c(0.2,0.3,0.4,0.3,0.5,0.6,0.4,0.6,0.7), 3)))
as_kfsm(x)
summary(as_flat(x))

Run the code above in your browser using DataLab