Collections
With StructuralEquationModels.jl, you can fit weighted sums of structural equation models. The most common use case for this are Multigroup models. Another use case may be optimizing the sum of loss functions for some of which you do know the analytic gradient, but not for others. In this case, you can optimize the sum of a Sem and a SemFiniteDiff (or any other differentiation method).
To use this feature, you have to construct a SemEnsemble model, which is actually quite easy:
# models
model_1 = Sem(...)
model_2 = SemFiniteDiff(...)
model_3 = Sem(...)
model_ensemble = SemEnsemble(model_1, model_2, model_3)So you just construct the individual models (however you like) and pass them to SemEnsemble. You may also pass a vector of weigths to SemEnsemble. By default, those are set to $N_{model}/N_{total}$, i.e. each model is weighted by the number of observations in it's data (which matches the formula for multigroup models).
Multigroup models can also be specified via the graph interface; for an example, see Multigroup models.
API - collections
StructuralEquationModels.SemEnsemble — Type
(1) SemEnsemble(models...; weights = nothing, groups = nothing, kwargs...)
(2) SemEnsemble(;specification, data, groups, column = :group, kwargs...)Constructor for ensemble models. (2) can be used to conveniently specify multigroup models.
Arguments
models...:AbstractSems.weights::Vector: Weights for each model. Defaults to the number of observed data points.specification::EnsembleParameterTable: Model specification.data::DataFrame: Observed data. Must contain acolumnof typeVector{Symbol}that contains the group.groups::Vector{Symbol}: Group names.column::Symbol: Name of the column indatathat contains the group.
All additional kwargs are passed down to the model parts.
Returns a SemEnsemble with fields
n::Int: Number of models.sems::Tuple:AbstractSems.weights::Vector: Weights for each model.param_labels::Vector: Stores parameter labels and their position.
For instructions on multigroup models, see the online documentation.
StructuralEquationModels.AbstractSemCollection — Type
Supertype for all collections of multiple SEMs