Skip to content

Commit 071005b

Browse files
format
1 parent 1fd1a6a commit 071005b

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

src/additional_functions/simulation.jl

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ function update_observed(loss::SemLoss, new_observed; kwargs...)
9999
return SemLoss(new_functions, loss.weights)
100100
end
101101

102-
103102
############################################################################################
104103
# simulate data
105104
############################################################################################
@@ -121,24 +120,22 @@ rand(model, start_simple(model), 100)
121120
```
122121
"""
123122
function Distributions.rand(
124-
model::AbstractSemSingle{O, I, L, D},
125-
params,
126-
n::Integer) where {O, I <: Union{RAM, RAMSymbolic}, L, D}
127-
update!(
128-
EvaluationTargets{true, false, false}(),
129-
model.imply,
130-
model,
131-
params)
123+
model::AbstractSemSingle{O, I, L, D},
124+
params,
125+
n::Integer,
126+
) where {O, I <: Union{RAM, RAMSymbolic}, L, D}
127+
update!(EvaluationTargets{true, false, false}(), model.imply, model, params)
132128
return rand(model, n)
133129
end
134130

135131
function Distributions.rand(
136-
model::AbstractSemSingle{O, I, L, D},
137-
n::Integer) where {O, I <: Union{RAM, RAMSymbolic}, L, D}
132+
model::AbstractSemSingle{O, I, L, D},
133+
n::Integer,
134+
) where {O, I <: Union{RAM, RAMSymbolic}, L, D}
138135
if MeanStruct(model.imply) === NoMeanStruct
139136
data = permutedims(rand(MvNormal(Symmetric(model.imply.Σ)), n))
140137
elseif MeanStruct(model.imply) === HasMeanStruct
141138
data = permutedims(rand(MvNormal(model.imply.μ, Symmetric(model.imply.Σ)), n))
142139
end
143140
return data
144-
end
141+
end

test/examples/political_democracy/constructor.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ end
174174
start_regressions = 0.5,
175175
start_variances_observed = 0.5,
176176
start_variances_latent = 1.0,
177-
start_covariances_observed = 0.2)
177+
start_covariances_observed = 0.2,
178+
)
178179
# set seed for simulation
179180
Random.seed!(83472834)
180181
colnames = Symbol.(names(example_data("political_democracy")))
@@ -183,13 +184,13 @@ end
183184
model_ml,
184185
data = rand(model_ml, params, 100_000),
185186
specification = spec,
186-
obs_colnames = colnames
187+
obs_colnames = colnames,
187188
)
188189
model_ml_sym_new = swap_observed(
189190
model_ml_sym,
190191
data = rand(model_ml_sym, params, 100_000),
191192
specification = spec,
192-
obs_colnames = colnames
193+
obs_colnames = colnames,
193194
)
194195
# fit models
195196
sol_ml = solution(sem_fit(model_ml_new))
@@ -370,7 +371,6 @@ end
370371
)
371372
end
372373

373-
374374
############################################################################################
375375
### data simulation
376376
############################################################################################
@@ -384,7 +384,8 @@ end
384384
start_variances_observed = 0.5,
385385
start_variances_latent = 1.0,
386386
start_covariances_observed = 0.2,
387-
start_means = 0.5)
387+
start_means = 0.5,
388+
)
388389
# set seed for simulation
389390
Random.seed!(83472834)
390391
colnames = Symbol.(names(example_data("political_democracy")))
@@ -394,14 +395,14 @@ end
394395
data = rand(model_ml, params, 100_000),
395396
specification = spec,
396397
obs_colnames = colnames,
397-
meanstructure = true
398+
meanstructure = true,
398399
)
399400
model_ml_sym_new = swap_observed(
400401
model_ml_sym,
401402
data = rand(model_ml_sym, params, 100_000),
402403
specification = spec,
403404
obs_colnames = colnames,
404-
meanstructure = true
405+
meanstructure = true,
405406
)
406407
# fit models
407408
sol_ml = solution(sem_fit(model_ml_new))

0 commit comments

Comments
 (0)