11"""
22 bootstrap(
3- fitted::SemFit;
3+ fitted::SemFit,
4+ specification::SemSpecification;
45 statistic = solution,
56 n_boot = 3000,
67 data = nothing,
7- specification = nothing,
88 engine = :Optim,
99 parallel = false,
1010 fit_kwargs = Dict(),
@@ -14,12 +14,11 @@ Return bootstrap samples for `statistic`.
1414
1515# Arguments
1616- `fitted`: a fitted SEM.
17+ - `specification`: a `ParameterTable` or `RAMMatrices` object passed to `replace_observed`.
1718- `statistic`: any function that can be called on a `SemFit` object.
1819 The output will be returned as the bootstrap sample.
1920- `n_boot`: number of boostrap samples
2021- `data`: data to sample from. Only needed if different than the data from `sem_fit`
21- - `specification`: a `ParameterTable` or `RAMMatrices` object passed to `replace_observed`.
22- Necessary for FIML / WLS models.
2322- `engine`: optimizer engine, passed to `fit`.
2423- `parallel`: if `true`, run bootstrap samples in parallel on all available threads.
2524 The number of threads is controlled by the `JULIA_NUM_THREADS` environment variable or
@@ -40,11 +39,11 @@ bootstrap(
4039```
4140"""
4241function bootstrap (
43- fitted:: SemFit ;
42+ fitted:: SemFit ,
43+ specification:: SemSpecification ;
4444 statistic = solution,
4545 n_boot = 3000 ,
4646 data = nothing ,
47- specification = nothing ,
4847 engine = :Optim ,
4948 parallel = false ,
5049 fit_kwargs = Dict (),
@@ -56,6 +55,7 @@ function bootstrap(
5655 # pre-allocations
5756 out = []
5857 conv = []
58+ errors = []
5959 n_failed = Ref (0 )
6060 # fit to bootstrap samples
6161 if ! parallel
@@ -73,8 +73,9 @@ function bootstrap(
7373 c = converged (new_fit)
7474 push! (out, sample)
7575 push! (conv, c)
76- catch
76+ catch e
7777 n_failed[] += 1
78+ push! (errors, e)
7879 end
7980 end
8081 else
@@ -103,9 +104,10 @@ function bootstrap(
103104 push! (out, sample)
104105 push! (conv, c)
105106 end
106- catch
107+ catch e
107108 lock (lk) do
108109 n_failed[] += 1
110+ push! (errors, e)
109111 end
110112 finally
111113 put! (model_pool, thread_model)
@@ -119,19 +121,19 @@ function bootstrap(
119121 return Dict (
120122 :samples => out,
121123 :n_boot => n_boot,
122- :n_converged => sum (conv),
124+ :n_converged => isempty (conv) ? 0 : sum (conv),
123125 :converged => conv,
124126 :n_errored => n_failed[],
127+ :errors => errors
125128 )
126129end
127130
128131"""
129132 se_bootstrap(
130- fitted::SemFit;
133+ fitted::SemFit,
134+ specification::SemSpecification;
131135 n_boot = 3000,
132136 data = nothing,
133- specification = nothing,
134- engine = :Optim,
135137 parallel = false,
136138 fit_kwargs = Dict(),
137139 replace_kwargs = Dict())
@@ -140,10 +142,9 @@ Return bootstrap standard errors.
140142
141143# Arguments
142144- `fitted`: a fitted SEM.
145+ - `specification`: a `ParameterTable` or `RAMMatrices` object passed to `replace_observed`.
143146- `n_boot`: number of boostrap samples
144147- `data`: data to sample from. Only needed if different than the data from `sem_fit`
145- - `specification`: a `ParameterTable` or `RAMMatrices` object passed to `replace_observed`.
146- Necessary for FIML / WLS models.
147148- `engine`: optimizer engine, passed to `fit`.
148149- `parallel`: if `true`, run bootstrap samples in parallel on all available threads.
149150 The number of threads is controlled by the `JULIA_NUM_THREADS` environment variable or
@@ -165,10 +166,10 @@ se_bootstrap(
165166```
166167"""
167168function se_bootstrap (
168- fitted:: SemFit ;
169+ fitted:: SemFit ,
170+ specification:: SemSpecification ;
169171 n_boot = 3000 ,
170172 data = nothing ,
171- specification = nothing ,
172173 engine = :Optim ,
173174 parallel = false ,
174175 fit_kwargs = Dict (),
0 commit comments