Concept Architecture
What matrix multiplication does
In health economics, this operation moves cohorts between health states, combines state occupancy with costs and utilities, applies regression coefficients and evaluates many parameter sets efficiently. This page explains the dimensional rule, the element-by-element calculation, the meaning of multiplication order and the checks needed for reliable model implementation.
Matrix multiplication is not the same as multiplying corresponding cells. It represents a sequence of weighted combinations, and its validity depends on both compatible dimensions and consistent labels.
The dimensions determine whether multiplication is possible
Two matrices can be multiplied when the number of columns in the first matrix equals the number of rows in the second. These matching inner dimensions identify the categories that are combined and summed. The remaining outer dimensions determine the shape of the result.
If (A) is an (m\times n) matrix and (B) is an (n\times p) matrix, then:
The multiplication is conformable because both inner dimensions equal (n). The resulting matrix (C) has (m) rows from (A) and (p) columns from (B).
| First matrix | Second matrix | Multiplication valid? | Result |
|---|---|---|---|
| (2\times3) | (3\times4) | Yes | (2\times4) |
| (1\times3) | (3\times1) | Yes | (1\times1) scalar |
| (3\times1) | (1\times3) | Yes | (3\times3) outer product |
| (2\times3) | (2\times3) | No | Inner dimensions do not match |
| (3\times3) | (3\times1) | Yes | (3\times1) column vector |
Matching dimensions alone do not guarantee a meaningful calculation. The labels on the matched dimension must also refer to the same concepts in the same order, such as Stable, Progressed and Dead in both a state vector and a transition matrix.
Each result is a row-by-column dot product
Every element in the product is calculated by multiplying corresponding entries from one row of the first matrix and one column of the second matrix, then summing those products. This operation is a dot product embedded within the larger matrix calculation. It converts several linked contributions into one result for each row-column pairing.
For (C=AB):
The index (k) runs across row (i) of (A) and down column (j) of (B). Each (c_{ij}) therefore contains all pathways connecting that row and column through the shared dimension.
A worked numerical example
Consider a (2\times3) matrix multiplied by a (3\times2) matrix. The product will be (2\times2), and each of its four entries comes from a separate row-by-column calculation. Writing out the arithmetic makes the direction and summation rule visible.
Let:
Then:
For example, the upper-left value is 11 because it combines the first row of (A) with the first column of (B). No element of the product is obtained by simply multiplying two cells in the same position.
The order of multiplication changes the meaning
Matrix multiplication is generally not commutative. Even when both (AB) and (BA) are defined, they can have different dimensions, different values and different interpretations. The order must follow the sequence of transformations represented by the model.
In general:
Using the matrices in the worked example, (AB) is (2\times2), while (BA) is (3\times3). The products cannot be interchangeable because they describe different mappings.
Matrix multiplication is associative, so compatible products may be regrouped without changing their value:
It is also distributive over addition:
These properties can improve computational efficiency, but regrouping should preserve a transparent connection between each mathematical operation and the underlying model step.
How multiplication moves a cohort through health states
A cohort state-transition model uses matrix multiplication to redistribute patients across health states at each cycle. A state vector records the current cohort distribution, while a transition matrix records the probabilities of moving from each current state to each next state. Their product produces the distribution for the next cycle.
Under a row-vector convention:
Suppose:
and the state order is Stable, Progressed and Dead, with:
The next-cycle cohort is:
The 375 patients in the Progressed state combine 175 transitions from Stable with 200 patients remaining Progressed. This illustrates how one result column aggregates every route into the same destination state.
Row-vector and column-vector conventions cannot be mixed
The same transition process can be expressed with row vectors or column vectors. Both conventions are mathematically valid, but the transition matrix must be oriented to match the chosen convention. Mixing them can produce an invalid dimension or, more dangerously, a plausible but incorrect result after an unnoticed transpose.
| Convention | State update | Probability constraint |
|---|---|---|
| Row-vector state | (s_{t+1}=s_tP) | Each row of (P) sums to one. |
| Column-vector state | (s_{t+1}=Ps_t) | Each column of (P) sums to one when (P) is the transpose of the row-convention matrix. |
The model documentation should state the convention once and apply it throughout every cycle, reward calculation and validation test. Labels should remain attached to the matrix dimensions rather than being inferred from position alone.
Multiplication converts state occupancy into expected value
Once a model has estimated how many patients occupy each health state, matrix multiplication can attach costs, utilities or other rewards. Multiplying a state row vector by a matching reward column vector produces a scalar expected value for that cycle. This is the dot-product case of matrix multiplication.
If (c) is a state-cost vector and (u) is a state-utility vector:
For the cohort above, suppose the cycle costs are:
Then:
The result is the total cycle cost for the cohort under the stated reward convention. Per-person results, discounting, cycle length and within-cycle correction must be handled explicitly rather than assumed by the multiplication.
Matrix powers represent repeated transitions
When the same transition matrix applies in every cycle, repeated multiplication can be written as a matrix power. This is a compact representation of a time-homogeneous transition process. It should not be used when transition probabilities change with age, cycle, history or time since treatment unless those changes are incorporated into the model structure.
After (t) cycles:
The notation (P^t) means multiplying (P) by itself (t) times; it does not mean raising each element individually to power (t). Efficient software algorithms can calculate large integer powers without performing every multiplication in the most direct sequence.
For time-varying transition matrices, the update becomes an ordered product:
The order is essential because the matrices generally do not commute. Reversing them would apply cycle-specific risks in the wrong sequence.
Matrix multiplication supports regression prediction
Regression models use multiplication to combine observations with estimated coefficients. The design matrix holds the predictor values for many observations, and the coefficient vector holds the estimated effect associated with each predictor. Their product produces the linear predictor for every observation at once.
For a linear model:
If (X) contains (N) observations and (K) coefficients, then (X) is (N\times K), (\hat\beta) is (K\times1), and (\hat y) is (N\times1). The shared (K) dimension must use the same predictor order in both (X) and (\hat\beta).
In a generalised linear model, the product first produces the linear predictor:
An inverse link function then converts (\eta) to the outcome scale. Matrix multiplication performs the linear combination, while the link function and distribution determine the statistical interpretation.
Ordinary multiplication differs from element-wise multiplication
Element-wise multiplication, sometimes called the Hadamard product, multiplies corresponding entries of matrices with the same dimensions. It does not sum over a shared dimension and therefore answers a different question. Software often uses different operators for the two calculations, making this a common implementation error.
For equal-sized matrices (A) and (B), the Hadamard product is:
| Operation | Dimension rule | Calculation | Typical use |
|---|---|---|---|
| Matrix product (AB) | Columns of (A) equal rows of (B) | Row-by-column products are summed. | State transitions, regression prediction and reward aggregation |
| Hadamard product (A\circ B) | (A) and (B) have identical dimensions. | Corresponding elements are multiplied without summing. | Applying cell-specific weights or masks |
| Dot product (a^{\mathsf T}b) | Vectors have the same length. | Corresponding products are summed to one scalar. | Expected cost or utility |
| Outer product (ab^{\mathsf T}) | A column vector multiplies a row vector. | Every pair of elements is multiplied. | Constructing pairwise contribution matrices |
Common implementation errors
Matrix multiplication can return a number even when the underlying categories are incorrectly aligned. Structural validation must therefore test meaning as well as syntax. The following failures can materially change health-economic model results.
- Reordered states cause matched dimensions to combine different health states despite having compatible sizes.
- Reversed multiplication order applies transformations in the wrong sequence or changes the result's dimensions.
- An unnoticed transpose can convert a row-vector convention into a column-vector calculation without updating probability constraints.
- Element-wise multiplication in place of a matrix product removes the required summation across pathways or predictors.
- Matrix powers interpreted element by element do not represent repeated state transitions.
- Invalid transition probabilities can preserve conformable dimensions while violating non-negativity or row-sum requirements.
- Mixed units can combine counts, proportions, costs or utilities on incompatible scales.
- Premature rounding can accumulate discrepancies over many cycles or across large cohorts.
A practical validation sequence
Validation should begin with labelled dimensions and finish with reconciliation to independently calculated model outputs. A small manual example can reveal ordering and orientation errors that remain hidden in a large automated implementation. The following steps provide a reproducible minimum check.
- Write the dimensions beside every vector and matrix before performing the multiplication.
- Label the shared dimension explicitly and confirm that both operands use the same categories and order.
- State the multiplication convention for state vectors, transition matrices and reward vectors.
- Calculate at least one result element manually using the row-by-column rule.
- Reconcile transition outputs to the starting cohort total, allowing only explicitly modelled entries and exits.
- Check probability constraints and test absorbing states, zero risks and deterministic transitions.
- Distinguish matrix, element-wise, dot and outer products in both the documentation and software syntax.
- Test an independent implementation for a small model and compare every intermediate vector.
- Confirm units and timing for costs, utilities, discount factors and cycle lengths.
- Retest after any state is added, removed or reordered because every connected vector and matrix may require revision.
Matrix multiplication is reliable only when its algebra and its labels tell the same story. A conformable product confirms that the dimensions fit, but validation must confirm that the operation represents the intended clinical and economic process.
Related Concepts (3)
Library
Publications
1
Accuracy and Stability of Numerical Algorithms — Nicholas J. Higham, 2nd Edition ed., 2002 (Society for Industrial and Applied Mathematics (SIAM))
The standard reference on floating-point error, conditioning, stability and the numerical reliability of matrix, polynomial and linear-algebra algorithms.
BookView source →
Frequently Asked Questions (6)
What is matrix multiplication?
An operation that combines two compatible matrices by calculating the dot products of their rows and columns.
Source: Golub GH, Van Loan CF. Matrix Computations. 4th ed. Johns Hopkins University Press; 2013.
How does matrix multiplication combine two matrices?
Matrix multiplication combines two compatible matrices by calculating the dot products of the rows of the first with the columns of the second. Each entry of the result comes from one such dot product, pairing a row with a column. This construction of the product from row-by-column dot products is how matrix multiplication combines the two matrices Because each entry is a row-by-column dot product, the two matrices must have matching inner dimensions, and the operation underlies much of how transformations and systems are composed.
Source: Golub GH, Van Loan CF. Matrix Computations. 4th ed. Johns Hopkins University Press; 2013.
Why must matrices be compatible for matrix multiplication?
Matrices must be compatible for matrix multiplication because the operation pairs each row of the first matrix with each column of the second through a dot product, which requires the row and column to have matching lengths. If the dimensions do not align, the dot products cannot be formed. This need for compatible dimensions follows directly from how matrix multiplication is defined Because each entry is a row-by-column dot product, the two matrices must have matching inner dimensions, and the operation underlies much of how transformations and systems are composed.
Source: Golub GH, Van Loan CF. Matrix Computations. 4th ed. Johns Hopkins University Press; 2013.
What does each entry of the result come from in matrix multiplication?
In matrix multiplication, each entry of the result comes from the dot product of a row of the first matrix with a column of the second. The entry's position reflects which row and which column were combined. This origin of every entry in a single row-by-column dot product is basic to how matrix multiplication produces its result Because each entry is a row-by-column dot product, the two matrices must have matching inner dimensions, and the operation underlies much of how transformations and systems are composed.
Source: Golub GH, Van Loan CF. Matrix Computations. 4th ed. Johns Hopkins University Press; 2013.
What are the inputs to matrix multiplication?
The inputs to matrix multiplication are two compatible matrices, combined by calculating the dot products of the rows of one with the columns of the other. Their compatibility, meaning aligned dimensions, is required for the operation to proceed. Taking two such matrices as inputs is part of what defines matrix multiplication Because each entry is a row-by-column dot product, the two matrices must have matching inner dimensions, and the operation underlies much of how transformations and systems are composed.
Source: Golub GH, Van Loan CF. Matrix Computations. 4th ed. Johns Hopkins University Press; 2013.
How does matrix multiplication relate to matrix algebra?
Matrix multiplication is an operation that combines two compatible matrices through the dot products of their rows and columns, while matrix algebra is the branch of mathematics concerned with representing and manipulating matrices and the operations performed on them. Matrix multiplication is one of the operations that matrix algebra defines and studies. The two are connected as a specific operation and the field that encompasses it Because each entry is a row-by-column dot product, the two matrices must have matching inner dimensions, and the operation underlies much of how transformations and systems are composed.
Source: Golub GH, Van Loan CF. Matrix Computations. 4th ed. Johns Hopkins University Press; 2013.
Trust Record
Verified by Dr Darrin Baines
British health economist
Professional identity: darrinbaines.org
Verification date: 24 Sep 2026
Content version: 1.0.0
Canonical Identity
- Term code
- CS-LA-MO-002
Stable URI · Machine-readable · Resolvable · CC BY 4.0
