Build QP Constraint Matrix and Target Vector
Source:R/daly_resistance_profiles.R
build_constraint_matrix.RdConstructs the constraint matrix M and target vector v used in the simplex-constrained weighted least-squares QP:
Arguments
- profiles_enum
Tibble from
enumerate_binary_profiles(). Theprofile_deltacolumn is ignored; only the binary class columns are used.- r_marg
Named numeric vector. Marginal resistance rates, one per class. Names must match column names in
profiles_enum.- co_mat
Numeric matrix or
NULL. Square symmetric pairwise co-resistance prevalence matrix with row/column names matchingnames(r_marg).NAcells trigger independence fallback. DefaultNULL.
Value
Named list:
MNumeric matrix \((n + n(n-1)/2) \times 2^n\).
vNumeric vector of constraint targets.
constraint_namesCharacter vector labelling each row of M.
fallback_pairsCharacter vector of class pairs that used the independence fallback.
capped_pairsNamed numeric vector of pairs whose pairwise value was capped, showing original and capped values.
Details
$$\min_p \|Mp - v\|^2_W \quad \text{s.t.} \quad p \ge 0,\; \sum p = 1$$
Marginal rows: \(M_{d,\delta} = 1\) iff class \(d\) is resistant in profile \(\delta\). Pairwise rows: \(M_{d_1 d_2,\delta} = 1\) iff both classes are resistant. When a pairwise value is unavailable (too few co-tested isolates), the product of marginals (independence assumption) is substituted. Pairwise values that exceed \(\min(P(A), P(B))\) are capped.