% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/likelihood-multiphase.R
\name{.hzr_conserve_events}
\alias{.hzr_conserve_events}
\title{Apply the Conservation of Events adjustment to one phase's log_mu}
\usage{
.hzr_conserve_events(
  theta,
  fixmu_phase,
  fixmu_pos,
  time,
  status,
  phases,
  covariate_counts,
  x_list,
  total_events,
  weights = NULL,
  time_lower = NULL
)
}
\arguments{
\item{theta}{Full parameter vector (internal scale).}

\item{fixmu_phase}{Character: name of the phase whose log_mu is solved.}

\item{fixmu_pos}{Integer: position of that log_mu in theta.}

\item{time}{Numeric vector of follow-up times.}

\item{status}{Numeric event indicator.}

\item{phases}{Named list of validated \code{hzr_phase} objects.}

\item{covariate_counts}{Named integer vector.}

\item{x_list}{Named list of per-phase design matrices.}

\item{total_events}{Numeric: sum of observed events (precomputed, weighted
when \code{weights} is supplied).}

\item{weights}{Optional numeric vector of row weights (length n). Defaults to
unit weights. Applied when summing per-phase cumhaz so Turner's adjustment
is computed on the same scale as \code{total_events}.}

\item{time_lower}{Optional numeric vector of counting-process entry (start)
times. When supplied, conservation is enforced on the entry-time scale --
\verb{Sum E = Sum [H(stop) - H(start)]} -- by subtracting the entry-time
cumulative hazard, matching the multiphase likelihood (and C HAZARD
\code{setcoe} under \code{LCENSOR}/\code{STARTTME}). \code{NULL} (the default) means no
truncation, i.e. \code{H(start) = 0}.}
}
\value{
Updated theta vector with fixmu phase's log_mu adjusted.
}
\description{
Given the current theta vector, analytically solve the fixmu phase's
log_mu so that total predicted events = total observed events.
}
\details{
This is called BEFORE each likelihood evaluation inside the optimizer,
matching the C HAZARD \code{CONSRV} entry point.
}
\keyword{internal}
