% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/define_model_system.R
\name{define_model_system}
\alias{define_model_system}
\title{Define a model system}
\usage{
define_model_system(
  components,
  factor,
  previous_stage = NULL,
  weights = NULL,
  equality_constraints = NULL,
  free_params = NULL
)
}
\arguments{
\item{components}{A named list of model_component objects}

\item{factor}{A factor_model object}

\item{previous_stage}{Optional result from a previous estimation stage.
If provided, the previous stage components and parameters will be fixed
and prepended to the new components. This enables sequential/multi-stage
estimation where early stages are held fixed while later stages are optimized.}

\item{weights}{Optional. Name of a variable in the data containing observation weights.
When specified, each observation's contribution to the log-likelihood is multiplied
by its weight. Useful for survey weights, importance sampling, or giving different
observations different influence on the estimation. Weights should be positive.
The variable is extracted from the data passed to \code{estimate_model_rcpp()}.}

\item{equality_constraints}{Optional. A list of character vectors, where each vector
specifies parameter names that should be constrained to be equal during estimation.
The first parameter in each group is the "primary" (freely estimated), and all
other parameters in the group are set equal to the primary.
Example: \code{list(c("Y1_loading_1", "Y2_loading_2"), c("Y1_sigma", "Y2_sigma"))}
This is useful for measurement invariance constraints in longitudinal models.}

\item{free_params}{Optional. A character vector of parameter names from previous_stage
that should remain FREE (not fixed) in the current stage. This allows selectively
freeing specific parameters while keeping others fixed. Commonly used to free
factor variances while keeping measurement loadings/thresholds fixed.
Example: \code{c("factor_var_1", "factor_var_2")} to free factor variances.
Only used when previous_stage is provided.}
}
\value{
An object of class "model_system". A list of model_component objects and one factor_model object.
}
\description{
Define a model system
}
\examples{
dat <- data.frame(y1 = rnorm(50), y2 = rnorm(50), intercept = 1)
fm <- define_factor_model(n_factors = 1)
mc1 <- define_model_component("m1", dat, "y1", fm,
  covariates = "intercept", model_type = "linear",
  loading_normalization = 1)
mc2 <- define_model_component("m2", dat, "y2", fm,
  covariates = "intercept", model_type = "linear",
  loading_normalization = NA_real_)
ms <- define_model_system(components = list(mc1, mc2), factor = fm)
}
