| make_matrices | R Documentation |
Build the design and the penalty matrix for models involving penalised splines based on a formula and a data set
make_matrices(formula, data, knots = NULL)
formula |
formula as used in Can also be a list of formulas, which are then processed separately. In that case, both a named list of right-side only formulas or a list of formulas with response variables can be provided. |
data |
data frame containing all the variables on the right side of the formula(s) |
knots |
optional list containing user specified knot values for each covariate to be used for basis construction.
For most bases the user simply supplies the If |
a list of class LaMa_matrices containing:
Z |
design matrix (or list of such matrices if |
S |
list of penalty matrices (with names based on the response terms of the formulas as well as the smooth terms and covariates). For tensorproduct smooths, corresponding entries are themselves lists, containing the |
pardim |
list of parameter dimensions (fixed and penalised separately) for each formula, for ease of setting up initial parameters |
coef |
list of coefficient vectors filled with zeros of the correct length for each formula, for ease of setting up initial parameters |
data |
the data frame used for the model(s) |
gam |
unfitted |
gam0 |
fitted |
knots |
knot list used in the basis construction (or named list over such lists if |
predict.LaMa_matrices for prediction design matrix construction based on the model matrices object created by this function.
data = data.frame(x = runif(100),
y = runif(100),
g = factor(rep(1:10, each = 10)))
# unvariate thin plate regression spline
modmat = make_matrices(~ s(x), data)
# univariate P-spline
modmat = make_matrices(~ s(x, bs = "ps"), data)
# adding random intercept
modmat = make_matrices(~ s(g, bs = "re") + s(x, bs = "ps"), data)
# tensorproduct of x and y
modmat = make_matrices(~ s(x) + s(y) + ti(x,y), data)
# multiple formulas at once
modmat = make_matrices(list(mu ~ s(x) + y, sigma ~ s(g, bs = "re")), data = data)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.