Skip to content

Commit b5e920a

Browse files
author
Alexey Stukalov
committed
replace_observed(...; recompute_obs_state=true)
1 parent b41e75b commit b5e920a

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

src/frontend/fit/standard_errors/bootstrap.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ end
251251
# Fit one bootstrap replicate: resample, replace observed data, fit.
252252
function _fit_bootstrap_sample(sem_model, data, start; engine, fit_kwargs)
253253
boot_data = resample_with_replacement(data)
254-
boot_model = replace_observed(sem_model, boot_data)
254+
# we replace the observed data with the bootstrapped one,
255+
# but preserve any internal state that is associated with the original data
256+
boot_model = replace_observed(sem_model, boot_data; recompute_observed_state = true)
255257
return fit(boot_model; start_val = start, engine = engine, fit_kwargs...)
256258
end

src/loss/WLS/WLS.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,13 @@ end
185185
function replace_observed(
186186
loss::SemWLS,
187187
new_observed::SemObserved;
188-
update_internal_state::Bool = true,
188+
recompute_observed_state::Bool = true,
189189
)
190-
# recompute weight matrices only if update_internal_state=true
190+
# recompute weight matrices only if recompute_observed_state=true
191191
return SemWLS(
192192
new_observed,
193193
SEM.implied(loss);
194-
wls_weight_matrix = update_internal_state ? nothing : loss.V,
195-
wls_weight_matrix_mean = update_internal_state ? nothing : loss.V_μ,
194+
wls_weight_matrix = recompute_observed_state ? nothing : loss.V,
195+
wls_weight_matrix_mean = recompute_observed_state ? nothing : loss.V_μ,
196196
)
197197
end

test/unit_tests/model.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ end
8989
new_data = randn(nsamples(obs), nobserved_vars(obs))
9090

9191
findiff_model_oldstate =
92-
replace_observed(findiff_model, new_data; update_internal_state = false)
92+
replace_observed(findiff_model, new_data; recompute_observed_state = false)
9393
findiff_model_newstate =
94-
replace_observed(findiff_model, new_data; update_internal_state = true)
94+
replace_observed(findiff_model, new_data; recompute_observed_state = true)
9595

9696
loss_orig = SEM._unwrap(sem_term(findiff_model))
9797
loss_oldstate = SEM._unwrap(sem_term(findiff_model_oldstate))

0 commit comments

Comments
 (0)