dot-build_deriv_qp: Build Derivative QP Constraints in Full P-Dimensional Space

.build_deriv_qpR Documentation

Build Derivative QP Constraints in Full P-Dimensional Space

Description

Internal helper that constructs the Amat / bvec pair enforcing derivative sign constraints at every row of a block-diagonal design matrix.

Given an N_{\mathrm{sub}} \times P block-diagonal design matrix X_block, where P = p \times (K+1), this function:

  1. Recovers the per-partition p-column expansion matrix C_qp and records each row's partition assignment.

  2. Calls make_derivative_matrix on C_qp to obtain first or second derivative matrices with respect to each predictor.

  3. Optionally selects only derivatives for a subset of predictor variables (target_vars).

  4. Maps each derivative row into the full P-dimensional coefficient space, yielding one constraint column per (observation, variable) pair.

The result is a constraint pair \mathbf{A}^{\top}\boldsymbol{\beta} \ge \mathbf{b} (with \mathbf{b} = \mathbf{0}) suitable for solve.QP.

Usage

.build_deriv_qp(
  X_block,
  sign_mult,
  just_first,
  p_expansions,
  K,
  colnm_expansions,
  power1_cols,
  power2_cols,
  nonspline_cols,
  interaction_single_cols,
  interaction_quad_cols,
  triplet_cols,
  include_2way_interactions,
  include_3way_interactions,
  include_quadratic_interactions,
  expansion_scales,
  target_vars = NULL,
  og_cols = NULL,
  obs_map = NULL,
  constraint_type = NULL,
  obs_order = NULL
)

Arguments

X_block

Numeric matrix, N_{\mathrm{sub}} \times P. Block-diagonal design matrix for the QP-selected observations.

sign_mult

Numeric scalar, +1 for positive constraints or -1 for negative constraints.

just_first

Logical. If TRUE, constrain first derivatives; if FALSE, constrain second derivatives.

p_expansions

Integer. Number of basis expansions per partition.

K

Integer. Number of interior knots (partitions minus 1).

colnm_expansions

Character vector of length p_expansions. Column names of the expansion matrix.

power1_cols

Integer vector of linear-term column indices.

power2_cols

Integer vector of quadratic-term column indices.

nonspline_cols

Integer vector of non-spline linear column indices.

interaction_single_cols

Integer vector of linear-by-linear interaction column indices.

interaction_quad_cols

Integer vector of linear-by-quadratic interaction column indices.

triplet_cols

Integer vector of three-way interaction column indices.

include_2way_interactions

Logical switch forwarded to make_derivative_matrix.

include_3way_interactions

Logical switch forwarded to make_derivative_matrix.

include_quadratic_interactions

Logical switch forwarded to make_derivative_matrix.

expansion_scales

Numeric vector of length p_expansions - 1. Passed as unit scales (1 + 0 * expansion_scales) so that the constraint matrix stays on the expansion-standardized coefficient scale.

target_vars

Optional. Integer vector of predictor column indices or character vector of predictor names identifying which predictors to constrain. When NULL (default), all derivative variables are constrained.

og_cols

Optional character vector of original predictor column names, used to resolve character target_vars to integer indices.

obs_map

Optional parsed qp_observations map. In keyed mode, derivative rows are filtered per variable using constraint_type and obs_order.

constraint_type

Optional character scalar naming the current derivative constraint, for example "qp_negative_derivative".

obs_order

Optional integer vector of original observation indices, one per row of X_block.

Value

A list with components:

Amat

P \times M constraint matrix, where M is the number of unique constraint columns (after deduplication).

bvec

Numeric vector of length M, all zeros.

meq

Integer, always 0 (inequality constraints).

See Also

process_qp, solve.QP


lgspline documentation built on Aug. 5, 2026, 1:10 a.m.