Description Usage Arguments Details
Return the design matrix of a spline, and objects such as the penalty matrix that are required for running the spline fitting engine (bayes_ridge_semi). For the time being, the only supported basis is 'B-spline'. The design matrix is transformed such that the model can be fitted as a linear mixed-effect models.
1 2 3 4 5 6 7 8 |
x |
a numeric vector of the design points. |
by |
a grouping variable and must be a factor. Vectors of length one are expanded to 'length(x)'. Use a dummy variable, e.g. as.factor(1), if there is only one group. |
knots |
the number of internal knots. |
degree |
the degree of spline. |
type |
the type of basis function. Currently only B-spline ('bs') is supported. |
is_sub |
is this the subject-specific curves? |
The 'by' argument specifies the factor variable that interacts with the 'x' covariate. Basically, this means that whether we should have a spline for each level of the factor. If there should not be any interaction, we can specify a dummy factor variable, e.g. as.factor(1).
This function is unlikely to be called by the users directly but rather by the fitting routine.
# Working assumption
## Non-subject-specific splines The polynomial coeffcients have a flat prior, whereas the rest have a zero-mean independent Gaussian prior. This implies that the splines are shrunk to the polynomial of degree 'degree'. Since the polynomial space (which includes an intercept) spanned by a spline are not penalised, the intercept term is removed to avoid spanning the same space as the (possible) main effect terms and resulting in an unidentifiable model. This usually means that the users should fit the intercepts as fixed main effects. For example, if you have 's(x1, by = b1)', then you should have something like 'y ~ b1' as you fixed (main effect) term.
## Subject-specific splines All regression coefficients are penalised towards 0, i.e. has a zero-mean Gaussian prior. Intercept is included. Due to the LMM parameterisation of B-spline basis, the first 'degree + 1' coefficients of the subject-specific spline are Gaussian with a full covariance matrix. The rest of the coefficients are independent Gaussian.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.