| .build_deriv_qp | R Documentation |
P-Dimensional SpaceInternal 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:
Recovers the per-partition p-column expansion matrix
C_qp and records each row's partition assignment.
Calls make_derivative_matrix on C_qp to obtain
first or second derivative matrices with respect to each predictor.
Optionally selects only derivatives for a subset of predictor
variables (target_vars).
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.
.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
)
X_block |
Numeric matrix, |
sign_mult |
Numeric scalar, |
just_first |
Logical. If |
p_expansions |
Integer. Number of basis expansions per partition. |
K |
Integer. Number of interior knots (partitions minus 1). |
colnm_expansions |
Character vector of length |
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
|
include_3way_interactions |
Logical switch forwarded to
|
include_quadratic_interactions |
Logical switch forwarded to
|
expansion_scales |
Numeric vector of length |
target_vars |
Optional. Integer vector of predictor column indices
or character vector of predictor names identifying which predictors
to constrain. When |
og_cols |
Optional character vector of original predictor column
names, used to resolve character |
obs_map |
Optional parsed |
constraint_type |
Optional character scalar naming the current
derivative constraint, for example |
obs_order |
Optional integer vector of original observation indices,
one per row of |
A list with components:
P \times M constraint matrix, where M is the
number of unique constraint columns (after deduplication).
Numeric vector of length M, all zeros.
Integer, always 0 (inequality constraints).
process_qp, solve.QP
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.