Learn R Programming

LaMa (version 3.1.0)

rep_sp: Repeat initial penalty strengths for replicated smooths

Description

Expands the sp0 element of a modmat object into a sp vector for penalty or penalty2, when each smooth is used more than once, for example one spline per state or per off-diagonal element of the transition probability matrix.

Usage

rep_sp(model_matrices, N)

Value

named numeric vector of initial penalty strengths, of the length and in the order expected for sp

Arguments

model_matrices

object of class LaMa_matrices as returned by modmat

N

number of replicates. Either a single number used for every smooth, or one number per smooth, i.e. per element of model_matrices$S

Details

sp runs over replicates within each smooth, so for a tensor product the margins vary fastest. A single rep() over sp0 therefore only gives the right answer for some models, silently producing the right length but the wrong values for others. This function repeats each smooth's penalty strengths separately, which is always correct.

See Also

modmat, which computes sp0

Examples

Run this code
modmat = modmat(~ s(x) + ti(x, y), data.frame(x = runif(100), y = runif(100)))
modmat$sp0         # one value per penalty
rep_sp(modmat, 2)  # ready to use as 'sp' for two replicates of each smooth

Run the code above in your browser using DataLab