Simulation studies
We are currently working on an interface for simulation studies. Until we are finished with this, this page is just a collection of tips.
Swap observed data
In simulation studies, a common task is fitting the same model to many different datasets. It would be a waste of resources to reconstruct the complete model for each dataset. We therefore provide the function swap_observed
to change the observed
part of a model, without necessarily reconstructing the other parts.
For the A first model, you would use it as
data = example_data("political_democracy")
data_1 = data[1:30, :]
data_2 = data[31:75, :]
model = Sem(
specification = partable,
data = data_1
)
model_updated = swap_observed(model; data = data_2, specification = partable)
Structural Equation Model
- Loss Functions
SemML
- Fields
observed: SemObservedData
imply: RAM
optimizer: SemOptimizerOptim
This is only relevant when you are planning to fit updated models in parallel
Models generated this way may share the same objects in memory (e.g. some parts of model
and model_updated
are the same objects in memory.) Therefore, fitting both of these models in parallel will lead to race conditions, possibly crashing your computer. To avoid these problems, you should copy model
before updating it.
If you are building your models by parts, you can also update each part seperately with the function update_observed
. For example,
new_observed = SemObservedData(;data = data_2, specification = partable)
my_optimizer = SemOptimizerOptim()
new_optimizer = update_observed(my_optimizer, new_observed)
SemOptimizerOptim
algorithm: Optim.LBFGS{Nothing, LineSearches.InitialStatic{Float64}, LineSearches.HagerZhang{Float64, Base.RefValue{Bool}}, Optim.var"#19#21"}
options: Optim.Options{Float64, Nothing}
API
StructuralEquationModels.swap_observed
— Function(1) swap_observed(model::AbstractSemSingle; kwargs...)
(2) swap_observed(model::AbstractSemSingle, observed; kwargs...)
Return a new model with swaped observed part.
Arguments
model::AbstractSemSingle
: optimization algorithm.kwargs
: additional keyword arguments; typically includesdata = ...
observed
: Either an object of subtype ofSemObserved
or a subtype ofSemObserved
Examples
See the online documentation on Swap observed data.
StructuralEquationModels.update_observed
— Functionupdate_observed(to_update, observed::SemObserved; kwargs...)
Update a SemImply
, SemLossFunction
or SemOptimizer
object to use a SemObserved
object.
Examples
See the online documentation on Swap observed data.
Implementation
You can provide a method for this function when defining a new type, for more information on this see the online developer documentation on Update observed data.