Skip to content

Commit

Permalink
Modularize constructors (#449)
Browse files Browse the repository at this point in the history
* split constructor into steps

* don't forget the weights

* news update
  • Loading branch information
palday authored Dec 9, 2020
1 parent f0caa2b commit 92d2e1b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
MixedModels v3.1.4 Release Notes
========================
* [experimental] Additional convenience constructors for `LinearMixedModel` [#449]

MixedModels v3.1.3 Release Notes
========================
* Compatibility updates
Expand Down Expand Up @@ -120,3 +124,4 @@ Package dependencies
[#444]: https://github.com/JuliaStats/MixedModels.jl/issues/444
[#446]: https://github.com/JuliaStats/MixedModels.jl/issues/446
[#447]: https://github.com/JuliaStats/MixedModels.jl/issues/447
[#449]: https://github.com/JuliaStats/MixedModels.jl/issues/449
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MixedModels"
uuid = "ff71e718-51f3-5ec2-a782-8ffcbfa3c316"
author = ["Phillip Alday <[email protected]>", "Douglas Bates <[email protected]>", "Jose Bayoan Santiago Calderon <[email protected]>"]
version = "3.1.3"
version = "3.1.4"

[deps]
Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45"
Expand Down
39 changes: 39 additions & 0 deletions src/linearmixedmodel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,25 @@ function LinearMixedModel(

y, Xs = modelcols(form, tbl)

return LinearMixedModel(y, Xs, form, wts)
end

"""
LinearMixedModel(y, Xs, form)
Private constructor for a LinearMixedModel.
To construct a model, you only need the response (`y`), already assembled
model matrices (`Xs`), schematized formula (`form`) and weights (`wts`).
Everything else in the structure can be derived from these quantities.
!!! note
This method is internal and experimental and so may change or disappear in
a future release without being considered a breaking change.
"""
function LinearMixedModel(y::AbstractArray,
Xs::Tuple, # can't be more specific here without stressing the compiler
form::FormulaTerm, wts = [])
y = reshape(float(y), (:, 1)) # y as a floating-point matrix
T = promote_type(Float64, eltype(y)) # ensure that eltype of model matrices is at least Float64
y = convert(Matrix{T}, y)
Expand Down Expand Up @@ -97,6 +116,26 @@ function LinearMixedModel(
end
push!(feterms, FeMat(y, [""]))

return LinearMixedModel(feterms, reterms, form, wts)
end

"""
LinearMixedModel(feterms, reterms, form, wts=[])
Private constructor for a `LinearMixedModel` given already assembled fixed and random effects.
To construct a model, you only need a vector of `FeMat`s (the fixed-effects
model matrix and response), a vector of `AbstractReMat` (the random-effects
model matrices), the formula and the weights. Everything else in the structure
can be derived from these quantities.
!!! note
This method is internal and experimental and so may change or disappear in
a future release without being considered a breaking change.
"""
function LinearMixedModel(feterms::Vector{FeMat{T}}, reterms::Vector{AbstractReMat{T}},
form::FormulaTerm, wts=[]) where T

# detect and combine RE terms with the same grouping var
if length(reterms) > 1
reterms = amalgamate(reterms)
Expand Down

2 comments on commit 92d2e1b

@palday
Copy link
Member Author

@palday palday commented on 92d2e1b Dec 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/26133

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v3.1.4 -m "<description of version>" 92d2e1b702777ec14720d21e48dfc0a2cca19f65
git push origin v3.1.4

Please sign in to comment.