API
Basic
@covstr
Metida.@covstr
— Macro@covstr(ex)
Macros for random/repeated effect model.
Example
@covstr(factor|subject)
@lmmformula
Metida.@lmmformula
— Macro@lmmformula(formula, args...)
Macro for made formula with variance-covariance structure representation. @lmmformula
could be used for shorter LMM
construction.
Example:
lmm = Metida.LMM(@lmmformula(var~sequence+period+formulation,
+API · Metida.jl API
Basic
@covstr
Metida.@covstr
— Macro@covstr(ex)
Macros for random/repeated effect model.
Example
@covstr(factor|subject)
source@lmmformula
Metida.@lmmformula
— Macro@lmmformula(formula, args...)
Macro for made formula with variance-covariance structure representation. @lmmformula
could be used for shorter LMM
construction.
Example:
lmm = Metida.LMM(@lmmformula(var~sequence+period+formulation,
random = formulation|subject:CSH,
repeated = formulation|subject:DIAG),
df0)
equal to:
lmm = LMM(@formula(var~sequence+period+formulation), df0;
@@ -9,51 +9,51 @@
random = formulation|subject:CSH,
random = 1|subject:DIAG,
repeated = formulation|subject:DIAG),
-df0)
random
or repeated
structure made by template:
effect formula
| blocking factor
[/ nested factor
] [: covariance structure
]
|
- devide effect formula form blocking factor definition (necessarily), /
and :
modificator are optional.
/
work like in MixedModels or in RegressionFormulae - expand factor f|a/b
to f|a
+ f|a&b
. It can't be used in repeated effect definition.
:
- covariance structure defined right after :
(SI, DIAG, CS, CSH, ets...), if :
not used then SI used for this effect.
Terms like a+b
or a*b
shuould not be used as a blocking factors.
sourceMetida.CovarianceType
Metida.CovarianceType
— TypeCovarianceType(cm::AbstractCovmatMethod)
Make covariance type with AbstractCovmatMethod.
sourceLMM
Metida.LMM
— TypeLMM(model, data; contrasts=Dict{Symbol,Any}(), random::Union{Nothing, VarEffect, Vector{VarEffect}} = nothing, repeated::Union{Nothing, VarEffect} = nothing, wts::Union{Nothing, AbstractVector, AbstractMatrix, AbstractString, Symbol} = nothing)
Make Linear-Mixed Model object.
model
: is a fixed-effect model (@formula
)
data
: tabular data
contrasts
: contrasts for fixed factors
random
: vector of random effects or single random effect
repeated
: is a repeated effect or vector
wts
: regression weights (residuals).
Weigts can be set as Symbol
or String
, in this case weights taken from tabular data. If weights is vector then this vector applyed to R-side part of covariance matrix (see Weights details). If weights is matrix then R-side part of covariance matrix multiplied by corresponding part of weight-matrix.
See also: @lmmformula
sourceVarEffect
Metida.VarEffect
— TypeVarEffect(formula, covtype::T, coding) where T <: AbstractCovarianceType
+df0)
random
or repeated
structure made by template:
effect formula
| blocking factor
[/ nested factor
] [: covariance structure
]
|
- devide effect formula form blocking factor definition (necessarily), /
and :
modificator are optional.
/
work like in MixedModels or in RegressionFormulae - expand factor f|a/b
to f|a
+ f|a&b
. It can't be used in repeated effect definition.
:
- covariance structure defined right after :
(SI, DIAG, CS, CSH, ets...), if :
not used then SI used for this effect.
Terms like a+b
or a*b
shuould not be used as a blocking factors.
sourceMetida.CovarianceType
Metida.CovarianceType
— TypeCovarianceType(cm::AbstractCovmatMethod)
Make covariance type with AbstractCovmatMethod.
sourceLMM
Metida.LMM
— TypeLMM(model, data; contrasts=Dict{Symbol,Any}(), random::Union{Nothing, VarEffect, Vector{VarEffect}} = nothing, repeated::Union{Nothing, VarEffect} = nothing, wts::Union{Nothing, AbstractVector, AbstractMatrix, AbstractString, Symbol} = nothing)
Make Linear-Mixed Model object.
model
: is a fixed-effect model (@formula
)
data
: tabular data
contrasts
: contrasts for fixed factors
random
: vector of random effects or single random effect
repeated
: is a repeated effect or vector
wts
: regression weights (residuals).
Weigts can be set as Symbol
or String
, in this case weights taken from tabular data. If weights is vector then this vector applyed to R-side part of covariance matrix (see Weights details). If weights is matrix then R-side part of covariance matrix multiplied by corresponding part of weight-matrix.
See also: @lmmformula
sourceVarEffect
Metida.VarEffect
— TypeVarEffect(formula, covtype::T, coding) where T <: AbstractCovarianceType
VarEffect(formula, covtype::T; coding = nothing) where T <: AbstractCovarianceType
VarEffect(formula; coding = nothing)
Random/repeated effect.
formula
from @covstr(ex) macros.
covtype
- covariance type (SI, DIAG, CS, CSH, AR, ARH, ARMA, TOEP, TOEPH, TOEPP, TOEPHP)
Note Categorical factors are coded with FullDummyCoding()
by default, use coding
for other contrast codeing.
Example
VarEffect(@covstr(1+factor|subject), CSH)
-VarEffect(@covstr(1 + formulation|subject), CSH; coding = Dict(:formulation => StatsModels.DummyCoding()))
sourceCovariance structures
Metida.Autoregressive
Metida.Autoregressive
— FunctionAutoregressive()
Autoregressive covariance type.
AR = Autoregressive()
\[\begin{bmatrix} 1 & \rho & \rho^2 & \rho^3 \\
+VarEffect(@covstr(1 + formulation|subject), CSH; coding = Dict(:formulation => StatsModels.DummyCoding()))
sourceCovariance structures
Metida.Autoregressive
Metida.Autoregressive
— FunctionAutoregressive()
Autoregressive covariance type.
AR = Autoregressive()
\[\begin{bmatrix} 1 & \rho & \rho^2 & \rho^3 \\
\rho & 1 & \rho & \rho^2 \\ \rho^2 & \rho & 1 & \rho \\
\rho^3 & \rho^2 & \rho & 1
-\end{bmatrix}\sigma^2\]
sourceMetida.AutoregressiveMovingAverage
Metida.AutoregressiveMovingAverage
— FunctionAutoregressiveMovingAverage()
Autoregressive moving average covariance type.
ARMA = AutoregressiveMovingAverage()
\[\begin{bmatrix} 1 & \gamma & \gamma\rho & \gamma\rho^2 \\
+\end{bmatrix}\sigma^2\]
sourceMetida.AutoregressiveMovingAverage
Metida.AutoregressiveMovingAverage
— FunctionAutoregressiveMovingAverage()
Autoregressive moving average covariance type.
ARMA = AutoregressiveMovingAverage()
\[\begin{bmatrix} 1 & \gamma & \gamma\rho & \gamma\rho^2 \\
\gamma & 1 & \gamma & \gamma\rho \\
\gamma\rho & \gamma & 1 & \gamma \\
\gamma\rho^2 & \gamma\rho & \gamma & 1
-\end{bmatrix}\sigma^2\]
sourceMetida.CompoundSymmetry
Metida.CompoundSymmetry
— FunctionCompoundSymmetry()
Compound symmetry covariance type.
CS = CompoundSymmetry()
\[\begin{bmatrix} 1 & \rho & \rho & \rho \\
+\end{bmatrix}\sigma^2\]
sourceMetida.CompoundSymmetry
Metida.CompoundSymmetry
— FunctionCompoundSymmetry()
Compound symmetry covariance type.
CS = CompoundSymmetry()
\[\begin{bmatrix} 1 & \rho & \rho & \rho \\
\rho & 1 & \rho & \rho \\
\rho & \rho & 1 & \rho \\
\rho & \rho & \rho & 1
-\end{bmatrix}\sigma^2\]
sourceMetida.Diag
Metida.Diag
— FunctionDiag()
Diagonal covariance type.
DIAG = Diag()
\[\begin{bmatrix} \sigma_a^2 & 0 & 0 \\ 0 & \sigma_b^2 & 0 \\ 0 & 0 & \sigma_c^2 \end{bmatrix}\]
sourceMetida.HeterogeneousAutoregressive
Metida.HeterogeneousAutoregressive
— FunctionHeterogeneousAutoregressive()
Heterogeneous autoregressive covariance type.
ARH = HeterogeneousAutoregressive()
\[\begin{bmatrix}
+\end{bmatrix}\sigma^2\]
sourceMetida.Diag
Metida.Diag
— FunctionDiag()
Diagonal covariance type.
DIAG = Diag()
\[\begin{bmatrix} \sigma_a^2 & 0 & 0 \\ 0 & \sigma_b^2 & 0 \\ 0 & 0 & \sigma_c^2 \end{bmatrix}\]
sourceMetida.HeterogeneousAutoregressive
Metida.HeterogeneousAutoregressive
— FunctionHeterogeneousAutoregressive()
Heterogeneous autoregressive covariance type.
ARH = HeterogeneousAutoregressive()
\[\begin{bmatrix}
\sigma_a^2 & \rho\sigma_a\sigma_b & \rho^2\sigma_a\sigma_c & \rho^3\sigma_a\sigma_d \\
\rho\sigma_b\sigma_a & \sigma_b^2 & \rho\sigma_b\sigma_c & \rho^2\sigma_b\sigma_d \\
\rho^2\sigma_c\sigma_a & \rho\sigma_c\sigma_b & \sigma_c^2 & \rho\sigma_c\sigma_d \\
\rho^3\sigma_d\sigma_a & \rho^2\sigma_d\sigma_b & \rho\sigma_d\sigma_c & \sigma_d^2
-\end{bmatrix}\]
sourceMetida.HeterogeneousCompoundSymmetry
Metida.HeterogeneousCompoundSymmetry
— FunctionHeterogeneousCompoundSymmetry()
Heterogeneous compound symmetry covariance type.
CSH = HeterogeneousCompoundSymmetry()
\[\begin{bmatrix}
+\end{bmatrix}\]
sourceMetida.HeterogeneousCompoundSymmetry
Metida.HeterogeneousCompoundSymmetry
— FunctionHeterogeneousCompoundSymmetry()
Heterogeneous compound symmetry covariance type.
CSH = HeterogeneousCompoundSymmetry()
\[\begin{bmatrix}
\sigma_a^2 & \rho\sigma_a\sigma_b & \rho\sigma_a\sigma_c & \rho\sigma_a\sigma_d \\
\rho\sigma_b\sigma_a & \sigma_b^2 & \rho\sigma_b\sigma_c & \rho\sigma_b\sigma_d \\
\rho\sigma_c\sigma_a & \rho\sigma_c\sigma_b & \sigma_c^2 & \rho\sigma_c\sigma_d \\
\rho\sigma_d\sigma_a & \rho\sigma_d\sigma_b & \rho\sigma_d\sigma_c & \sigma_d^2
-\end{bmatrix}\]
sourceMetida.HeterogeneousToeplitz
Metida.HeterogeneousToeplitz
— FunctionHeterogeneousToeplitz()
Heterogeneous toeplitz covariance type. Only for G matrix.
TOEPH = HeterogeneousToeplitz()
\[\begin{bmatrix}
+\end{bmatrix}\]
sourceMetida.HeterogeneousToeplitz
Metida.HeterogeneousToeplitz
— FunctionHeterogeneousToeplitz()
Heterogeneous toeplitz covariance type. Only for G matrix.
TOEPH = HeterogeneousToeplitz()
\[\begin{bmatrix}
\sigma_a^2 & \rho_1 \sigma_a \sigma_b & \rho_2 \sigma_a \sigma_c & \rho_3 \sigma_a \sigma_d \\
\rho_1 \sigma_b \sigma_a & \sigma_b^2 & \rho_1 \sigma_b \sigma_c & \rho_2 \sigma_b \sigma_d \\
\rho_2 \sigma_c \sigma_a & \rho_1 \sigma_c \sigma_b & \sigma_c^2 & \rho_1 \sigma_c \sigma_d \\
\rho_3 \sigma_d \sigma_a & \rho_2 \sigma_d \sigma_b & \rho_1 \sigma_d \sigma_c & \sigma_d^2
-\end{bmatrix}\]
sourceMetida.HeterogeneousToeplitzParameterized
Metida.HeterogeneousToeplitzParameterized
— FunctionHeterogeneousToeplitzParameterized(p::Int)
Heterogeneous toeplitz covariance type with parameter p, (number of bands = p - 1, if p = 1 it's equal DIAG structure).
TOEPHP(p) = HeterogeneousToeplitzParameterized(p)
sourceMetida.ScaledIdentity
Metida.ScaledIdentity
— FunctionScaledIdentity()
Scaled identity covariance type.
SI = ScaledIdentity()
\[\begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}\sigma^{2}\]
sourceMetida.SpatialExponential
Metida.SpatialExponential
— FunctionSpatialExponential()
Spatian Exponential covariance structure. Used only for repeated effect.
\[R_{i,j} = \sigma^{2} * exp(-dist(i,j)/\theta)\]
where dist
- Euclidean distance between row-vectors of repeated effect matrix for subject i
and j
, θ > 0.
SPEXP = SpatialExponential()
sourceMetida.SpatialGaussian
Metida.SpatialGaussian
— FunctionSpatialGaussian()
Spatian Gaussian covariance structure. Used only for repeated effect.
\[R_{i,j} = \sigma^{2} * exp(- dist(i,j)^2 / \theta^2)\]
where dist
- Euclidean distance between row-vectors of repeated effect matrix for subject i
and j
, θ ≠ 0.
SPGAU = SpatialGaussian()
sourceMetida.SpatialPower
Metida.SpatialPower
— FunctionSpatialPower()
Spatian Power covariance structure. Used only for repeated effect.
\[R_{i,j} = \sigma^{2} * \rho^{dist(i,j)}\]
where dist
- Euclidean distance between row-vectors of repeated effect matrix for subject i
and j
, 1 > ρ > -1.
SPPOW = SpatialPower()
sourceMetida.Toeplitz
Metida.Toeplitz
— FunctionToeplitz()
Toeplitz covariance type. Only for G matrix.
TOEP = Toeplitz()
\[\begin{bmatrix} 1 & \rho_1 & \rho_2 & \rho_3 \\
+\end{bmatrix}\]
sourceMetida.HeterogeneousToeplitzParameterized
Metida.HeterogeneousToeplitzParameterized
— FunctionHeterogeneousToeplitzParameterized(p::Int)
Heterogeneous toeplitz covariance type with parameter p, (number of bands = p - 1, if p = 1 it's equal DIAG structure).
TOEPHP(p) = HeterogeneousToeplitzParameterized(p)
sourceMetida.ScaledIdentity
Metida.ScaledIdentity
— FunctionScaledIdentity()
Scaled identity covariance type.
SI = ScaledIdentity()
\[\begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}\sigma^{2}\]
sourceMetida.SpatialExponential
Metida.SpatialExponential
— FunctionSpatialExponential()
Spatian Exponential covariance structure. Used only for repeated effect.
\[R_{i,j} = \sigma^{2} * exp(-dist(i,j)/\theta)\]
where dist
- Euclidean distance between row-vectors of repeated effect matrix for subject i
and j
, θ > 0.
SPEXP = SpatialExponential()
sourceMetida.SpatialGaussian
Metida.SpatialGaussian
— FunctionSpatialGaussian()
Spatian Gaussian covariance structure. Used only for repeated effect.
\[R_{i,j} = \sigma^{2} * exp(- dist(i,j)^2 / \theta^2)\]
where dist
- Euclidean distance between row-vectors of repeated effect matrix for subject i
and j
, θ ≠ 0.
SPGAU = SpatialGaussian()
sourceMetida.SpatialPower
Metida.SpatialPower
— FunctionSpatialPower()
Spatian Power covariance structure. Used only for repeated effect.
\[R_{i,j} = \sigma^{2} * \rho^{dist(i,j)}\]
where dist
- Euclidean distance between row-vectors of repeated effect matrix for subject i
and j
, 1 > ρ > -1.
SPPOW = SpatialPower()
sourceMetida.Toeplitz
Metida.Toeplitz
— FunctionToeplitz()
Toeplitz covariance type. Only for G matrix.
TOEP = Toeplitz()
\[\begin{bmatrix} 1 & \rho_1 & \rho_2 & \rho_3 \\
\rho_1 & 1 & \rho_1 & \rho_2 \\
\rho_2 & \rho_1 & 1 & \rho_1 \\
\rho_3 & \rho_2 & \rho_1 & 1
-\end{bmatrix}\sigma^2\]
sourceMetida.ToeplitzParameterized
Metida.ToeplitzParameterized
— FunctionToeplitzParameterized(p::Int)
Toeplitz covariance type with parameter p, (number of bands = p - 1, if p = 1 it's equal SI structure).
TOEPP(p) = ToeplitzParameterized(p)
sourceMetida.Unstructured
Metida.Unstructured
— FunctionUnstructured()
Unstructured covariance structure with t*(t+1)/2-t
paremeters where t
- number of factor levels, t*(t+1)/2-2t
of them is covariance (ρ) patemeters. All levels for repeated effect should be unique within each subject.
UN = Unstructured()
sourceMethods
Metida.caic
Metida.caic
— Functioncaic(lmm::LMM)
Conditional Akaike Information Criterion.
sourceMetida.coefn
Metida.coefn
— Functioncoefn(lmm)
Coef number.
sourceMetida.dof_satter
Metida.dof_satter
— Functiondof_satter(lmm::LMM{T}, l) where T
Return Satterthwaite approximation for the denominator degrees of freedom, where l
is a contrast vector (estimable linear combination of fixed effect coefficients vector (β
).
\[df = \frac{2(LCL')^{2}}{g'Ag}\]
Where: $A = 2H^{-1}$, $g = \triangledown_{\theta}(LC^{-1}_{\theta}L')$
sourcedof_satter(lmm::LMM{T}, n::Int) where T
Return Satterthwaite approximation for the denominator degrees of freedom, where n
- coefficient number.
sourcedof_satter(lmm::LMM{T}) where T
Return Satterthwaite approximation for the denominator degrees of freedom for all coefficients.
sourcedof_satter(lmm::LMM{T}, l::Matrix) where T
Return Satterthwaite approximation for the denominator degrees of freedom for conrast matrix l
.
For size(l, 1)
> 1:
\[df = \frac{2E}{E - rank(LCL')}\]
where:
- let $LCL' = QΛQ^{-1}$, where $QΛQ^{-1}$ - spectral decomposition of $LCL'$
- $Lq_i$ is the i-th row of $Q^{-1}L$
- $A = 2H^{-1}$, $g = \triangledown_{\theta}(Lq_i C^{-1}_{\theta} Lq_i')$
- $v_i = \frac{2*Λ_{i,i}^2}{g' * A * g}$
- $E = \sum_{i=1}^n {\frac{v_i}(v_i - 2)}$ for $v_i > 2$
sourceMetida.estimate
Metida.estimate
— Functionestimate(lmm, l::AbstractVector; level = 0.95, name = "Estimate")
Estimate table for l vector. Satter DF used.
sourceestimate(lmm; level = 0.95)
Estimates table. Satter DF used.
sourceMetida.getlog
Metida.getlog
— Functiongetlog(lmm::LMM)
Return fitting log.
sourceMetida.gmatrix
Metida.gmatrix
— Functiongmatrix(lmm::LMM{T}, r::Int) where T
sourceMetida.hessian
Metida.hessian
— Functionhessian(lmm, theta)
Calculate Hessian matrix of REML for theta.
sourceMetida.lcontrast
Metida.lcontrast
— Functionlcontrast(lmm::LMM, i::Int)
L-contrast matrix for i
fixed effect.
sourceMetida.nblocks
Metida.nblocks
— FunctionNumber of blocks
sourceMetida.rand
Base.rand
— Functionrand(rng::AbstractRNG, lmm::LMM{T}) where T
Generate random responce vector for fitted 'lmm' model.
sourcerand(rng::AbstractRNG, lmm::LMM{T}; theta) where T
Generate random responce vector 'lmm' model, theta covariance vector, and zero means.
sourcerand(rng::AbstractRNG, lmm::LMM{T}; theta, beta) where T
Generate random responce vector 'lmm' model, theta covariance vector and mean's vector.
sourceMetida.rand
Random.rand!
— Functionrand!(v::AbstractVector, lmm::LMM) = rand!(default_rng(), v, lmm, lmm.result.theta, lmm.result.beta)
Generate random responce vector for fitted 'lmm' model, store results in v
.
sourcerand!(rng::AbstractRNG, lmm::LMM{T}; theta) where T
Generate random responce vector 'lmm' model, theta covariance vector, and zero means, store results in v
.
sourceMetida.raneff
Metida.raneff
— Functionraneff(lmm::LMM{T}, i)
Vector of random effect coefficients for block i
.
sourceraneff(lmm::LMM{T})
Vector of random effect coefficients for all subjects by each random effect.
sourceMetida.raneffn
Metida.raneffn
— Functionraneffn(lmm)
Retuen number of random effects.
sourceMetida.rankx
Metida.rankx
— Functionrankx(lmm::LMM)
Return rank of X
matrix.
sourceMetida.rmatrix
Metida.rmatrix
— Functionrmatrix(lmm::LMM{T}, i::Int) where T
sourceMetida.theta
Metida.theta
— Functiontheta(lmm::LMM)
Return theta vector.
sourceMetida.thetalength
Metida.thetalength
— Functionthetalength(lmm::LMM)
Length of theta vector.
sourceMetida.vmatrix
Metida.vmatrix!
— Functionvmatrix!(V, θ, lmm, i)
Update variance-covariance matrix V for i bolock. Upper triangular updated.
sourceStatsAPI
Metida.aic
StatsAPI.aic
— FunctionStatsBase.aic(lmm::LMM)
Akaike Information Criterion.
sourceMetida.aicc
StatsAPI.aicc
— FunctionStatsBase.aicc(lmm::LMM)
Corrected Akaike Information Criterion.
sourceMetida.bic
StatsAPI.bic
— FunctionStatsBase.bic(lmm::LMM)
Bayesian information criterion.
sourceMetida.coef
StatsAPI.coef
— FunctionStatsBase.coef(lmm::LMM) = copy(lmm.result.beta)
Model coefficients (β).
sourceMetida.coefnames
StatsAPI.coefnames
— FunctionStatsBase.coefnames(lmm::LMM) = StatsBase.coefnames(lmm.mf)
Coefficients names.
sourceMetida.coeftable
StatsAPI.coeftable
— Functioncoeftable(lmm::LMM)
Return coefficients table.
sourceMetida.confint
StatsAPI.confint
— FunctionStatsBase.confint(lmm::LMM{T}; level::Real=0.95, ddf::Symbol = :satter) where T
Confidece interval for coefficients.
ddf = :satter/:residual
\[CI_{U/L} = β ± SE * t_{ddf, 1-α/2}\]
See also: dof_satter
, dof_residual
sourceStatsBase.confint(lmm::LMM{T}, i::Int; level::Real=0.95, ddf::Symbol = :satter) where T
Confidece interval for coefficient i
.
sourceStatsBase.confint(br::BootstrapResult, n::Int; level::Float64=0.95, method=:bp, metric = :coef, delrml = false)
Confidence interval for bootstrap result.
*method:
- :bp - bootstrap percentile;
- :rbp - reverse bootstrap percentile;
- :norm - Normal distribution;
- :bcnorm - Bias corrected Normal distribution;
- :jn - bias corrected (jackknife resampling).
sourceMetida.crossmodelmatrix
StatsAPI.crossmodelmatrix
— Functioncrossmodelmatrix(lmm::LMM)
Return X'X.
sourceMetida.dof
StatsAPI.dof
— FunctionStatsBase.dof(lmm::LMM)
DOF.
sourceMetida.dof_residual
StatsAPI.dof_residual
— FunctionStatsBase.dof_residual(lmm::LMM)
DOF residuals: N - rank(X), where N - total number of observations.
sourceMetida.fit
StatsAPI.fit
— Functionfit(::Type{T}, f::FormulaTerm, data;
+\end{bmatrix}\sigma^2\]
sourceMetida.ToeplitzParameterized
Metida.ToeplitzParameterized
— FunctionToeplitzParameterized(p::Int)
Toeplitz covariance type with parameter p, (number of bands = p - 1, if p = 1 it's equal SI structure).
TOEPP(p) = ToeplitzParameterized(p)
sourceMetida.Unstructured
Metida.Unstructured
— FunctionUnstructured()
Unstructured covariance structure with t*(t+1)/2-t
paremeters where t
- number of factor levels, t*(t+1)/2-2t
of them is covariance (ρ) patemeters. All levels for repeated effect should be unique within each subject.
UN = Unstructured()
sourceMethods
Metida.caic
Metida.caic
— Functioncaic(lmm::LMM)
Conditional Akaike Information Criterion.
sourceMetida.coefn
Metida.coefn
— Functioncoefn(lmm)
Coef number.
sourceMetida.dof_satter
Metida.dof_satter
— Functiondof_satter(lmm::LMM{T}, l) where T
Return Satterthwaite approximation for the denominator degrees of freedom, where l
is a contrast vector (estimable linear combination of fixed effect coefficients vector (β
).
\[df = \frac{2(LCL')^{2}}{g'Ag}\]
Where: $A = 2H^{-1}$, $g = \triangledown_{\theta}(LC^{-1}_{\theta}L')$
sourcedof_satter(lmm::LMM{T}, n::Int) where T
Return Satterthwaite approximation for the denominator degrees of freedom, where n
- coefficient number.
sourcedof_satter(lmm::LMM{T}) where T
Return Satterthwaite approximation for the denominator degrees of freedom for all coefficients.
sourcedof_satter(lmm::LMM{T}, l::Matrix) where T
Return Satterthwaite approximation for the denominator degrees of freedom for conrast matrix l
.
For size(l, 1)
> 1:
\[df = \frac{2E}{E - rank(LCL')}\]
where:
- let $LCL' = QΛQ^{-1}$, where $QΛQ^{-1}$ - spectral decomposition of $LCL'$
- $Lq_i$ is the i-th row of $Q^{-1}L$
- $A = 2H^{-1}$, $g = \triangledown_{\theta}(Lq_i C^{-1}_{\theta} Lq_i')$
- $v_i = \frac{2*Λ_{i,i}^2}{g' * A * g}$
- $E = \sum_{i=1}^n {\frac{v_i}(v_i - 2)}$ for $v_i > 2$
sourceMetida.estimate
Metida.estimate
— Functionestimate(lmm, l::AbstractVector; level = 0.95, name = "Estimate")
Estimate table for l vector. Satter DF used.
sourceestimate(lmm; level = 0.95)
Estimates table. Satter DF used.
sourceMetida.getlog
Metida.getlog
— Functiongetlog(lmm::LMM)
Return fitting log.
sourceMetida.gmatrix
Metida.gmatrix
— Functiongmatrix(lmm::LMM{T}, r::Int) where T
sourceMetida.hessian
Metida.hessian
— Functionhessian(lmm, theta)
Calculate Hessian matrix of REML for theta.
sourceMetida.lcontrast
Metida.lcontrast
— Functionlcontrast(lmm::LMM, i::Int)
L-contrast matrix for i
fixed effect.
sourceMetida.nblocks
Metida.nblocks
— FunctionNumber of blocks
sourceMetida.rand
Base.rand
— Functionrand(rng::AbstractRNG, lmm::LMM{T}) where T
Generate random responce vector for fitted 'lmm' model.
sourcerand(rng::AbstractRNG, lmm::LMM{T}; theta) where T
Generate random responce vector 'lmm' model, theta covariance vector, and zero means.
sourcerand(rng::AbstractRNG, lmm::LMM{T}; theta, beta) where T
Generate random responce vector 'lmm' model, theta covariance vector and mean's vector.
sourceMetida.rand
Random.rand!
— Functionrand!(v::AbstractVector, lmm::LMM) = rand!(default_rng(), v, lmm, lmm.result.theta, lmm.result.beta)
Generate random responce vector for fitted 'lmm' model, store results in v
.
sourcerand!(rng::AbstractRNG, lmm::LMM{T}; theta) where T
Generate random responce vector 'lmm' model, theta covariance vector, and zero means, store results in v
.
sourceMetida.raneff
Metida.raneff
— Functionraneff(lmm::LMM{T}, i)
Vector of random effect coefficients for block i
.
sourceraneff(lmm::LMM{T})
Vector of random effect coefficients for all subjects by each random effect.
sourceMetida.raneffn
Metida.raneffn
— Functionraneffn(lmm)
Retuen number of random effects.
sourceMetida.rankx
Metida.rankx
— Functionrankx(lmm::LMM)
Return rank of X
matrix.
sourceMetida.rmatrix
Metida.rmatrix
— Functionrmatrix(lmm::LMM{T}, i::Int) where T
sourceMetida.theta
Metida.theta
— Functiontheta(lmm::LMM)
Return theta vector.
sourceMetida.thetalength
Metida.thetalength
— Functionthetalength(lmm::LMM)
Length of theta vector.
sourceMetida.vmatrix
Metida.vmatrix
— Functionvmatrix(lmm::LMM, i::Int)
Return variance-covariance matrix V for i bolock.
sourceMetida.vmatrix!
Metida.vmatrix!
— Functionvmatrix!(V, θ, lmm, i)
Update variance-covariance matrix V for i bolock. Upper triangular updated.
sourceMetida.m2logreml
Metida.m2logreml
— Functionm2logreml(lmm::LMM, θ = theta(lmm); maxthreads::Int = num_cores())
-2 logREML
sourceMetida.logreml
Metida.logreml
— Functionlogreml(lmm::LMM, θ = theta(lmm); maxthreads::Int = num_cores())
logREML
sourceStatsAPI
Metida.aic
StatsAPI.aic
— FunctionStatsBase.aic(lmm::LMM)
Akaike Information Criterion.
sourceMetida.aicc
StatsAPI.aicc
— FunctionStatsBase.aicc(lmm::LMM)
Corrected Akaike Information Criterion.
sourceMetida.bic
StatsAPI.bic
— FunctionStatsBase.bic(lmm::LMM)
Bayesian information criterion.
sourceMetida.coef
StatsAPI.coef
— FunctionStatsBase.coef(lmm::LMM) = copy(lmm.result.beta)
Model coefficients (β).
sourceMetida.coefnames
StatsAPI.coefnames
— FunctionStatsBase.coefnames(lmm::LMM) = StatsBase.coefnames(lmm.mf)
Coefficients names.
sourceMetida.coeftable
StatsAPI.coeftable
— Functioncoeftable(lmm::LMM)
Return coefficients table.
sourceMetida.confint
StatsAPI.confint
— FunctionStatsBase.confint(lmm::LMM{T}; level::Real=0.95, ddf::Symbol = :satter) where T
Confidece interval for coefficients.
ddf = :satter/:residual
\[CI_{U/L} = β ± SE * t_{ddf, 1-α/2}\]
See also: dof_satter
, dof_residual
sourceStatsBase.confint(lmm::LMM{T}, i::Int; level::Real=0.95, ddf::Symbol = :satter) where T
Confidece interval for coefficient i
.
sourceStatsBase.confint(br::BootstrapResult, n::Int; level::Float64=0.95, method=:bp, metric = :coef, delrml = false)
Confidence interval for bootstrap result.
*method:
- :bp - bootstrap percentile;
- :rbp - reverse bootstrap percentile;
- :norm - Normal distribution;
- :bcnorm - Bias corrected Normal distribution;
- :jn - bias corrected (jackknife resampling).
sourceMetida.crossmodelmatrix
StatsAPI.crossmodelmatrix
— Functioncrossmodelmatrix(lmm::LMM)
Return X'X.
sourceMetida.dof
StatsAPI.dof
— FunctionStatsBase.dof(lmm::LMM)
DOF.
sourceMetida.dof_residual
StatsAPI.dof_residual
— FunctionStatsBase.dof_residual(lmm::LMM)
DOF residuals: N - rank(X), where N - total number of observations.
sourceMetida.fit
StatsAPI.fit
— Functionfit(::Type{T}, f::FormulaTerm, data;
contrasts=Dict{Symbol,Any}(),
random::Union{Nothing, VarEffect, Vector{VarEffect}} = nothing,
repeated::Union{Nothing, VarEffect} = nothing,
-kwargs...)
Fit LMM model with @formula.
Keywords see fit!
sourcesource fit(::Type{T}, f::LMMformula, data;
contrasts=Dict{Symbol,Any}(),
-kwargs...) where T <: LMM
Fit LMM model with @lmmformula
.
Keywords see fit!
sourceMetida.fit
StatsAPI.fit!
— Functionfit!(lmm::LMM{T}; kwargs...
-) where T
Fit LMM model.
Keywords:
solver
- :default / :nlopt for using with MetidaNLopt.jl/ :cuda for using with MetidaCu.jlverbose
- :auto / 1 / 2 / 3 - - 1 - only log, 2 - log and print, 3 - print only errors, other log, 0 (or any other value) - no loggingvarlinkf
- :exp / :sq / :identity refrholinkf
- :sigm / :atan / :sqsigm / :psigmaifirst
- first iteration with AI-like method - :default / :ai / :scoreaifmax
- maximum pre-optimization stepsg_tol
- absolute tolerance in the gradientx_tol
- absolute tolerance of theta vectorf_tol
- absolute tolerance in changes of the REMLhes
- calculate REML Hessianinit
- initial theta valuesio
- output IOtime_limit
- time limit = 120 seciterations
- maximum iterations = 300refitinit
- true/false - if true
- use last values for initial condition (false
by default)optmethod
- Optimization method. Look at Optim.jl documentation. (Newton by default)singtol
- singular tolerance = 1e-8maxthreads
- maximum threads = min(num_cores(), Threads.nthreads())
sourceislinear
StatsAPI.islinear
— FunctionStatsBase.islinear(model::LMM)
sourceisfitted
StatsAPI.isfitted
— FunctionStatsBase.isfitted(lmm::LMM)
sourceMetida.loglikelihood
StatsAPI.loglikelihood
— FunctionStatsBase.loglikelihood(lmm::LMM)
Return loglikelihood value.
sourceMetida.modelmatrix
StatsAPI.modelmatrix
— FunctionStatsBase.modelmatrix(lmm::LMM)
Fixed effects matrix.
sourceMetida.nobs
StatsAPI.nobs
— FunctionStatsBase.nobs(lmm::MetiaModel)
Number of observations.
sourceMetida.response
StatsAPI.response
— FunctionStatsBase.response(lmm::LMM)
Response vector.
sourceMetida.responsename
StatsAPI.responsename
— Functionresponsename(lmm::LMM)
Responce varible name.
sourceMetida.stderror
StatsAPI.stderror
— FunctionStatsBase.stderror(lmm::LMM)
Standard error
sourceMetida.vcov
StatsAPI.vcov
— FunctionStatsBase.vcov(lmm::LMM)
Variance-covariance matrix of β.
sourceExperimental
Metida.SpatialExponentialD
Metida.SpatialExponentialD
— FunctionSpatialExponentialD()
Warning Experimental
Same as SpatialExponential, but add D to all diagonal elements.
SPEXPD = SpatialExponentialD()
sourceMetida.SpatialGaussianD
Metida.SpatialGaussianD
— FunctionSpatialGaussianD()
Warning Experimental
Same as SpatialGaussianD, but add D to all diagonal elements.
SPGAUD = SpatialGaussianD()
sourceMetida.SpatialPowerD
Metida.SpatialPowerD
— FunctionSpatialPowerD()
Warning Experimental
Same as SpatialPower, but add D to all diagonal elements.
SPPOWD = SpatialPowerD()
sourceMetida.ScaledWeightedCov
Metida.ScaledWeightedCov
— FunctionScaledWeightedCov(wtsm::AbstractMatrix{T})
Warning Experimental
Scaled weighted covariance matrix, where wtsm
- NxN
within block correlation matrix (N - total number of observations). Used only for repeated effect.
SWC = ScaledWeightedCov
\[R = Corr(W) * \sigma_c^2\]
where $Corr(W)$ - diagonal correlation matrix.
example:
matwts = Symmetric(UnitUpperTriangular(rand(size(df0,1), size(df0,1))))
+kwargs...) where T <: LMM
Fit LMM model with @lmmformula
.
Keywords see fit!
sourceMetida.fit
StatsAPI.fit!
— Functionfit!(lmm::LMM{T}; kwargs...
+) where T
Fit LMM model.
Keywords:
solver
- :default / :nlopt for using with MetidaNLopt.jl/ :cuda for using with MetidaCu.jlverbose
- :auto / 1 / 2 / 3 - - 1 - only log, 2 - log and print, 3 - print only errors, other log, 0 (or any other value) - no loggingvarlinkf
- :exp / :sq / :identity refrholinkf
- :sigm / :atan / :sqsigm / :psigmaifirst
- first iteration with AI-like method - :default / :ai / :scoreaifmax
- maximum pre-optimization stepsg_tol
- absolute tolerance in the gradientx_tol
- absolute tolerance of theta vectorf_tol
- absolute tolerance in changes of the REMLhes
- calculate REML Hessianinit
- initial theta valuesio
- output IOtime_limit
- time limit = 120 seciterations
- maximum iterations = 300refitinit
- true/false - if true
- use last values for initial condition (false
by default)optmethod
- Optimization method. Look at Optim.jl documentation. (Newton by default)singtol
- singular tolerance = 1e-8maxthreads
- maximum threads = min(num_cores(), Threads.nthreads())
sourceislinear
StatsAPI.islinear
— FunctionStatsBase.islinear(model::LMM)
sourceisfitted
StatsAPI.isfitted
— FunctionStatsBase.isfitted(lmm::LMM)
sourceMetida.loglikelihood
StatsAPI.loglikelihood
— FunctionStatsBase.loglikelihood(lmm::LMM)
Return loglikelihood value.
sourceMetida.modelmatrix
StatsAPI.modelmatrix
— FunctionStatsBase.modelmatrix(lmm::LMM)
Fixed effects matrix.
sourceMetida.nobs
StatsAPI.nobs
— FunctionStatsBase.nobs(lmm::MetiaModel)
Number of observations.
sourceMetida.response
StatsAPI.response
— FunctionStatsBase.response(lmm::LMM)
Response vector.
sourceMetida.responsename
StatsAPI.responsename
— Functionresponsename(lmm::LMM)
Responce varible name.
sourceMetida.stderror
StatsAPI.stderror
— FunctionStatsBase.stderror(lmm::LMM)
Standard error
sourceMetida.vcov
StatsAPI.vcov
— FunctionStatsBase.vcov(lmm::LMM)
Variance-covariance matrix of β.
sourceExperimental
Metida.SpatialExponentialD
Metida.SpatialExponentialD
— FunctionSpatialExponentialD()
Warning Experimental
Same as SpatialExponential, but add D to all diagonal elements.
SPEXPD = SpatialExponentialD()
sourceMetida.SpatialGaussianD
Metida.SpatialGaussianD
— FunctionSpatialGaussianD()
Warning Experimental
Same as SpatialGaussianD, but add D to all diagonal elements.
SPGAUD = SpatialGaussianD()
sourceMetida.SpatialPowerD
Metida.SpatialPowerD
— FunctionSpatialPowerD()
Warning Experimental
Same as SpatialPower, but add D to all diagonal elements.
SPPOWD = SpatialPowerD()
sourceMetida.ScaledWeightedCov
Metida.ScaledWeightedCov
— FunctionScaledWeightedCov(wtsm::AbstractMatrix{T})
Warning Experimental
Scaled weighted covariance matrix, where wtsm
- NxN
within block correlation matrix (N - total number of observations). Used only for repeated effect.
SWC = ScaledWeightedCov
\[R = Corr(W) * \sigma_c^2\]
where $Corr(W)$ - diagonal correlation matrix.
example:
matwts = Symmetric(UnitUpperTriangular(rand(size(df0,1), size(df0,1))))
lmm = LMM(@formula(var~sequence+period+formulation), df0;
repeated = VarEffect(@covstr(1|subject), SWC(matwts)))
fit!(lmm)
-
Note There is no wtsm
checks for symmetricity or values.
sourceMetida.dof_contain
Metida.dof_contain
— Functiondof_contain(lmm, i)
Warning Experimental! Compute rank(XZi) for each random effect that syntactically contain factor assigned for β[i] element (Where Zi - Z matrix for random effect i). Minimum returned. If no random effect found N - rank(XZ) returned.
sourceMetida.typeiii
Metida.typeiii
— Functiontypeiii(lmm::LMM{T}; ddf::Symbol = :satter) where T
Warning Experimental
Type III table.
sourceMetida.MILMM
Metida.MILMM
— TypeMILMM(lmm::LMM, data)
Multiple imputation model.
sourceMetida.RawCoding
Metida.RawCoding
— Typemutable struct RawCoding <: AbstractContrasts
Contrast for CategoricalTerm to get column "as it is" for model matrix.
sourceNot API functions
Metida.contrast
Metida.contrast
— Functioncontrast(lmm, l::AbstractMatrix; name::String = "Contrast", ddf = :satter)
User contrast table. ddf = :satter
or :residual
or any number for direct ddf setting.
sourceMetida.fvalue
Metida.fvalue
— Functionfvalue(lmm::LMM, l::Matrix)
F value for contrast matrix l
.
\[F = \frac{\beta'L'(LCL')^{-1}L\beta}{rank(LCL')}\]
sourceMetida.mulαβαtinc
Metida.mulαβαtinc!
— Functionmulαβαtinc!(θ::AbstractMatrix, A::AbstractMatrix, B::AbstractMatrix)
θ + A * B * A'
Change θ (only upper triangle). B is symmetric.
sourcemulαβαtinc!(θ::AbstractMatrix, A::AbstractMatrix, B::AbstractMatrix, alpha)
θ + A * B * A' * alpha
Change θ (only upper triangle). B is symmetric.
sourcemulαβαtinc!(θ::AbstractVector{T}, A::AbstractMatrix, B::AbstractMatrix, a::AbstractVector, b::AbstractVector, alpha) where T
θ + A * B * (a - b) * alpha
Change θ (only upper triangle). B is symmetric.
sourceMetida.mulθ₃
Metida.mulθ₃
— Functionmulθ₃(y, X, β, V::AbstractMatrix{T})::T where T
(y - X * β)' * (-V) * (y - X * β)
use only upper triangle of V
sourceMetida.mulαtβinc
Metida.mulαtβinc!
— Functionmulαtβinc!(θ::AbstractVector{T}, A::AbstractMatrix, b::AbstractVector) where T
θ + A' * b
Change θ.
sourceMetida.tname
Metida.tname
— FunctionTerm name.
sourceMetida.raneflenv
Metida.raneflenv
— FunctionReturn number of subject foe each random effet in current block.
sourceMetida.edistance
Metida.edistance
— Functionedistance(mx::AbstractMatrix{T}, i::Int, j::Int) where T
Distance between vector mx[i, :] and mx[j, :].
sourceSettings
This document was generated with Documenter.jl version 1.7.0 on Friday 20 September 2024. Using Julia version 1.8.5.
+
There is no wtsm
checks for symmetricity or values.
Metida.dof_contain
Metida.dof_contain
— Functiondof_contain(lmm, i)
Experimental! Compute rank(XZi) for each random effect that syntactically contain factor assigned for β[i] element (Where Zi - Z matrix for random effect i). Minimum returned. If no random effect found N - rank(XZ) returned.
Metida.typeiii
Metida.typeiii
— Functiontypeiii(lmm::LMM{T}; ddf::Symbol = :satter) where T
Experimental
Type III table.
Metida.MILMM
Metida.MILMM
— TypeMILMM(lmm::LMM, data)
Multiple imputation model.
Metida.RawCoding
Metida.RawCoding
— Typemutable struct RawCoding <: AbstractContrasts
Contrast for CategoricalTerm to get column "as it is" for model matrix.
Not API functions
Metida.contrast
Metida.contrast
— Functioncontrast(lmm, l::AbstractMatrix; name::String = "Contrast", ddf = :satter)
User contrast table. ddf = :satter
or :residual
or any number for direct ddf setting.
Metida.fvalue
Metida.fvalue
— Functionfvalue(lmm::LMM, l::Matrix)
F value for contrast matrix l
.
\[F = \frac{\beta'L'(LCL')^{-1}L\beta}{rank(LCL')}\]
Metida.mulαβαtinc
Metida.mulαβαtinc!
— Functionmulαβαtinc!(θ::AbstractMatrix, A::AbstractMatrix, B::AbstractMatrix)
θ + A * B * A'
Change θ (only upper triangle). B is symmetric.
mulαβαtinc!(θ::AbstractMatrix, A::AbstractMatrix, B::AbstractMatrix, alpha)
θ + A * B * A' * alpha
Change θ (only upper triangle). B is symmetric.
mulαβαtinc!(θ::AbstractVector{T}, A::AbstractMatrix, B::AbstractMatrix, a::AbstractVector, b::AbstractVector, alpha) where T
θ + A * B * (a - b) * alpha
Change θ (only upper triangle). B is symmetric.
Metida.mulθ₃
Metida.mulθ₃
— Functionmulθ₃(y, X, β, V::AbstractMatrix{T})::T where T
(y - X * β)' * (-V) * (y - X * β)
use only upper triangle of V
Metida.mulαtβinc
Metida.mulαtβinc!
— Functionmulαtβinc!(θ::AbstractVector{T}, A::AbstractMatrix, b::AbstractVector) where T
θ + A' * b
Change θ.
Metida.tname
Metida.tname
— FunctionTerm name.
Metida.raneflenv
Metida.raneflenv
— FunctionReturn number of subject foe each random effet in current block.
Metida.edistance
Metida.edistance
— Functionedistance(mx::AbstractMatrix{T}, i::Int, j::Int) where T
Distance between vector mx[i, :] and mx[j, :].
Metida.m2logml
Metida.m2logml
— Functionm2logml(lmm::LMM, β = coef(lmm), θ = theta(lmm); maxthreads::Int = num_cores())
-2 logML
Metida.logml
Metida.logml
— Functionlogml(lmm::LMM, beta = coef(lmm), θ = theta(lmm); maxthreads::Int = num_cores())
logML