Copy
Use the same random effect more than once in the linear predictor, optionally with a different weight each time.
Overview
A random effect is normally used once in a model. The copy component lets the same effect appear more than once in the same linear predictor, optionally with a different weight each time.
If \(u\) is a component you have already defined, a copy of it is a second component \(v\) tied to the first,
\[ v \;=\; \beta\,u \;+\; \varepsilon, \qquad \varepsilon \sim N\!\left(0,\;\tau_\varepsilon^{-1}\right), \]
where \(\tau_\varepsilon\) is fixed and very large, so the equality holds for practical purposes. The copy contributes no new field and no new precision. It adds a single scalar \(\beta\), and by default even that is fixed at one.
Setup
Six observations. Each one involves three people, drawn from a pool of three, in three different roles. The roles are recorded in the columns \(i\), \(j\) and \(k\).
The effect itself is a short vector, one entry per person:
\[ u \;=\; (u_1,\; u_2,\; u_3). \]
There are six rows but only three numbers in \(u\). For a given row, \(i\) names the person in the first role, \(j\) the second and \(k\) the third, so \(u_i\) is that row's first contribution. The same three numbers are reused across rows.
| \(r\) | \(i\) | \(j\) | \(k\) | \(u_i\) | \(u_j\) | \(u_k\) |
|---|---|---|---|---|---|---|
| 1 | 1 | 3 | 2 | \(u_1\) | \(u_3\) | \(u_2\) |
| 2 | 2 | 1 | 3 | \(u_2\) | \(u_1\) | \(u_3\) |
| 3 | 3 | 2 | 1 | \(u_3\) | \(u_2\) | \(u_1\) |
| 4 | 1 | 2 | 3 | \(u_1\) | \(u_2\) | \(u_3\) |
| 5 | 2 | 3 | 1 | \(u_2\) | \(u_3\) | \(u_1\) |
| 6 | 3 | 1 | 2 | \(u_3\) | \(u_1\) | \(u_2\) |
The left half is the data you supply. The right half is the same table read through \(u\): on row 3 the second role holds person 2, so it contributes \(u_2\).
Person 1 appears in the first role on rows 1 and 4, in the second role on rows 2 and 6, and in the third on rows 3 and 5. In every one of those six places the contribution should be the same number \(u_1\).
The Problem It Solves
We want one person effect, used in two roles. Each specification is keyed by its own column, so declaring it twice does not reuse the effect: it creates a second, independent one. Call them \(u\) and \(w\). Both are meant to describe the same quantity, the effect of a person, but the model treats them as unrelated,
\[ y_1 = \mu + u_1 + w_3, \qquad y_2 = \mu + u_2 + w_1 . \]
Person 1 now carries two different numbers, \(u_1\) in the first role and \(w_1\) in the second, with nothing tying them together. That gives six unknowns where there should be three, and no single quantity to report as the effect of person 1.
The copy component lets the second role reuse the first effect instead of creating a new one.
Specification in pyINLA
Plain Copy
{'id': 'i', 'model': 'iid'},
{'id': 'j', 'copy': 'i'},
\[ y \;=\; \mu + u_i + u_j + e \]
Written out over the six rows,
\[ \begin{aligned} y_1 &= \mu + u_1 + u_3 &\qquad y_4 &= \mu + u_1 + u_2 \\ y_2 &= \mu + u_2 + u_1 &\qquad y_5 &= \mu + u_2 + u_3 \\ y_3 &= \mu + u_3 + u_2 &\qquad y_6 &= \mu + u_3 + u_1 \end{aligned} \]
There are three unknowns, and person 1 contributes the same number in row 1 as role \(i\) and in row 2 as role \(j\). The output reports one precision, for \(i\), and no \(\beta\).
Scaled Copy
{'id': 'i', 'model': 'iid'},
{'id': 'j', 'copy': 'i', 'hyper': {'beta': {'fixed': False}}},
\[ y \;=\; \mu + u_i + \beta\,u_j + e \]
\[ y_1 = \mu + u_1 + \beta u_3, \qquad y_2 = \mu + u_2 + \beta u_1, \qquad y_3 = \mu + u_3 + \beta u_2 . \]
There are still three person effects, plus one scalar. The output adds Beta for j. The slot may be addressed as beta, b or theta1.
Several Copies of One Source
{'id': 'i', 'model': 'iid'},
{'id': 'j', 'copy': 'i', 'hyper': {'beta': {'fixed': False}}},
{'id': 'k', 'copy': 'i', 'hyper': {'beta': {'fixed': False}}},
\[ y \;=\; \mu + u_i + \beta_j\,u_j + \beta_k\,u_k + e \]
\[ y_1 = \mu + u_1 + \beta_j u_3 + \beta_k u_2 , \qquad y_2 = \mu + u_2 + \beta_j u_1 + \beta_k u_3 . \]
A source may be copied any number of times, each copy carrying its own weight.
Two Copies Sharing One Weight
{'id': 'i', 'model': 'iid'},
{'id': 'j', 'copy': 'i', 'hyper': {'beta': {'fixed': False}}},
{'id': 'k', 'copy': 'i', 'same.as': 'j'},
\[ y \;=\; \mu + u_i + \beta\left(u_j + u_k\right) + e \]
\[ y_1 = \mu + u_1 + \beta\,(u_3 + u_2), \qquad y_2 = \mu + u_2 + \beta\,(u_1 + u_3). \]
Compared with the previous case, two parameters collapse to one. Use it when the two roles are believed to scale alike. The output reports Beta for j and nothing for \(k\), which owns no parameter.
Bounds under same.as
When a copy sets same.as, the bounds declared on the referenced copy apply. A range written on the referring copy is ignored.
A Copy of a Copy
{'id': 'i', 'model': 'iid'},
{'id': 'j', 'copy': 'i', 'hyper': {'beta': {'fixed': False}}},
{'id': 'k', 'copy': 'j', 'hyper': {'beta': {'fixed': False}}},
Here \(k\) copies \(j\), not \(i\). Since \(v = \beta_j u\) and \(w = \beta_k v\), the weights compose,
\[ w \;=\; \beta_k\beta_j\,u, \qquad y_1 \;=\; \mu + u_1 + \beta_j u_3 + \beta_k\beta_j\,u_2 . \]
The weight on the third term is the product, not \(\beta_k\) alone. On simulated data with true weights \(1\), \(0.5\) and \(0.25\):
Beta for j = 0.4953 Beta for k = 0.5009
product = 0.2481
To weight the third term independently, copy the source as in Several Copies of One Source, not the copy.
Fixing the Weight
{'id': 'j', 'copy': 'i', 'fixed': True, 'initial': 1.5}
\[ y_1 = \mu + u_1 + 1.5\,u_3 \]
Nothing is estimated. This is useful when the scaling is known, or to test a value rather than infer it.
Bounding the Weight
When \(\beta\) is estimated, range=(low, high) keeps it between two values. Here \(\beta\) must stay between 0 and 2:
{'id': 'j', 'copy': 'i', 'fixed': False, 'range': (0, 2)}
The bound is enforced by a change of variable. The optimizer works with an unrestricted number \(x\), which can be any real value, and each \(x\) is converted into a \(\beta\) inside the bounds. For range=(0, 2) the conversion is \(\beta = 2/(1+e^{-x})\):
| \(x\) | \(-5\) | \(-1\) | \(0\) | \(1\) | \(5\) |
|---|---|---|---|---|---|
| \(\beta\) | 0.01 | 0.54 | 1.00 | 1.46 | 1.99 |
However far \(x\) moves, \(\beta\) never leaves the interval. The conversion depends on which bounds are given:
range | Meaning | Conversion |
|---|---|---|
| not given (default) | \(\beta\) can be any value | \(\beta = x\) |
(low, high) | \(\text{low} < \beta < \text{high}\) | \(\beta = \text{low} + \dfrac{\text{high}-\text{low}}{1+e^{-x}}\) |
(low, np.inf) | \(\beta > \text{low}\) | \(\beta = \text{low} + e^{x}\) |
(-np.inf, high) | \(\beta < \text{high}\) | not supported, refused |
A common choice is (0, np.inf), when the shared effect is known not to change sign.
Prior and starting value are on \(x\)
With a range, the prior and initial apply to \(x\), not to \(\beta\). With range=(0, 2), the default prior is centred at \(x = 1\), which is \(\beta \approx 1.46\), and 'initial': 0 starts the search at \(\beta = 1\).
How Tightly the Copy Tracks
{'id': 'j', 'copy': 'i', 'precision': 1e8}
This is \(\tau_\varepsilon\) from the opening equation, fixed at \(10^{8}\) by default. Lowering it lets \(v\) drift from \(\beta u\), which is seldom intended.
Order of Declaration
Components are sorted into dependency order before the model is assembled, so chains and forward references may be written in any order:
{'id': 'k', 'copy': 'j'}, # written before what it copies
{'id': 'j', 'copy': 'i'},
{'id': 'i', 'model': 'iid'},
What a Copy Inherits
A copy has no structure of its own. It takes the precision matrix, the dimension \(n\) and index grid, and the replicate and group layout from its source. Three consequences follow.
| What happens | Why |
|---|---|
no Precision for j is reported | the copy uses the source's |
| the copy's column is read against the source's index set | a value the source lacks has nothing to point at |
n, values, nrep, ngroup on a copy are refused | set them on the source |
A replicated or grouped source still needs the copy to name its own replicate or group column, which says which replicate or group each row of the copy belongs to.
What May Be Copied
Fourteen components: iid, rw1, rw2, ar1, ar, seasonal, besag, bym, bym2, generic0, dmatern, iidkd, clinear, cgeneric, and another copy as in A Copy of a Copy.
There are two exceptions. A linear term never becomes a field the copy could point at. An SPDE component cannot be copied because the copy would carry no projection of its own, leaving \(\beta\) unidentified.
What Is Refused
Each of the following stops before anything is fitted, rather than returning a quiet wrong answer.
copy naming a component that does not exist |
| a copy index the source does not have |
same.as naming something that is not a copy, or naming itself |
| a circular chain, where no component owns the values |
range with an infinite lower and finite upper bound |
A.local on a copy, or copying an SPDE component |
n, values, nrep or ngroup on a copy |
'model': 'copy' or 'of' in place of 'copy' |
Writing {'id': 'j', 'model': 'iid', 'copy': 'i'} is not an error, but the 'model' entry is discarded with a warning: copy is itself the model.
Reference
| Key | Default | Effect |
|---|---|---|
copy | required | component to copy |
hyper['beta'] | fixed at 1 | the weight \(\beta\) |
same.as | none | share another copy's weight |
fixed, initial | True, 1 | pin \(\beta\) |
range | unbounded | bound \(\beta\) |
precision | \(10^{8}\) | tightness of the copy |
replicate, group | none | the copy's replicate or group column, when the source has one |
weights | none | per row weights on the term |
diagonal | 0 | constant added to the diagonal |