Learn R Programming

lgspline (version 0.2.0)

get_2ndDerivPenalty: Compute Integrated Squared Second Derivative Penalty Matrix for Smoothing Splines

Description

Generates a penalty matrix representing the integrated squared second derivatives for smoothing spline basis functions, which controls the smoothness of the fitted curve.

Usage

get_2ndDerivPenalty(
  colnm_expansions,
  C,
  power1_cols,
  power2_cols,
  power3_cols,
  power4_cols,
  interaction_single_cols,
  interaction_quad_cols,
  triplet_cols,
  nc,
  select_cols = NULL
)

Value

A symmetric \(p \times p\) penalty matrix \(\textbf{P}\) representing integrated squared second derivatives for basis expansions in a single partition of the smoothing spline.

Arguments

colnm_expansions

Character vector of column names for basis expansions

C

Numeric matrix of basis expansions

power1_cols

Indices of linear term columns

power2_cols

Indices of quadratic term columns

power3_cols

Indices of cubic term columns

power4_cols

Indices of quartic term columns

interaction_single_cols

Indices of single interaction columns

interaction_quad_cols

Indices of quadratic interaction columns

triplet_cols

Indices of triplet interaction columns

nc

Number of cubic expansions

select_cols

Optional vector of column indices to penalize (default: all linear terms)

Details

This function computes the analytic form of the traditional integrated, squared, second-derivative evaluated over the bounds of the input data. If \(f(x) = \textbf{X}\boldsymbol{\beta}\), then the penalty is based on \(\int \{ f''(x) \}^2 dx = \boldsymbol{\beta}^{T}(\int \textbf{X}''^{T}\textbf{X}'' dx)\boldsymbol{\beta}\). This function computes the matrix \(\textbf{P} = \int \textbf{X}''^{T}\textbf{X}'' dx\). When scaled by a non-negative scalar (wiggle penalty, predictor penalties and/or partition penalties), this becomes the smoothing spline penalty.