Skip to content

applyCorrelationMatrix

Performs the mathematical operation \(\sqrt{\symbf{D}\symbf{C}\symbf{D}^T}\) for each time step, where \(\symbf{C}\) is a square matrix containing correlation coefficients, like

\[ \symbf{C} = \begin{bmatrix} c_{1,1} & c_{1,2} & \cdots & c_{1,N} \\ c_{2,1} & c_{2,2} & \cdots & c_{2,N} \\ \vdots & \vdots & \ddots & \vdots \\ c_{N,1} & c_{N,2} & \cdots & c_{N,N} \end{bmatrix} \]

and \(\symbf{D}\) is a row vector containing the data at the current time step

\[ \symbf{D} = \begin{bmatrix} d_{1} & d_{2} & \cdots & d_{N} \end{bmatrix} \]

and \(N\) is the number of variables.

This produces a scalar for each time step:

\[ \begin{align*} & \sqrt{\symbf{D}\symbf{C}\symbf{D}^T} \\ &= \sqrt{ \begin{bmatrix} d_{1} & d_{2} & \cdots & d_{N} \end{bmatrix} \begin{bmatrix} c_{1,1} & c_{1,2} & \cdots & c_{1,N} \\ c_{2,1} & c_{2,2} & \cdots & c_{2,N} \\ \vdots & \vdots & \ddots & \vdots \\ c_{N,1} & c_{N,2} & \cdots & c_{N,N} \end{bmatrix} \begin{bmatrix} d_{1} \\ d_{2} \\ \vdots \\ d_{N} \end{bmatrix} } \\ &= \sqrt{ d_{1} \left(c_{1,1} d_{1} + c_{2,1} d_{2} + \cdots + c_{N,1} d_{N}\right) + d_{2} \left(c_{1,2} d_{1} + c_{2,2} d_{2} + \cdots + c_{N,2} d_{N}\right) + \cdots + d_{N} \left(c_{1,N} d_{1} + c_{2,N} d_{2} + \cdots + c_{N,N} d_{N}\right) } \end{align*} \]

The results are written to a new table, and the name of the table is returned.

Signature and arguments

applyCorrelationMatrix(
    correlationMatrixTableName,
    dataMatrixTableName
)
correlationMatrixTableName
The name of the table containing the correlation matrix \(\symbf{C}\). The header is ignored.
dataMatrixTableName
The name of the table containing the data matrix where each row represents an instance of \(\symbf{D}\) at a specific time step. The variableMatrix() function is well suited here.

Examples

See the example workbook.

Using tables from the model

You may use tables that already exist on the model (e.g. in the inputs workbook):

applyCorrelationMatrix(table("TableCorr1"), table("TableData1"))

The table() function ensures that the tables are copied to the output workbook, where the calculation is performed.

Using a variable matrix

Since applyCorrelationMatrix simply requires two table names, and variableMatrix() returns such a name, you can use it directly to apply a correlation matrix to variables from the current projection node:

applyCorrelationMatrix(table("TableCorr1"), variableMatrix("VarA", "VarB", "VarC"))

Using tables from CSV

The csvToTable() function also returns a table name, and can therefore also be used directly inside applyCorrelationMatrix:

applyCorrelationMatrix(csvToTable("correlation.csv"), csvToTable("data.csv"))