Skip to content

Matrices with names

In the app: Help → Help contents, Matrices with names.

A Matrix keeps names for its rows and columns, so matrix algebra checks that they meet: A @ B needs A's columns to be B's rows, in the same order, and a mistake in ordering is an error rather than a wrong number. The usual functions are methods (A.T, A.inv(), A.pinv(), A.chol(), A.power(2), A.svd(), A.eig(), A.kron(B)) or Matrix's (Matrix.cov(fit), Matrix.var_lag(var, 1), Matrix.lyapunov(F, Q), Matrix.hcat(A, B)).

In the app, Model > Matrix makes a named matrix as a step: from an expression in that syntax, using the session's objects by name ((X.T @ X).inv() @ X.T @ y); from a fit's coefficients or covariance matrix, a VAR's lag matrix or error covariance, a dataset's series over a span, or a formula's regressors and dependent variable; or from numbers typed or pasted from Excel into a grid, with names for the rows and columns. A matrix window's Matrix menu transposes, inverts, factors (Cholesky, lower or upper) and decomposes it (SVD, eigenvalues, QR, LU, Schur), raises it to a power and solves the Lyapunov equation X = A X A' + Q, each as a new named matrix; it also copies the matrix as LaTeX (a bmatrix, or a table with the names), CSV or tab-separated text, and exports it to Excel. A fitted result's right-click menu in the workspace offers it As matrix.

Each step records one line, name = expression, which the script runs to give the same matrix; it is recomputed when the objects it uses change. The expression is checked before it runs: names, attribute access, calls, operators, indexing and literals only; imports, lambda, attributes starting with an underscore and anything that reads or writes files are refused. The dialog checks it as you type, showing the problem (and keeping OK disabled) or, when it is cheap to compute, the result's shape and names. The user guide's section on matrices covers the methods in full.

See also

References