% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/get_B.R
\name{.lagrangian_project}
\alias{.lagrangian_project}
\title{Lagrangian Projection via OLS Reformulation}
\usage{
.lagrangian_project(
  GhalfXy,
  Ghalf,
  A,
  K,
  p_expansions,
  R_constraints,
  constraint_value_vectors,
  family,
  parallel_aga,
  parallel_matmult,
  cl,
  chunk_size,
  num_chunks,
  rem_chunks
)
}
\arguments{
\item{GhalfXy}{Numeric column vector \eqn{\mathbf{y}^*} of length
\eqn{P}; produced by multiplying \eqn{\mathbf{G}^{1/2}} (Path 2) or
\eqn{\mathbf{G}^{-1/2}} (Path 3) into the unconstrained estimate.}

\item{Ghalf}{List of \eqn{\mathbf{G}^{1/2}_k} matrices (one per
partition).}

\item{A}{Constraint matrix \eqn{\mathbf{A}} (\eqn{P \times R}).}

\item{K}{Integer; number of interior knots.}

\item{p_expansions}{Integer; number of basis terms per partition.}

\item{R_constraints}{Integer; number of columns of \eqn{\mathbf{A}}.}

\item{constraint_value_vectors}{List of constraint right-hand-side
vectors encoding \eqn{\mathbf{A}^{\top}\boldsymbol{\beta} =
\mathbf{c}}. When non-empty and nonzero, the particular solution is
added.}

\item{family}{GLM family object (used for \code{linkinv(0)} fallback
when \code{NA} values arise in \eqn{\mathbf{y}^*}).}

\item{parallel_aga, parallel_matmult}{Logical flags for parallel
computation.}

\item{cl}{Parallel cluster object.}

\item{chunk_size, num_chunks, rem_chunks}{Parallel distribution parameters.}
}
\value{
A list of length \eqn{K+1}, each element a column vector of
  constrained coefficients \eqn{\tilde{\boldsymbol{\beta}}_k}.
}
\description{
Given unconstrained (or GEE-initialized) coefficient estimates
\eqn{\hat{\boldsymbol{\beta}}}, computes the constrained estimate
\eqn{\tilde{\boldsymbol{\beta}} = \mathbf{U}\hat{\boldsymbol{\beta}}}
where \eqn{\mathbf{U} = \mathbf{I} - \mathbf{G}\mathbf{A}
(\mathbf{A}^{\top}\mathbf{G}\mathbf{A})^{-1}\mathbf{A}^{\top}}.
}
\details{
Rather than forming \eqn{\mathbf{U}} directly, the projection is
reformulated as a residual from an OLS problem (the
\eqn{\mathbf{G}^{1/2}\mathbf{r}^*} trick):
\deqn{\mathbf{y}^* = \mathbf{G}^{-1/2}\hat{\boldsymbol{\beta}}}
\deqn{\mathbf{X}^* = \mathbf{G}^{1/2}\mathbf{A}}
\deqn{\mathbf{r}^* = (\mathbf{I} - \mathbf{X}^*(\mathbf{X}^{*\top}
  \mathbf{X}^*)^{-1}\mathbf{X}^{*\top})\mathbf{y}^*}
\deqn{\tilde{\boldsymbol{\beta}} = \mathbf{G}^{1/2}\mathbf{r}^*}

This avoids explicitly forming and inverting
\eqn{\mathbf{A}^{\top}\mathbf{G}\mathbf{A}}; the most expensive step is
the QR decomposition of the \eqn{R \times R} system inside
\code{.lm.fit}, which is far cheaper than the full \eqn{P \times P}
solve.
}
\keyword{internal}
