This class produces a smooth for each combination of the levels of the supplied factor variables. s(fac,x,bs="sz")
produces a smooth of x
for each level of fac
, for example. The smooths are constrained to represent deviations from the main effect smooth, so that models such as
$$g(\mu_i) = f(x_i) + f_{k(i)}(x_i)$$
can be estimated in an identifiable manner, where \(k(i)\) indicates the level of some factor that applies for the ith observation. Identifiability in this case is ensured by constraining the coefficients of the splines representing the \(f_{k}\). In particular if \(\beta_{ki}\) is the ith coefficient of \(f_k\) then the constraints are \(\sum_k \beta_{ki} = 0\).
Such sum to zero constraints are implemented using sum to zero contrasts: identity matrices with an extra row of -1s appended. Consider the case of a single factor first. The model matrix corresponding to a smooth per factor level is the row tensor product (see tensor.prod.model.matrix
) of the model matrix for the factor, and the model matrix for the smooth. The contrast matrix is then the Kronecker product of the sum to zero contrast for the factor, and an identity matrix of dimension determined by the number of coefficients of the smooth.
If there are multiple factors then the overall model matrix is the row Kronecker product of all the factor model matrices and the smooth, while the contrast is the Kronecker product of all the sum-to-zero contrasts for the factors and a final identity matrix. Notice that this construction means that the main effects (and any interactions) of the factors are included in the factor level dependent smooths. In other words the individual smooths are not each centered. This means that adding main effects or interactions of the factors will lead to a rank deficient model.
The terms can have a smoothing parameter per smooth, or a single smoothing parameter for all the smooths. The latter is specified by giving the smooth term an id
. e.g. s(fac,x,bs="sz",id=1)
.
The basis for the smooths can be selected by supplying a list as the xt
argument to s
, with a bs
item. e.g. s(fac,x,xt=list(bs="cr"))
selectes the "cr"
basis. The default is "tp"
The plot method for this class has two schemes. scheme==0
is in colour, while scheme==1
is black and white. Currently it only works for 1D smooths.