## Main effects

\[ \begin{aligned} \mu_{\boldsymbol{s},t} &= f^{-1} \left( \boldsymbol{X}^{\mathrm{main}}_{\boldsymbol{s},t} \boldsymbol{\beta} \ldots \right) \end{aligned} \]

Within `sdmTMB()`

, \(\boldsymbol{X}^{\mathrm{main}}_{\boldsymbol{s},t}
\boldsymbol{\beta}\) is defined by the `formula`

argument and represents the main-effect model matrix and a corresponding
vector of coefficients. This main effect formula can contain optional
penalized smoothers or non-linear functions as defined below.

### Smoothers

Smoothers in sdmTMB are implemented with the same formula syntax
familiar to mgcv (Wood 2017) users fitting
GAMs (generalized additive models). Smooths are implemented in the
formula using `+ s(x)`

, which implements a smooth from
`mgcv::s()`

. Within these smooths, the same syntax commonly
used in `mgcv::s()`

can be applied, e.g. 2-dimensional
smooths may be constructed with `+ s(x, y)`

; smooths can be
specific to various factor levels, `+ s(x, by = group)`

;
smooths can vary according to a continuous variable,
`+ s(x, by = x2)`

; the basis function dimensions may be
specified, e.g. `+ s(x, k = 4)`

(see
`?mgcv::choose.k`

); and various types of splines may be
constructed such as cyclic splines to model seasonality,
e.g. `+ s(month, bs = "cc", k = 12)`

.

While mgcv can fit unpenalized (e.g., B-splines) or penalized splines
(P-splines), sdmTMB only implements penalized splines. The penalized
splines are constructed in sdmTMB using the function
`mgcv::smooth2random()`

, which transforms splines into random
effects (and associated design matrices) that are estimable in a
mixed-effects modelling framework. This is the same approach as is
implemented in the R packages gamm4 (Wood &
Scheipl 2020) and brms (Bürkner
2017).

### Linear break-point threshold models

The linear break-point or “hockey stick” model can be used to describe threshold or asymptotic responses. This function consists of two pieces, so that for \(x < b_{1}\), \(s(x) = x \cdot b_{0}\), and for \(x > b_{1}\), \(s(x) = b_{1} \cdot b_{0}\). In both cases, \(b_{0}\) represents the slope of the function up to a threshold, and the product \(b_{1} \cdot b_{0}\) represents the value at the asymptote. No constraints are placed on parameters \(b_{0}\) or \(b_{1}\).

These models can be fit by including `+ breakpt(x)`

in the
model formula, where `x`

is a covariate. The formula can
contain a single break-point covariate.

### Logistic threshold models

Models with logistic threshold relationships between a predictor and the response can be fit with the form

\[ s(x)=\tau + \psi\ { \left[ 1+{ e }^{ -\ln \left(19\right) \cdot \left( x-s50 \right) / \left(s95 - s50 \right) } \right] }^{-1}, \]

where \(s\) represents the logistic function, \(\psi\) is a scaling parameter (controlling the height of the y-axis for the response; unconstrained), \(\tau\) is an intercept, \(s50\) is a parameter controlling the point at which the function reaches 50% of the maximum (\(\psi\)), and \(s95\) is a parameter controlling the point at which the function reaches 95% of the maximum. The parameter \(s50\) is unconstrained but \(s95\) is constrained to be larger than \(s50\).

These models can be fit by including `+ logistic(x)`

in
the model formula, where `x`

is a covariate. The formula can
contain a single logistic covariate.