mgcv's gam and its
siblings to fit models of the general form
$E(Y_i(t)) = g(\mu(t) + \int X_i(s)\beta(s,t)ds +
f(z_{1i}, t) + f(z_{2i}) + z_{3i} \beta_3(t) + \dots$
)
with a functional (but not necessarily continuous)
response $Y(t)$, response function $g$,
(optional) smooth intercept $\mu(t)$, (multiple)
functional covariates $X(t)$ and scalar covariates
$z_1$, $z_2$, etc.pffr(formula, yind, fitter = NA, method = "REML", tensortype = c("te", "t2"),
bs.yindex = list(bs = "ps", k = 5, m = c(2, 1)),
bs.int = list(bs = "ps", k = 20, m = c(2, 1)), ...)formula contains an ff-term which
"REML"-estimation,
including of unknown scale. See gam
for details.list(bs="ps", k=5, m=c(2, 1)), i.e. 5
cubic B-splines bases with first order difference
penalty.list(bs="ps", k=20, m=c(2, 1)), i.e.
20 cubic B-splines bases with first order difference
penalty.pffr-object, which is a
gam-object with some additional
information in an pffr-entry. If fitter is
"gamm" or "gamm4", only the $gam
part of the returned list is modified in this way.formulasimply as~s(z1)),~c(s(z2)), or$\beta_2 z_{2i}$, specified as~c(z2)),~z3),~ff(X, yindex=t, xindex=s), seeff).c()-notation to denote model terms that
are constant over the index of the functional
response.
Internally, univariate smooth terms without a
c()-wrapper are expanded into bivariate smooth
terms in the original covariate and the index of the
functional response. Bivariate smooth terms (s(),
te() or t2()) without a c()-wrapper are
expanded into trivariate smooth terms in the original
covariates and the index of the functional response.
Linear terms for scalar covariates or categorical
covariates are expanded into varying coefficient terms,
varying smoothly over the index of the functional
response. For factor variables, a separate smooth
function with its own smoothing parameter is estimated
for each level of the factor.
Functional random
intercepts $B_{0g(i)}(t)$ for a grouping variable
g can be specified via ~s(g, bs="re")),
functional random slopes $u_i B_{1g(i)}(t)$ in a
numeric variable u via ~s(g, u,
bs="re")).
The marginal spline basis used for the
index of the the functional response is specified via the
global argument bs.yindex. If necessary, this can
be overriden for any term by supplying a
bs.yindex-argument, e.g. ~s(x,
bs.yindex=list(bs="tp", k=7) would yield a tensor
product spline for which the marginal basis for the index
of the response are 7 cubic thin-plate spline
functions.
Use ~-1 + c(1) + ... to specify a
model with only a constant and no functional intercept.
The functional response and functional covariates have to
be supplied as n by mgcv for tensor product terms whose
marginal terms include the index of the functional
response $t$. Instead, $\sum_i \hat f(z_i, x_i,
t) = 0$ for all $t$ is enforced, so that effects
varying over $t$ can be interpreted as deviations
from the global functional intercept. I recommend using
centered scalar covariates for terms like $z
\beta(t)$ (~z) and centered functional covariates
with $\sum_i X_i(t) = 0$ for all $t$ in
ff-terms so that the global functional intercept
can be interpreted as the global mean function.