-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
correct coeftable for GLMMs, add tests (#308)
* correct coeftable for GLMMs, add tests * Move methods for abstract MixedModel struct to separate file.
- Loading branch information
Showing
5 changed files
with
116 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
""" | ||
cond(m::MixedModel) | ||
Return a vector of condition numbers of the λ matrices for the random-effects terms | ||
""" | ||
LinearAlgebra.cond(m::MixedModel) = cond.(m.λ) | ||
|
||
function σs(m::MixedModel) | ||
σ = dispersion(m) | ||
NamedTuple{fnames(m)}(((σs(t, σ) for t in m.reterms)...,)) | ||
end | ||
|
||
function σρs(m::MixedModel) | ||
σ = dispersion(m) | ||
NamedTuple{fnames(m)}(((σρs(t, σ) for t in m.reterms)...,)) | ||
end | ||
|
||
""" | ||
vcov(m::LinearMixedModel) | ||
Returns the variance-covariance matrix of the fixed effects. | ||
If `corr=true`, then correlation of fixed effects is returned instead. | ||
""" | ||
function StatsBase.vcov(m::MixedModel; corr=false) | ||
Xtrm = fetrm(m) | ||
iperm = invperm(Xtrm.piv) | ||
p = length(iperm) | ||
r = Xtrm.rank | ||
Linv = inv(feL(m)) | ||
T = eltype(Linv) | ||
permvcov = dispersion(m, true) * (Linv'Linv) | ||
if p == Xtrm.rank | ||
vv = permvcov[iperm, iperm] | ||
else | ||
covmat = fill(zero(T) / zero(T), (p, p)) | ||
for j = 1:r, i = 1:r | ||
covmat[i, j] = permvcov[i, j] | ||
end | ||
vv = covmat[iperm, iperm] | ||
end | ||
|
||
corr ? StatsBase.cov2cor!(vv, stderror(m)) : vv | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters