Skip to content

Commit 4b0815f

Browse files
paldaydmbates
andauthored
force Symmetric pre Cholesky (#42)
* force Symmetric pre Cholesky * patch bump * Use Diagonal instead of diagm; factor corrmat Co-authored-by: Douglas Bates <dmbates@gmail.com>
1 parent 0079acc commit 4b0815f

2 files changed

Lines changed: 5 additions & 10 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MixedModelsSim"
22
uuid = "d5ae56c5-23ca-4a1f-b505-9fc4796fc1fe"
33
authors = ["Phillip Alday", "Douglas Bates", "Lisa DeBruine", "Reinhold Kliegl"]
4-
version = "0.2.0"
4+
version = "0.2.1"
55

66
[deps]
77
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"

src/utilities.jl

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ end
158158
"""
159159
create_re(sigmas...; corrmat=Matrix{Float64}(I, length(sigmas), length(sigmas))
160160
161-
Create the covariance matrix for a random effect from the standard deviations and correlation matrix.
161+
Create the covariance factor for a random effect from the standard deviations and correlation matrix.
162162
163163
The `sigmas` should be specified in the same order as the random slopes in the
164164
output of `VarCorr(m)`.
@@ -167,18 +167,13 @@ The correlation matrix defaults to the identiy matrix, i.e. no correlation betwe
167167
random effects.
168168
169169
!!! note
170-
The return value is the lower Cholesky of the covariance matrix, which is what
170+
The return value is the lower Cholesky factor of the covariance matrix, which is what
171171
[`update!`](@ref) requires.
172172
"""
173173
function create_re(sigmas...; corrmat=nothing)
174-
dim = length(sigmas)
175-
ss = diagm([sigmas...])
174+
ss = Diagonal([sigmas...])
176175

177-
if isnothing(corrmat)
178-
LowerTriangular(ss)
179-
else
180-
cholesky(ss * corrmat * ss).L
181-
end
176+
isnothing(corrmat) ? LowerTriangular(ss) : ss * cholesky(Symmetric(corrmat, :L)).L
182177
end
183178

184179

0 commit comments

Comments
 (0)