155155
156156
157157"""
158- update !(m::MixedModel; θ)
158+ _update !(m::MixedModel, θ)
159159
160160Update the mixed model to use θ as its new parameter vector.
161161
@@ -167,8 +167,8 @@ Update the mixed model to use θ as its new parameter vector.
167167!!! note
168168 For GLMMs, this only sets θ and not β, even for `fast=false` fits.
169169"""
170- update ! (m:: LinearMixedModel ; θ) = updateL! (MixedModels. setθ! (m, θ))
171- update ! (m:: GeneralizedLinearMixedModel ; θ) = pirls! (MixedModels. setθ! (m, θ), false )
170+ _update ! (m:: LinearMixedModel , θ) = updateL! (MixedModels. setθ! (m, θ))
171+ _update ! (m:: GeneralizedLinearMixedModel , θ) = pirls! (MixedModels. setθ! (m, θ), false )
172172# arguably type piracy, but we're all the same developers....
173173
174174
@@ -182,16 +182,87 @@ The `re` can be created using [`create_re`](@ref).
182182
183183They should be specified in the order specified in `VarCorr(m)`.
184184
185+ !!! warning
186+ We recommend against calling this method directly. Instead, use the method
187+ with keyword arguments to specify the different `re` by name.
188+
189+ !!! note
190+ This is a convenience function for installing a particular parameter vector
191+ and the resulting model fit. It does not actually perform any type of
192+ optimization.
193+
185194Details
186195========
187196The `re` used as the λ fields of the model's `ReTerm`s and should be specified
188197as the lower Cholesky factor of covariance matrices.
189198"""
190199function update! (m:: MixedModel , re... )
200+ Base. depwarn (" Specifying the random effects by position instead of name is deprecated" ,
201+ :update!vararg )
202+
191203 θ = vcat ((flatlowertri (rr) for rr in re). .. )
192- update ! (m; θ = θ)
204+ return _update ! (m, θ)
193205end
194206
207+ """
208+ update!(m::MixedModel; namedre...)
209+ update!(m::MixedModel; θ)
210+
211+ Update the mixed model to use the random-effects covariance matrices.
212+
213+ The `namedre` can be created using [`create_re`](@ref). The `namedre` are specified
214+ by the name of the blocking variable, e.g. `subj=create_re(...)`.
215+
216+ !!! warning
217+ Setting θ directly as a keyword-argument is deprecated.
218+
219+ !!! note
220+ This is a convenience function for installing a particular parameter vector
221+ and the resulting model fit. It does not actually perform any type of
222+ optimization.
223+
224+ Details
225+ ========
226+ The `re` is used as the λ fields of the model's `ReTerm`s and should be specified
227+ as the lower Cholesky factor of covariance matrices.
228+ """
229+ function update! (m:: MixedModel ; θ= nothing , namedre... )
230+ if θ === nothing
231+ length (namedre) == 0 && throw (ArgumentError (" no random effects specified" ))
232+ θ = createθ (m; namedre... )
233+ elseif θ != = nothing && length (namedre) != 0
234+ throw (ArgumentError (" θ must not be specified when named random effects are" ))
235+ end
236+ return _update! (m, θ)
237+ end
238+
239+ """
240+ createθ(m::MixedModel; named_re)
241+ create_theta(m::MixedModel; named_re)
242+
243+ Create the parameter vector θ corresponding to the random effects.
244+
245+ The `named_re` can be created using [`create_re`](@ref). The `named_re` are specified
246+ by the name of the blocking variable, e.g. `subj=create_re(...)`.
247+
248+ The model must be specified because the parameters are sorted internally for computational
249+ efficiency.
250+ """
251+ function createθ (m:: MixedModel ; named_re... )
252+ newre = Dict (named_re... )
253+ fns = fnames (m)
254+
255+ if Set (fns) != keys (newre)
256+ throw (ArgumentError (" Specified blocking variables do not match model blocking variables." ))
257+ end
258+
259+ return mapfoldl (vcat, fns) do fname
260+ flatlowertri (newre[fname])
261+ end
262+ end
263+
264+ const create_theta = createθ
265+
195266"""
196267 create_re(sigmas...; corrmat=Matrix{Float64}(I, length(sigmas), length(sigmas))
197268
0 commit comments