Mathematical Notation
We try to use a consistent notation in equations throughout the manuscript, which we try to explain as we go. For the sake of clarity we have outlined everything here.
General rules
Small letters (e.g. \(x\)) denote scalars
Bold, small letters (e.g. \(\boldsymbol{x}\)) denote vectors
Capital letters (e.g. \(X\)) denote matrices
Letter/Symbol | Usage |
---|---|
\(\sigma\) | standard deviation |
\(\Sigma\) | covariance matrix |
\(\sigma_{x_1x_2}\) | covariance between variables x1 and x2 |
\(\mu\) | mean |
\(\epsilon\) | residual |
\(\beta\) | slope |
\(x\) | predictor variable |
\(y\) | response variable |
Notation for a linear mixed model
There are several ways to write out an equation for a linear model. First we can write out all the different variables:
\(y_i = \beta_0 + \beta_1 x_{1,i} + \beta_2 x_{2,i} + \beta_3 x_{3,i} + \epsilon_i\)
where each observation (denoted by the index \(i\)) of our response variable (\(y_i\)) is the sum of an intercept (\(\beta_0\); value of the response when the predictor variables are all 0), the associated value of our predictor variables (\(x_{1i}\), \(x_{2i}\), \(x_{3i}\); which also vary at the level of the observation), each with a certain magnitude and direction of their effect (effect size or slope; \(\beta_1\) etc), and some unexplained, residual variation (\(\epsilon_i\)).
We can also write this in matrix notation:
\(\boldsymbol{y} = X\boldsymbol{\beta} + \boldsymbol{\epsilon}\)
where \(X\) is a matrix of predictors and \(\boldsymbol{\beta}\) is a (column) vector of slopes/effect sizes. This matrix notation is a bit more compact and relates most easily the structure of the simulate_population()
function. However it becomes more complex when we have things varying at different levels, as we have to start getting design matrices for the random effects involved e.g.
\(\boldsymbol{y} = X\boldsymbol{\beta} + Z\boldsymbol{u} + \boldsymbol{\epsilon}\)
which we would rather avoid here as it has little relation to the squidSim code.
We can therefore combine the index and matrix notation. This is maybe a little more complex, but it’s compact and flexible and relates well to the simulate_population()
function.
\(y_{i} = \beta_0 + \boldsymbol{x}_{i} \boldsymbol{\beta} + \epsilon_{i}\)
where \(\boldsymbol{x}_{i}\) is the \(i\)th row of \(X\). I have deliberately separated the intercept (\(\beta_0\)) out here, for the purpose of comparing with the structure of simulate_population()
. Then for models that have predictors vary at different levels we can have
\(y_{ij} = \beta_0 + \boldsymbol{x}_{i} \boldsymbol{\beta}_x + \boldsymbol{u}_j \boldsymbol{\beta}_u + \epsilon_{ij}\)
Instead of having predictors at different levels, we might have ‘random effects’
\(y_{ij} = \beta_0 + \boldsymbol{x}_{i} \boldsymbol{\beta}_x + u_j + \epsilon_{ij}\)
at multiple levels
\(y_{ijk} = \beta_0 + \boldsymbol{x}_{i} \boldsymbol{\beta}_x + u_j + w_k + \epsilon_{ijk}\)
Distributions
We can write distribution equations as:
\(x_{1i} \sim \mathcal{N}(\mu, \sigma^2)\)
or
\(\boldsymbol{x}_i \sim \mathcal{N}(\boldsymbol{\mu}_x, \Sigma_x)\)
Interactions / Random regression
\(y_{ij} = \beta_0 + \beta_1x_{i} + u_{1j} + x_{i}u_{2j} + \epsilon_{ij}\)
\(x_{i} \sim \mathcal{N}(\mu_x, \sigma^2_x)\)
\(\boldsymbol{u}_j \sim \mathcal{N}(0, \Sigma_u)\)
\(\epsilon_{ij} \sim \mathcal{N}(0, \sigma^2_{\epsilon})\)
Multi-response
\(\boldsymbol{y}_{ij} = \boldsymbol{\beta}_0 + \boldsymbol{x}_{i} B_x + \boldsymbol{u}_j + \boldsymbol{\epsilon}_{ij}\)
\(\boldsymbol{x}_i \sim \mathcal{N}(\boldsymbol{\mu}_x, \Sigma_x)\)
\(\boldsymbol{u}_j \sim \mathcal{N}(0, \Sigma_u)\)
\(\boldsymbol{\epsilon}_{ij} \sim \mathcal{N}(0, \Sigma_{\epsilon})\)
where \(\boldsymbol{\beta}_0\) is a vector of intercepts of length q (number of responses) \(B\) is a \(p*q\) (p - number of predictors) matrix of \(\beta\)s