diff --git a/dev/.documenter-siteinfo.json b/dev/.documenter-siteinfo.json index 35a1bb8..d141559 100644 --- a/dev/.documenter-siteinfo.json +++ b/dev/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.8.5","generation_timestamp":"2024-09-20T09:32:52","documenter_version":"1.7.0"}} \ No newline at end of file +{"documenter":{"julia_version":"1.8.5","generation_timestamp":"2024-09-27T13:26:36","documenter_version":"1.7.0"}} \ No newline at end of file diff --git a/dev/api/index.html b/dev/api/index.html index d0a7415..02d981d 100644 --- a/dev/api/index.html +++ b/dev/api/index.html @@ -1,5 +1,5 @@ -API · Metida.jl

API

Basic

@covstr

Metida.@covstrMacro
@covstr(ex)

Macros for random/repeated effect model.

Example

@covstr(factor|subject)
source

@lmmformula

Metida.@lmmformulaMacro
@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.@covstrMacro
@covstr(ex)

Macros for random/repeated effect model.

Example

@covstr(factor|subject)
source

@lmmformula

Metida.@lmmformulaMacro
@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.

source

Metida.CovarianceType

LMM

Metida.LMMType
LMM(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

source

VarEffect

Metida.VarEffectType
VarEffect(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.

source

Metida.CovarianceType

LMM

Metida.LMMType
LMM(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

source

VarEffect

Metida.VarEffectType
VarEffect(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()))
source

Covariance structures

Metida.Autoregressive

Metida.AutoregressiveFunction
Autoregressive()

Autoregressive covariance type.

AR = Autoregressive()

\[\begin{bmatrix} 1 & \rho & \rho^2 & \rho^3 \\ +VarEffect(@covstr(1 + formulation|subject), CSH; coding = Dict(:formulation => StatsModels.DummyCoding()))

source

Covariance structures

Metida.Autoregressive

Metida.AutoregressiveFunction
Autoregressive()

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\]

source

Metida.AutoregressiveMovingAverage

Metida.AutoregressiveMovingAverageFunction
AutoregressiveMovingAverage()

Autoregressive moving average covariance type.

ARMA = AutoregressiveMovingAverage()

\[\begin{bmatrix} 1 & \gamma & \gamma\rho & \gamma\rho^2 \\ +\end{bmatrix}\sigma^2\]

source

Metida.AutoregressiveMovingAverage

Metida.AutoregressiveMovingAverageFunction
AutoregressiveMovingAverage()

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\]

source

Metida.CompoundSymmetry

Metida.CompoundSymmetryFunction
CompoundSymmetry()

Compound symmetry covariance type.

CS = CompoundSymmetry()

\[\begin{bmatrix} 1 & \rho & \rho & \rho \\ +\end{bmatrix}\sigma^2\]

source

Metida.CompoundSymmetry

Metida.CompoundSymmetryFunction
CompoundSymmetry()

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\]

source

Metida.Diag

Metida.DiagFunction
Diag()

Diagonal covariance type.

DIAG = Diag()

\[\begin{bmatrix} \sigma_a^2 & 0 & 0 \\ 0 & \sigma_b^2 & 0 \\ 0 & 0 & \sigma_c^2 \end{bmatrix}\]

source

Metida.HeterogeneousAutoregressive

Metida.HeterogeneousAutoregressiveFunction
HeterogeneousAutoregressive()

Heterogeneous autoregressive covariance type.

ARH = HeterogeneousAutoregressive()

\[\begin{bmatrix} +\end{bmatrix}\sigma^2\]

source

Metida.Diag

Metida.DiagFunction
Diag()

Diagonal covariance type.

DIAG = Diag()

\[\begin{bmatrix} \sigma_a^2 & 0 & 0 \\ 0 & \sigma_b^2 & 0 \\ 0 & 0 & \sigma_c^2 \end{bmatrix}\]

source

Metida.HeterogeneousAutoregressive

Metida.HeterogeneousAutoregressiveFunction
HeterogeneousAutoregressive()

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}\]

source

Metida.HeterogeneousCompoundSymmetry

Metida.HeterogeneousCompoundSymmetry

Metida.HeterogeneousCompoundSymmetryFunction
HeterogeneousCompoundSymmetry()

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}\]

source

Metida.HeterogeneousToeplitz

Metida.HeterogeneousToeplitzFunction
HeterogeneousToeplitz()

Heterogeneous toeplitz covariance type. Only for G matrix.

TOEPH = HeterogeneousToeplitz()

\[\begin{bmatrix} +\end{bmatrix}\]

source

Metida.HeterogeneousToeplitz

Metida.HeterogeneousToeplitzFunction
HeterogeneousToeplitz()

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}\]

source

Metida.HeterogeneousToeplitzParameterized

Metida.HeterogeneousToeplitzParameterizedFunction
HeterogeneousToeplitzParameterized(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)

source

Metida.ScaledIdentity

Metida.ScaledIdentityFunction
ScaledIdentity()

Scaled identity covariance type.

SI = ScaledIdentity()

\[\begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}\sigma^{2}\]

source

Metida.SpatialExponential

Metida.SpatialExponentialFunction
SpatialExponential()

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()

source

Metida.SpatialGaussian

Metida.SpatialGaussianFunction
SpatialGaussian()

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()

source

Metida.SpatialPower

Metida.SpatialPowerFunction
SpatialPower()

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()

source

Metida.Toeplitz

Metida.ToeplitzFunction
Toeplitz()

Toeplitz covariance type. Only for G matrix.

TOEP = Toeplitz()

\[\begin{bmatrix} 1 & \rho_1 & \rho_2 & \rho_3 \\ +\end{bmatrix}\]

source

Metida.HeterogeneousToeplitzParameterized

Metida.HeterogeneousToeplitzParameterizedFunction
HeterogeneousToeplitzParameterized(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)

source

Metida.ScaledIdentity

Metida.ScaledIdentityFunction
ScaledIdentity()

Scaled identity covariance type.

SI = ScaledIdentity()

\[\begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}\sigma^{2}\]

source

Metida.SpatialExponential

Metida.SpatialExponentialFunction
SpatialExponential()

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()

source

Metida.SpatialGaussian

Metida.SpatialGaussianFunction
SpatialGaussian()

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()

source

Metida.SpatialPower

Metida.SpatialPowerFunction
SpatialPower()

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()

source

Metida.Toeplitz

Metida.ToeplitzFunction
Toeplitz()

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\]

source

Metida.ToeplitzParameterized

Metida.ToeplitzParameterizedFunction
ToeplitzParameterized(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)

source

Metida.Unstructured

Metida.UnstructuredFunction
Unstructured()

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()

source

Methods

Metida.caic

Metida.caicFunction
caic(lmm::LMM)

Conditional Akaike Information Criterion.

source

Metida.coefn

Metida.dof_satter

Metida.dof_satterFunction
dof_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')$

source
dof_satter(lmm::LMM{T}, n::Int) where T

Return Satterthwaite approximation for the denominator degrees of freedom, where n - coefficient number.

source
dof_satter(lmm::LMM{T}) where T

Return Satterthwaite approximation for the denominator degrees of freedom for all coefficients.

source
dof_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$
source

Metida.estimate

Metida.estimateFunction
estimate(lmm, l::AbstractVector; level = 0.95, name = "Estimate")

Estimate table for l vector. Satter DF used.

source
estimate(lmm; level = 0.95)

Estimates table. Satter DF used.

source

Metida.getlog

Metida.gmatrix

Metida.hessian

Metida.lcontrast

Metida.nblocks

Metida.rand

Base.randFunction
rand(rng::AbstractRNG, lmm::LMM{T}) where T

Generate random responce vector for fitted 'lmm' model.

source
rand(rng::AbstractRNG, lmm::LMM{T}; theta) where T

Generate random responce vector 'lmm' model, theta covariance vector, and zero means.

source
rand(rng::AbstractRNG, lmm::LMM{T}; theta, beta) where T

Generate random responce vector 'lmm' model, theta covariance vector and mean's vector.

source

Metida.rand

Random.rand!Function
rand!(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.

source
rand!(rng::AbstractRNG, lmm::LMM{T}; theta) where T

Generate random responce vector 'lmm' model, theta covariance vector, and zero means, store results in v.

source

Metida.raneff

Metida.raneffFunction
raneff(lmm::LMM{T}, i)

Vector of random effect coefficients for block i.

source
raneff(lmm::LMM{T})

Vector of random effect coefficients for all subjects by each random effect.

source

Metida.raneffn

Metida.rankx

Metida.rmatrix

Metida.theta

Metida.thetalength

Metida.vmatrix

Metida.vmatrix!Function
vmatrix!(V, θ, lmm, i)

Update variance-covariance matrix V for i bolock. Upper triangular updated.

source

StatsAPI

Metida.aic

Metida.aicc

StatsAPI.aiccFunction
StatsBase.aicc(lmm::LMM)

Corrected Akaike Information Criterion.

source

Metida.bic

Metida.coef

StatsAPI.coefFunction
StatsBase.coef(lmm::LMM) = copy(lmm.result.beta)

Model coefficients (β).

source

Metida.coefnames

Metida.coeftable

Metida.confint

StatsAPI.confintFunction
StatsBase.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

source
StatsBase.confint(lmm::LMM{T}, i::Int; level::Real=0.95, ddf::Symbol = :satter) where T

Confidece interval for coefficient i.

source

StatsBase.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).
source

Metida.crossmodelmatrix

Metida.dof

Metida.dof_residual

StatsAPI.dof_residualFunction
StatsBase.dof_residual(lmm::LMM)

DOF residuals: N - rank(X), where N - total number of observations.

source

Metida.fit

StatsAPI.fitFunction
fit(::Type{T}, f::FormulaTerm, data;
+\end{bmatrix}\sigma^2\]

source

Metida.ToeplitzParameterized

Metida.ToeplitzParameterizedFunction
ToeplitzParameterized(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)

source

Metida.Unstructured

Metida.UnstructuredFunction
Unstructured()

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()

source

Methods

Metida.caic

Metida.caicFunction
caic(lmm::LMM)

Conditional Akaike Information Criterion.

source

Metida.coefn

Metida.dof_satter

Metida.dof_satterFunction
dof_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')$

source
dof_satter(lmm::LMM{T}, n::Int) where T

Return Satterthwaite approximation for the denominator degrees of freedom, where n - coefficient number.

source
dof_satter(lmm::LMM{T}) where T

Return Satterthwaite approximation for the denominator degrees of freedom for all coefficients.

source
dof_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$
source

Metida.estimate

Metida.estimateFunction
estimate(lmm, l::AbstractVector; level = 0.95, name = "Estimate")

Estimate table for l vector. Satter DF used.

source
estimate(lmm; level = 0.95)

Estimates table. Satter DF used.

source

Metida.getlog

Metida.gmatrix

Metida.hessian

Metida.lcontrast

Metida.nblocks

Metida.rand

Base.randFunction
rand(rng::AbstractRNG, lmm::LMM{T}) where T

Generate random responce vector for fitted 'lmm' model.

source
rand(rng::AbstractRNG, lmm::LMM{T}; theta) where T

Generate random responce vector 'lmm' model, theta covariance vector, and zero means.

source
rand(rng::AbstractRNG, lmm::LMM{T}; theta, beta) where T

Generate random responce vector 'lmm' model, theta covariance vector and mean's vector.

source

Metida.rand

Random.rand!Function
rand!(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.

source
rand!(rng::AbstractRNG, lmm::LMM{T}; theta) where T

Generate random responce vector 'lmm' model, theta covariance vector, and zero means, store results in v.

source

Metida.raneff

Metida.raneffFunction
raneff(lmm::LMM{T}, i)

Vector of random effect coefficients for block i.

source
raneff(lmm::LMM{T})

Vector of random effect coefficients for all subjects by each random effect.

source

Metida.raneffn

Metida.rankx

Metida.rmatrix

Metida.theta

Metida.thetalength

Metida.vmatrix

Metida.vmatrixFunction
vmatrix(lmm::LMM, i::Int)

Return variance-covariance matrix V for i bolock.

source

Metida.vmatrix!

Metida.vmatrix!Function
vmatrix!(V, θ, lmm, i)

Update variance-covariance matrix V for i bolock. Upper triangular updated.

source

Metida.m2logreml

Metida.m2logremlFunction
m2logreml(lmm::LMM, θ = theta(lmm); maxthreads::Int = num_cores())

-2 logREML

source

Metida.logreml

Metida.logremlFunction
logreml(lmm::LMM, θ = theta(lmm); maxthreads::Int = num_cores())

logREML

source

StatsAPI

Metida.aic

Metida.aicc

StatsAPI.aiccFunction
StatsBase.aicc(lmm::LMM)

Corrected Akaike Information Criterion.

source

Metida.bic

Metida.coef

StatsAPI.coefFunction
StatsBase.coef(lmm::LMM) = copy(lmm.result.beta)

Model coefficients (β).

source

Metida.coefnames

Metida.coeftable

Metida.confint

StatsAPI.confintFunction
StatsBase.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

source
StatsBase.confint(lmm::LMM{T}, i::Int; level::Real=0.95, ddf::Symbol = :satter) where T

Confidece interval for coefficient i.

source

StatsBase.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).
source

Metida.crossmodelmatrix

Metida.dof

Metida.dof_residual

StatsAPI.dof_residualFunction
StatsBase.dof_residual(lmm::LMM)

DOF residuals: N - rank(X), where N - total number of observations.

source

Metida.fit

StatsAPI.fitFunction
fit(::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!

source
fit(::Type{T}, f::LMMformula, data;
+kwargs...)

Fit LMM model with @formula.

Keywords see fit!

source
fit(::Type{T}, f::LMMformula, data;
 contrasts=Dict{Symbol,Any}(),  
-kwargs...) where T <: LMM

Fit LMM model with @lmmformula.

Keywords see fit!

source

Metida.fit

StatsAPI.fit!Function
fit!(lmm::LMM{T}; kwargs...
-) where T

Fit LMM model.

Keywords:

  • solver - :default / :nlopt for using with MetidaNLopt.jl/ :cuda for using with MetidaCu.jl
  • verbose - :auto / 1 / 2 / 3 - - 1 - only log, 2 - log and print, 3 - print only errors, other log, 0 (or any other value) - no logging
  • varlinkf - :exp / :sq / :identity ref
  • rholinkf - :sigm / :atan / :sqsigm / :psigm
  • aifirst - first iteration with AI-like method - :default / :ai / :score
  • aifmax - maximum pre-optimization steps
  • g_tol - absolute tolerance in the gradient
  • x_tol - absolute tolerance of theta vector
  • f_tol - absolute tolerance in changes of the REML
  • hes - calculate REML Hessian
  • init - initial theta values
  • io - output IO
  • time_limit - time limit = 120 sec
  • iterations - maximum iterations = 300
  • refitinit - 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-8
  • maxthreads - maximum threads = min(num_cores(), Threads.nthreads())
source

islinear

isfitted

Metida.loglikelihood

Metida.modelmatrix

Metida.nobs

Metida.response

Metida.responsename

Metida.stderror

Metida.vcov

Experimental

Metida.SpatialExponentialD

Metida.SpatialExponentialDFunction
SpatialExponentialD()
Warning

Experimental

Same as SpatialExponential, but add D to all diagonal elements.

SPEXPD = SpatialExponentialD()

source

Metida.SpatialGaussianD

Metida.SpatialGaussianDFunction
SpatialGaussianD()
Warning

Experimental

Same as SpatialGaussianD, but add D to all diagonal elements.

SPGAUD = SpatialGaussianD()

source

Metida.SpatialPowerD

Metida.SpatialPowerDFunction
SpatialPowerD()
Warning

Experimental

Same as SpatialPower, but add D to all diagonal elements.

SPPOWD = SpatialPowerD()

source

Metida.ScaledWeightedCov

Metida.ScaledWeightedCovFunction
ScaledWeightedCov(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!

source

Metida.fit

StatsAPI.fit!Function
fit!(lmm::LMM{T}; kwargs...
+) where T

Fit LMM model.

Keywords:

  • solver - :default / :nlopt for using with MetidaNLopt.jl/ :cuda for using with MetidaCu.jl
  • verbose - :auto / 1 / 2 / 3 - - 1 - only log, 2 - log and print, 3 - print only errors, other log, 0 (or any other value) - no logging
  • varlinkf - :exp / :sq / :identity ref
  • rholinkf - :sigm / :atan / :sqsigm / :psigm
  • aifirst - first iteration with AI-like method - :default / :ai / :score
  • aifmax - maximum pre-optimization steps
  • g_tol - absolute tolerance in the gradient
  • x_tol - absolute tolerance of theta vector
  • f_tol - absolute tolerance in changes of the REML
  • hes - calculate REML Hessian
  • init - initial theta values
  • io - output IO
  • time_limit - time limit = 120 sec
  • iterations - maximum iterations = 300
  • refitinit - 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-8
  • maxthreads - maximum threads = min(num_cores(), Threads.nthreads())
source

islinear

isfitted

Metida.loglikelihood

Metida.modelmatrix

Metida.nobs

Metida.response

Metida.responsename

Metida.stderror

Metida.vcov

Experimental

Metida.SpatialExponentialD

Metida.SpatialExponentialDFunction
SpatialExponentialD()
Warning

Experimental

Same as SpatialExponential, but add D to all diagonal elements.

SPEXPD = SpatialExponentialD()

source

Metida.SpatialGaussianD

Metida.SpatialGaussianDFunction
SpatialGaussianD()
Warning

Experimental

Same as SpatialGaussianD, but add D to all diagonal elements.

SPGAUD = SpatialGaussianD()

source

Metida.SpatialPowerD

Metida.SpatialPowerDFunction
SpatialPowerD()
Warning

Experimental

Same as SpatialPower, but add D to all diagonal elements.

SPPOWD = SpatialPowerD()

source

Metida.ScaledWeightedCov

Metida.ScaledWeightedCovFunction
ScaledWeightedCov(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.

source

Metida.dof_contain

Metida.dof_containFunction
dof_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.

source

Metida.typeiii

Metida.typeiiiFunction
typeiii(lmm::LMM{T}; ddf::Symbol = :satter) where T
Warning

Experimental

Type III table.

source

Metida.MILMM

Metida.RawCoding

Metida.RawCodingType
mutable struct RawCoding <: AbstractContrasts

Contrast for CategoricalTerm to get column "as it is" for model matrix.

source

Not API functions

Metida.contrast

Metida.contrastFunction
contrast(lmm, l::AbstractMatrix; name::String = "Contrast", ddf = :satter)

User contrast table. ddf = :satter or :residual or any number for direct ddf setting.

source

Metida.fvalue

Metida.fvalueFunction
fvalue(lmm::LMM, l::Matrix)

F value for contrast matrix l.

\[F = \frac{\beta'L'(LCL')^{-1}L\beta}{rank(LCL')}\]

source

Metida.mulαβαtinc

Metida.mulαβαtinc!Function
mulαβαtinc!(θ::AbstractMatrix, A::AbstractMatrix, B::AbstractMatrix)

θ + A * B * A'

Change θ (only upper triangle). B is symmetric.

source
mulαβαtinc!(θ::AbstractMatrix, A::AbstractMatrix, B::AbstractMatrix, alpha)

θ + A * B * A' * alpha

Change θ (only upper triangle). B is symmetric.

source
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.

source

Metida.mulθ₃

Metida.mulθ₃Function
mulθ₃(y, X, β, V::AbstractMatrix{T})::T where T

(y - X * β)' * (-V) * (y - X * β)

use only upper triangle of V

source

Metida.mulαtβinc

Metida.mulαtβinc!Function
mulαtβinc!(θ::AbstractVector{T}, A::AbstractMatrix, b::AbstractVector) where T

θ + A' * b

Change θ.

source

Metida.tname

Metida.raneflenv

Metida.edistance

Metida.edistanceFunction
edistance(mx::AbstractMatrix{T}, i::Int, j::Int) where T

Distance between vector mx[i, :] and mx[j, :].

source
+
Note

There is no wtsm checks for symmetricity or values.

source

Metida.dof_contain

Metida.dof_containFunction
dof_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.

source

Metida.typeiii

Metida.typeiiiFunction
typeiii(lmm::LMM{T}; ddf::Symbol = :satter) where T
Warning

Experimental

Type III table.

source

Metida.MILMM

Metida.MILMMType
MILMM(lmm::LMM, data)

Multiple imputation model.

source

Metida.RawCoding

Metida.RawCodingType
mutable struct RawCoding <: AbstractContrasts

Contrast for CategoricalTerm to get column "as it is" for model matrix.

source

Not API functions

Metida.contrast

Metida.contrastFunction
contrast(lmm, l::AbstractMatrix; name::String = "Contrast", ddf = :satter)

User contrast table. ddf = :satter or :residual or any number for direct ddf setting.

source

Metida.fvalue

Metida.fvalueFunction
fvalue(lmm::LMM, l::Matrix)

F value for contrast matrix l.

\[F = \frac{\beta'L'(LCL')^{-1}L\beta}{rank(LCL')}\]

source

Metida.mulαβαtinc

Metida.mulαβαtinc!Function
mulαβαtinc!(θ::AbstractMatrix, A::AbstractMatrix, B::AbstractMatrix)

θ + A * B * A'

Change θ (only upper triangle). B is symmetric.

source
mulαβαtinc!(θ::AbstractMatrix, A::AbstractMatrix, B::AbstractMatrix, alpha)

θ + A * B * A' * alpha

Change θ (only upper triangle). B is symmetric.

source
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.

source

Metida.mulθ₃

Metida.mulθ₃Function
mulθ₃(y, X, β, V::AbstractMatrix{T})::T where T

(y - X * β)' * (-V) * (y - X * β)

use only upper triangle of V

source

Metida.mulαtβinc

Metida.mulαtβinc!Function
mulαtβinc!(θ::AbstractVector{T}, A::AbstractMatrix, b::AbstractVector) where T

θ + A' * b

Change θ.

source

Metida.tname

Metida.tnameFunction
Term name.
source

Metida.raneflenv

Metida.raneflenvFunction
Return number of subject foe each random effet in current block.
source

Metida.edistance

Metida.edistanceFunction
edistance(mx::AbstractMatrix{T}, i::Int, j::Int) where T

Distance between vector mx[i, :] and mx[j, :].

source

Metida.m2logml

Metida.m2logmlFunction
m2logml(lmm::LMM, β = coef(lmm), θ = theta(lmm); maxthreads::Int = num_cores())

-2 logML

source

Metida.logml

Metida.logmlFunction
logml(lmm::LMM, beta = coef(lmm), θ = theta(lmm); maxthreads::Int = num_cores())

logML

source
diff --git a/dev/bench/index.html b/dev/bench/index.html index 4873f26..0e91725 100644 --- a/dev/bench/index.html +++ b/dev/bench/index.html @@ -115,4 +115,4 @@ █▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█ ▁ 7.34 s Histogram: frequency by time 7.37 s < - Memory estimate: 5.04 GiB, allocs estimate: 46549.

Conclusion

MixedModels.jl faster than Metida.jl in similar cases, but Metida.jl can be used with different covariance structures for random and repeated effects. MetidaNLopt have better performance but not estimate Hessian matrix of REML. MetidaCu have advantage only for big observation-pes-subject number.

+ Memory estimate: 5.04 GiB, allocs estimate: 46549.

Conclusion

MixedModels.jl faster than Metida.jl in similar cases, but Metida.jl can be used with different covariance structures for random and repeated effects. MetidaNLopt have better performance but not estimate Hessian matrix of REML. MetidaCu have advantage only for big observation-pes-subject number.

diff --git a/dev/bioequivalence/index.html b/dev/bioequivalence/index.html index b28c877..749350b 100644 --- a/dev/bioequivalence/index.html +++ b/dev/bioequivalence/index.html @@ -18,4 +18,4 @@ ) fit!(lmm) ci = confint(lmm)[end] -exp.(ci) .* 100.0
(73.66277770520527, 115.87469810346369)

Reference

+exp.(ci) .* 100.0
(73.66277770520527, 115.87469810346369)

Reference

diff --git a/dev/boot/index.html b/dev/boot/index.html index e7d25a7..935ce65 100644 --- a/dev/boot/index.html +++ b/dev/boot/index.html @@ -4,4 +4,4 @@ ) Metida.fit!(lmm) bt = Metida.bootstrap(lmm; n = 1000, double = true, rng = MersenneTwister(1234)) -confint(bt)

See also: confint, Metida.miboot, Metida.nvar, Metida.tvar, Metida.straps, Metida.sdstraps, Metida.thetastraps

source

Metida.nvar

Metida.nvarFunction
nvar(br::BootstrapResult)

Number of coefficient in the model.

source

Metida.tvar

Metida.tvarFunction
tvar(br::BootstrapResult) = length(br.theta)

Number of theta parameters in the model.

source

Metida.straps

Metida.strapsFunction
straps(br::BootstrapResult, idx::Int)

Return coefficients vector.

source

Metida.sdstraps

Metida.sdstrapsFunction
sdstraps(br::BootstrapResult, idx::Int)

Return sqrt(var(β)) vector.

source

Metida.thetastraps

Metida.thetastrapsFunction
straps(br::BootstrapResult, idx::Int)

Return theta vector.

source
+confint(bt)

See also: confint, Metida.miboot, Metida.nvar, Metida.tvar, Metida.straps, Metida.sdstraps, Metida.thetastraps

source

Metida.nvar

Metida.nvarFunction
nvar(br::BootstrapResult)

Number of coefficient in the model.

source

Metida.tvar

Metida.tvarFunction
tvar(br::BootstrapResult) = length(br.theta)

Number of theta parameters in the model.

source

Metida.straps

Metida.strapsFunction
straps(br::BootstrapResult, idx::Int)

Return coefficients vector.

source

Metida.sdstraps

Metida.sdstrapsFunction
sdstraps(br::BootstrapResult, idx::Int)

Return sqrt(var(β)) vector.

source

Metida.thetastraps

Metida.thetastrapsFunction
straps(br::BootstrapResult, idx::Int)

Return theta vector.

source
diff --git a/dev/cuda/index.html b/dev/cuda/index.html index 849ecab..c0d88c5 100644 --- a/dev/cuda/index.html +++ b/dev/cuda/index.html @@ -5,4 +5,4 @@ lmm = LMM(@formula(var ~ sequence + period + formulation), df; random = VarEffect(@covstr(formulation|subject), CSH), repeated = VarEffect(@covstr(formulation|subject), VC)) -fit!(lmm; solver = :cuda) +fit!(lmm; solver = :cuda) diff --git a/dev/custom/index.html b/dev/custom/index.html index c0cc2dc..f6fe92a 100644 --- a/dev/custom/index.html +++ b/dev/custom/index.html @@ -157,4 +157,4 @@ θ vector: [46.8999, 8.28173] Residual σ² var 2199.6 Residual θ theta 8.28173 - + diff --git a/dev/details/index.html b/dev/details/index.html index b973e2e..9fb2ce5 100644 --- a/dev/details/index.html +++ b/dev/details/index.html @@ -30,4 +30,4 @@ \mathcal{H}^{'}(\theta_{n}) = - \mathcal{H}L_1(\theta_{n}) + \mathcal{H} L_3(\theta) , if score \\ \mathcal{H}^{'}(\theta_{n}) = \mathcal{H} L_3(\theta_{n}) , if ai -\]

Beta (β)

\[\beta = {(\sum_{i=1}^n X_{i}'V_i^{-1}X_{i})}^{-1}(\sum_{i=1}^n X_{i}'V_i^{-1}y_{i})\]

F

\[F = \frac{\beta'L'(LCL')^{-1}L\beta}{rank(LCL')}\]

Variance covariance matrix of β

\[C = (\sum_{i=1}^{n} X_i'V_i^{-1}X_i)^{-1}\]

Sweep

Details see: https://github.com/joshday/SweepOperator.jl

Apply special function to some part of theta vector.

Variance (var) part

Applied only to variance part.

Exponential function (:exp)

Exponential function applied.

\[ f(x) = exp(x)\]

\[ f^{-1}(x) = log(x)\]

Square function (:sq)

\[ f(x) = x^2\]

\[ f^{-1}(x) = sqrt(x)\]

Identity function (:identity)

\[ f(x) = x\]

\[ f^{-1}(x) = x\]

Covariance (rho) part

Applied only to covariance part.

Sigmoid function (:sigm)

\[ f(x) = 1 / (1 + exp(- x * k)) * 2 - 1\]

\[ f^{-1}(x) = -log(1 / (x + 1) * 2 - 1) / k\]

where $k = 0.1$

Arctangent function (:atan)

\[ f(x) = atan(x)/pi*2\]

\[ f^{-1}(x) = tan(x*pi/2)\]

"Square" sigmoid function (:sqsigm)

\[ f(x) = x / \sqrt{1 + (x)^2}\]

\[ f^{-1}(x) = sign(x) * \sqrt{x^2/(1 - x^2)}\]

Positive sigmoid function (:psigm)

\[ f(x) = 1/(1 + exp(-x / 2))\]

\[ f^{-1}(x) = -log(1/x - 1) * 2\]

Additional parameters (theta) part

No function applied.

+\]

Beta (β)

\[\beta = {(\sum_{i=1}^n X_{i}'V_i^{-1}X_{i})}^{-1}(\sum_{i=1}^n X_{i}'V_i^{-1}y_{i})\]

F

\[F = \frac{\beta'L'(LCL')^{-1}L\beta}{rank(LCL')}\]

Variance covariance matrix of β

\[C = (\sum_{i=1}^{n} X_i'V_i^{-1}X_i)^{-1}\]

Sweep

Details see: https://github.com/joshday/SweepOperator.jl

Apply special function to some part of theta vector.

Variance (var) part

Applied only to variance part.

Exponential function (:exp)

Exponential function applied.

\[ f(x) = exp(x)\]

\[ f^{-1}(x) = log(x)\]

Square function (:sq)

\[ f(x) = x^2\]

\[ f^{-1}(x) = sqrt(x)\]

Identity function (:identity)

\[ f(x) = x\]

\[ f^{-1}(x) = x\]

Covariance (rho) part

Applied only to covariance part.

Sigmoid function (:sigm)

\[ f(x) = 1 / (1 + exp(- x * k)) * 2 - 1\]

\[ f^{-1}(x) = -log(1 / (x + 1) * 2 - 1) / k\]

where $k = 0.1$

Arctangent function (:atan)

\[ f(x) = atan(x)/pi*2\]

\[ f^{-1}(x) = tan(x*pi/2)\]

"Square" sigmoid function (:sqsigm)

\[ f(x) = x / \sqrt{1 + (x)^2}\]

\[ f^{-1}(x) = sign(x) * \sqrt{x^2/(1 - x^2)}\]

Positive sigmoid function (:psigm)

\[ f(x) = 1/(1 + exp(-x / 2))\]

\[ f^{-1}(x) = -log(1/x - 1) * 2\]

Additional parameters (theta) part

No function applied.

diff --git a/dev/examples/index.html b/dev/examples/index.html index a3994e7..d637335 100644 --- a/dev/examples/index.html +++ b/dev/examples/index.html @@ -30,9 +30,9 @@ Random 1 ρ rho -0.0427208 Residual σ² var 0.970345

MixedModels result:

fm = @formula(response ~ 1 + factor*time + (1 + time|subject&factor))
-mm = fit(MixedModel, fm, rds, REML=true)

Minimizing 2    Time: 0:00:00 ( 0.16  s/it)
+mm = fit(MixedModel, fm, rds, REML=true)

Minimizing 2    Time: 0:00:00 ( 0.14  s/it)
   objective:  1426.9231858044589
-

Minimizing 66    Time: 0:00:00 ( 5.78 ms/it)
+

Minimizing 66    Time: 0:00:00 ( 5.13 ms/it)
 Linear mixed model fit by REML
  response ~ 1 + factor + time + factor & time + (1 + time | subject & factor)
  REML criterion at convergence: 1300.18075981887
@@ -83,9 +83,9 @@
   Random 2   σ²    var   3.73092
   Residual   σ²    var   0.302415
 

MixedModels:

fm2 = @formula(diameter ~ 1 + (1|plate) + (1|sample))
-mm = fit(MixedModel, fm2, df, REML=true)

Minimizing 2    Time: 0:00:00 ( 0.28  s/it)
+mm = fit(MixedModel, fm2, df, REML=true)

Minimizing 2    Time: 0:00:00 ( 0.26  s/it)
   objective:  366.5302937135882
-

Minimizing 46    Time: 0:00:00 (12.27 ms/it)
+

Minimizing 46    Time: 0:00:00 (11.49 ms/it)
 Linear mixed model fit by REML
  diameter ~ 1 + (1 | plate) + (1 | sample)
  REML criterion at convergence: 330.86058899096145
@@ -232,4 +232,4 @@
 
 emmeans(tm)
 
-effects(Dict(:period => ["1", "2", "3", "4"]), tm)
+effects(Dict(:period => ["1", "2", "3", "4"]), tm) diff --git a/dev/faq/index.html b/dev/faq/index.html index b6a95d9..41be38b 100644 --- a/dev/faq/index.html +++ b/dev/faq/index.html @@ -1,2 +1,2 @@ -F.A.Q. · Metida.jl
  • Q1: Why it working so slow?

Metida.jl work with small and medium datasets. Model fitting is based on variance-covariance matrix inversion at each iteration. That's why if you have big blocks it will work slow. If you have big blocks you can try to use MetidaCu.jl for optimization on CUDA GPU. You can use MetidaNLopt.jl for better performance, but you will not get Hessian matrix at the end of optimization. Also if you don't need to specify repeated-measures (R) covariance part and use SI, DIAG, CS, CSH covariance types for random-effect part (G) you can use MixedModels.jl - it work much faster.

  • Q2: What blocks is?

Blocks depend on subjects. If you have only one random effect block is equivalent to subject. If you have more than one random effect blocks will be made as non-crossing combination for all subject variables.

  • Q3: Why model does not converge?

Optimization of REML function can depend on many factors. In some cases covariance parameters can be correlated (ill-conditioned/singular covariance matrix). So hypersurface in the maximum area can be very flat, that why the result can be different for different starting values (or for different software even REML is near equal). Also, some models can not be fitted for specific data at all. If the model not fitted try to check how meaningful and reasonable is the model or try to guess more robust initial conditions.

  • Q4: Is model fitting is correct?

Use 'lmm.log' to see warnings and errors. If you have warnings and error maybe this model is overspecified. Try to change variance structure or guess more robust initial conditions.

  • Q5: How to choose best variance-covariance structure?

SAS Manual, Mixed Models Analyses Using the SAS System Course Notes:

Unfortunately, our attempt to share a very RECENT perspective by a relatively small number of statistics and statistics related research has somewhat sidetracked the focus of lesson 1. Would like to attempt to provide some clarity to some of the discussion on the discussion forum about the bar chart vs. interval charts. You can use information criteria produced by the MIXED procedure as a tool to help you select the model with the most appropriate covariance structure. The smaller the information criteria value is, the better the model is. Theoretically, the smaller the -2 Res Log Likelihood is, the better the model is. However, you can always make this value smaller by adding parameters to the model. Information criteria attached penalties to the negative -2 Res Log Likelihood value; that is, the more the parameters, the bigger the penalties. Two commonly used information criteria are Akaike's (1974) and Schwartz's (1978). Generally speaking, BIC tends to choose less complex models than AIC. Because choosing a model that is too simple inflates Type I error rate, when Type I error control is the highest priority, you may want to use AIC. On the other hand, if loss of power is more of a concern, BIC might be preferable (Guerin and Stroup 2000). Starting in the Release 8.1, the MIXED procedure produces another information criteria, AICC. AICC is a finite-sample corrected Akaike Information Criterion. For small samples, it reduces the bias produced by AIC; for large samples, AICC converges to AIC. In general, AICC is preferred to AIC. For more information on information criteria, especially AICC, refer to Burnham, K. P. and Anderson, D. R. (1998). The basic idea for repeated measures analysis is that, among plausible within-subject covariance models given a particular study, the model that minimizes AICC or BIC (your choice) is preferable. When AICC or BIC are close, the simpler model is generally preferred.

  • Q6: I have a slightly different results for DF calculation, what's wrong?

Check logs. If final hessian matrix for REML function is ill-conditioned results on differet OS can be slightly different. If possible, try to use more stable covariance structure. Or make an issue on github.

  • Q7: I changed maxthreads settings but nothing happend.

Check the number of execution threads: Threads.nthreads(), maybe you should change julia startup settings. See also julia threads docs.

See also:

  • Barnett, A.G., Koper, N., Dobson, A.J., Schmiegelow, F. and Manseau, M. (2010), Using information criteria to select the correct variance–covariance structure for longitudinal data in ecology. Methods in Ecology and Evolution, 1: 15-24. https://doi.org/10.1111/j.2041-210X.2009.00009.x

  • Guidelines for Selecting the Covariance Structure in Mixed Model Analysis

  • H. J. Keselman,James Algina,Rhonda K. Kowalchuk &Russell D. Wolfinger. A comparison of two approaches for selecting covariance structures in the analysis of repeated measurements. https://doi.org/10.1080/03610919808813497

+F.A.Q. · Metida.jl
  • Q1: Why it working so slow?

Metida.jl work with small and medium datasets. Model fitting is based on variance-covariance matrix inversion at each iteration. That's why if you have big blocks it will work slow. If you have big blocks you can try to use MetidaCu.jl for optimization on CUDA GPU. You can use MetidaNLopt.jl for better performance, but you will not get Hessian matrix at the end of optimization. Also if you don't need to specify repeated-measures (R) covariance part and use SI, DIAG, CS, CSH covariance types for random-effect part (G) you can use MixedModels.jl - it work much faster.

  • Q2: What blocks is?

Blocks depend on subjects. If you have only one random effect block is equivalent to subject. If you have more than one random effect blocks will be made as non-crossing combination for all subject variables.

  • Q3: Why model does not converge?

Optimization of REML function can depend on many factors. In some cases covariance parameters can be correlated (ill-conditioned/singular covariance matrix). So hypersurface in the maximum area can be very flat, that why the result can be different for different starting values (or for different software even REML is near equal). Also, some models can not be fitted for specific data at all. If the model not fitted try to check how meaningful and reasonable is the model or try to guess more robust initial conditions.

  • Q4: Is model fitting is correct?

Use 'lmm.log' to see warnings and errors. If you have warnings and error maybe this model is overspecified. Try to change variance structure or guess more robust initial conditions.

  • Q5: How to choose best variance-covariance structure?

SAS Manual, Mixed Models Analyses Using the SAS System Course Notes:

Unfortunately, our attempt to share a very RECENT perspective by a relatively small number of statistics and statistics related research has somewhat sidetracked the focus of lesson 1. Would like to attempt to provide some clarity to some of the discussion on the discussion forum about the bar chart vs. interval charts. You can use information criteria produced by the MIXED procedure as a tool to help you select the model with the most appropriate covariance structure. The smaller the information criteria value is, the better the model is. Theoretically, the smaller the -2 Res Log Likelihood is, the better the model is. However, you can always make this value smaller by adding parameters to the model. Information criteria attached penalties to the negative -2 Res Log Likelihood value; that is, the more the parameters, the bigger the penalties. Two commonly used information criteria are Akaike's (1974) and Schwartz's (1978). Generally speaking, BIC tends to choose less complex models than AIC. Because choosing a model that is too simple inflates Type I error rate, when Type I error control is the highest priority, you may want to use AIC. On the other hand, if loss of power is more of a concern, BIC might be preferable (Guerin and Stroup 2000). Starting in the Release 8.1, the MIXED procedure produces another information criteria, AICC. AICC is a finite-sample corrected Akaike Information Criterion. For small samples, it reduces the bias produced by AIC; for large samples, AICC converges to AIC. In general, AICC is preferred to AIC. For more information on information criteria, especially AICC, refer to Burnham, K. P. and Anderson, D. R. (1998). The basic idea for repeated measures analysis is that, among plausible within-subject covariance models given a particular study, the model that minimizes AICC or BIC (your choice) is preferable. When AICC or BIC are close, the simpler model is generally preferred.

  • Q6: I have a slightly different results for DF calculation, what's wrong?

Check logs. If final hessian matrix for REML function is ill-conditioned results on differet OS can be slightly different. If possible, try to use more stable covariance structure. Or make an issue on github.

  • Q7: I changed maxthreads settings but nothing happend.

Check the number of execution threads: Threads.nthreads(), maybe you should change julia startup settings. See also julia threads docs.

See also:

  • Barnett, A.G., Koper, N., Dobson, A.J., Schmiegelow, F. and Manseau, M. (2010), Using information criteria to select the correct variance–covariance structure for longitudinal data in ecology. Methods in Ecology and Evolution, 1: 15-24. https://doi.org/10.1111/j.2041-210X.2009.00009.x

  • Guidelines for Selecting the Covariance Structure in Mixed Model Analysis

  • H. J. Keselman,James Algina,Rhonda K. Kowalchuk &Russell D. Wolfinger. A comparison of two approaches for selecting covariance structures in the analysis of repeated measurements. https://doi.org/10.1080/03610919808813497

diff --git a/dev/index.html b/dev/index.html index 019221b..9241e28 100644 --- a/dev/index.html +++ b/dev/index.html @@ -1,2 +1,2 @@ -Home · Metida.jl

Metida

Mixed Models

Multilevel models (also known as hierarchical linear models, linear mixed-effect model, mixed models, nested data models, random coefficient, random-effects models, random parameter models, or split-plot designs) are statistical models of parameters that vary at more than one level. An example could be a model of student performance that contains measures for individual students as well as measures for classrooms within which the students are grouped. These models can be seen as generalizations of linear models (in particular, linear regression), although they can also extend to non-linear models. These models became much more popular after sufficient computing power and software became available. (Wiki)

Metida.jl is a Julia package for fitting mixed-effects models with flexible covariance structure.

Implemented covariance structures:

  • Scaled Identity (SI)
  • Diagonal (DIAG)
  • Autoregressive (AR)
  • Heterogeneous Autoregressive (ARH)
  • Compound Symmetry (CS)
  • Heterogeneous Compound Symmetry (CSH)
  • Autoregressive Moving Average (ARMA)
  • Toeplitz (TOEP)
  • Toeplitz Parameterized (TOEPP)
  • Heterogeneous Toeplitz (TOEPH)
  • Heterogeneous Toeplitz Parameterized (TOEPHP)
  • Spatial Exponential (SPEXP)
  • Spatial Power (SPPOW)
  • Spatial Gaussian (SPGAU)
  • Unstructured (UN)
  • Custom Covariance Type

Limitations

  • Maximum length of block more than ~400 (observation-per-subject).
  • Observation number more than 160 000.
  • For MetidaCu number of blocks more than 40 (maximum length of block more than 4000).

Actually Metida can fit datasets with wore than 160k observation and 40k subjects levels on PC with 64 GB RAM. This is not "hard-coded" limitation, but depends on your model and data structure. Fitting of big datasets can take a lot of time. Optimal dataset size is less than 100k observations with maximum length of block less than 400.

Warning

Julia v1.8 or higher required.

Contents

See also:

Reference

  • Gelman, A.; Hill, J. (2007). Data Analysis Using Regression and Multilevel/Hierarchical Models. New York: Cambridge University Press. pp. 235–299. ISBN 978-0-521-68689-1.
+Home · Metida.jl

Metida

Mixed Models

Multilevel models (also known as hierarchical linear models, linear mixed-effect model, mixed models, nested data models, random coefficient, random-effects models, random parameter models, or split-plot designs) are statistical models of parameters that vary at more than one level. An example could be a model of student performance that contains measures for individual students as well as measures for classrooms within which the students are grouped. These models can be seen as generalizations of linear models (in particular, linear regression), although they can also extend to non-linear models. These models became much more popular after sufficient computing power and software became available. (Wiki)

Metida.jl is a Julia package for fitting mixed-effects models with flexible covariance structure.

Implemented covariance structures:

  • Scaled Identity (SI)
  • Diagonal (DIAG)
  • Autoregressive (AR)
  • Heterogeneous Autoregressive (ARH)
  • Compound Symmetry (CS)
  • Heterogeneous Compound Symmetry (CSH)
  • Autoregressive Moving Average (ARMA)
  • Toeplitz (TOEP)
  • Toeplitz Parameterized (TOEPP)
  • Heterogeneous Toeplitz (TOEPH)
  • Heterogeneous Toeplitz Parameterized (TOEPHP)
  • Spatial Exponential (SPEXP)
  • Spatial Power (SPPOW)
  • Spatial Gaussian (SPGAU)
  • Unstructured (UN)
  • Custom Covariance Type

Limitations

  • Maximum length of block more than ~400 (observation-per-subject).
  • Observation number more than 160 000.
  • For MetidaCu number of blocks more than 40 (maximum length of block more than 4000).

Actually Metida can fit datasets with wore than 160k observation and 40k subjects levels on PC with 64 GB RAM. This is not "hard-coded" limitation, but depends on your model and data structure. Fitting of big datasets can take a lot of time. Optimal dataset size is less than 100k observations with maximum length of block less than 400.

Warning

Julia v1.8 or higher required.

Contents

See also:

Reference

  • Gelman, A.; Hill, J. (2007). Data Analysis Using Regression and Multilevel/Hierarchical Models. New York: Cambridge University Press. pp. 235–299. ISBN 978-0-521-68689-1.
diff --git a/dev/instanduse/index.html b/dev/instanduse/index.html index efbe34c..878a8b3 100644 --- a/dev/instanduse/index.html +++ b/dev/instanduse/index.html @@ -67,4 +67,4 @@ period 1.0789 3.0 8.66853 0.407683 formulation 0.767409 1.0 5.46311 0.417867 ------------- ---------- ----- --------- ----------- -

Model construction

To construct model you can use LMM constructor.

+

Model construction

To construct model you can use LMM constructor.

diff --git a/dev/mi/index.html b/dev/mi/index.html index 536f612..79fb145 100644 --- a/dev/mi/index.html +++ b/dev/mi/index.html @@ -6,9 +6,9 @@ ) Metida.fit!(lmm) mi = Metida.MILMM(lmm, df0m) -bm = Metida.milmm(mi; n = 100, rng = MersenneTwister(1234))source
milmm(lmm::LMM, data; n = 100, verbose = true, rng = default_rng())

Multiple imputation in one step. data for lmm and for milmm should be the same, if different data used resulst can be unpredictable.

source

Metida.miboot

Metida.mibootFunction
miboot(mi::MILMM{T}; n = 100, double = true, bootn = 100, verbose = true, rng = default_rng())

Multiple imputation with parametric bootstrap step.

Warning

Experimental: API not stable

Example:

lmm = Metida.LMM(@formula(var~sequence+period+formulation), df0m;
+bm = Metida.milmm(mi; n = 100, rng = MersenneTwister(1234))
source
milmm(lmm::LMM, data; n = 100, verbose = true, rng = default_rng())

Multiple imputation in one step. data for lmm and for milmm should be the same, if different data used resulst can be unpredictable.

source

Metida.miboot

Metida.mibootFunction
miboot(mi::MILMM{T}; n = 100, double = true, bootn = 100, verbose = true, rng = default_rng())

Multiple imputation with parametric bootstrap step.

Warning

Experimental: API not stable

Example:

lmm = Metida.LMM(@formula(var~sequence+period+formulation), df0m;
 random = Metida.VarEffect(Metida.@covstr(formulation|subject), Metida.CSH),
 )
 Metida.fit!(lmm)
 mi = Metida.MILMM(lmm, df0m)
-bm = Metida.miboot(mi; n = 100, rng = MersenneTwister(1234))
source
+bm = Metida.miboot(mi; n = 100, rng = MersenneTwister(1234))source diff --git a/dev/nlopt/index.html b/dev/nlopt/index.html index da8d5f8..20a502e 100644 --- a/dev/nlopt/index.html +++ b/dev/nlopt/index.html @@ -5,4 +5,4 @@ lmm = LMM(@formula(var ~ sequence + period + formulation), df; random = VarEffect(@covstr(formulation|subject), CSH), repeated = VarEffect(@covstr(formulation|subject), VC)) -fit!(lmm; solver = :nlopt)

NLopt is a free/open-source library for nonlinear optimization, providing a common interface for a number of different free optimization routines available online as well as original implementations of various other algorithms.

Optimization with NLopt.jl using gradient-free algirithms is less stable, that why two-step optimization schema used. Results can be slightly different for differens OS and Julia versions. Always look into logs.

+fit!(lmm; solver = :nlopt)

NLopt is a free/open-source library for nonlinear optimization, providing a common interface for a number of different free optimization routines available online as well as original implementations of various other algorithms.

Optimization with NLopt.jl using gradient-free algirithms is less stable, that why two-step optimization schema used. Results can be slightly different for differens OS and Julia versions. Always look into logs.

diff --git a/dev/objects.inv b/dev/objects.inv index 6d261a5..3de38f8 100644 Binary files a/dev/objects.inv and b/dev/objects.inv differ diff --git a/dev/ref/index.html b/dev/ref/index.html index 9d7cf1d..b26d4c5 100644 --- a/dev/ref/index.html +++ b/dev/ref/index.html @@ -1,2 +1,2 @@ -Citation & Reference · Metida.jl

Citation & Reference

Sweep algorithm

  • Sweep based on SweepOperator.jl. Thanks to @joshday and @Hua-Zhou.

  • http://hua-zhou.github.io/teaching/biostatm280-2019spring/slides/12-sweep/sweep.html

More:

  • Section 7.4-7.6 of Numerical Analysis for Statisticians by Kenneth Lange (2010).

  • The paper A tutorial on the SWEEP operator by James H. Goodnight (1979).

REML & Parameter estimation

  • Henderson, C. R., et al. “The Estimation of Environmental and Genetic Trends from Records Subject to Culling.” Biometrics, vol. 15, no. 2, 1959, pp. 192–218. JSTOR, www.jstor.org/stable/2527669.

  • Laird, Nan M., and James H. Ware. “Random-Effects Models for Longitudinal Data.” Biometrics, vol. 38, no. 4, 1982, pp. 963–974. JSTOR, www.jstor.org/stable/2529876.

  • Lindstrom & J.; Bates, M. (1988). Newton—Raphson and EM Algorithms for Linear Mixed-Effects Models for Repeated-Measures Data. Journal of the American Statistical Association. 83. 1014. 10.1080/01621459.1988.10478693.

  • Gurka, Matthew. (2006). Selecting the Best Linear Mixed Model under REML. The American Statistician. 60. 19-26. 10.1198/000313006X90396.

  • Sang Hong Lee, Julius H.J. van der Werf. An efficient variance component approach implementing an average information REML suitable for combined LD and linkage mapping with a general complex pedigree. Genetics Selection Evolution, BioMed Central, 2006, 38 (1), pp.25-43. ⟨hal-00894558⟩

  • F.N. Gumedze, T.T. Dunne, Parameter estimation and inference in the linear mixed model, Linear Algebra and its Applications, Volume 435, Issue 8, 2011, Pages 1920-1944, ISSN 0024-3795, https://doi.org/10.1016/j.laa.2011.04.015. (http://www.sciencedirect.com/science/article/pii/S002437951100320X)

AI algorithm

  • D.L. Johnson, R. Thompson, Restricted Maximum Likelihood Estimation of Variance Components for Univariate Animal Models Using Sparse Matrix Techniques and Average Information, Journal of Dairy Science, Volume 78, Issue 2, 1995, Pages 449-456, ISSN 0022-0302, https://doi.org/10.3168/jds.S0022-0302(95)76654-1. (http://www.sciencedirect.com/science/article/pii/S0022030295766541)

  • Mishchenko, Kateryna & Holmgren, Sverker & Rönnegård, Lars. (2007). Newton-type Methods for REML Estimation in Genetic Analysis of Quantitative Traits. Journal of Computational Methods in Science and Engineering. 8. 10.3233/JCM-2008-81-203.

  • Matilainen K, Mäntysaari EA, Lidauer MH, Strandén I, Thompson R. Employing a Monte Carlo algorithm in Newton-type methods for restricted maximum likelihood estimation of genetic parameters. PLoS One. 2013;8(12):e80821. Published 2013 Dec 10. doi:10.1371/journal.pone.0080821

Covariance structures

  • Wolfinger, Russ. (1993). Covariance structure selection in general mixed models. Communications in Statistics-simulation and Computation - COMMUN STATIST-SIMULAT COMPUT. 22. 1079-1106. 10.1080/03610919308813143.

  • Wolfinger, Russ. (1996). Heterogeneous Variance: Covariance Structures for Repeated Measures. Journal of Agricultural, Biological, and Environmental Statistics. 1. 205. 10.2307/1400366.

  • Littell, Ramon & Pendergast, Jane & Natarajan, Ranjini. (2000). Modelling covariance structure in the analysis of repeated measures data. Statistics in Medicine. 19. 1793-1819. 10.1002/1097-0258(20000715)19:13%3C1793::AID-SIM482%3E3.0.CO;2-Q.

  • QUINTAL, SILVANA SILVA RED, VIANA, ALEXANDRE PIO, CAMPOS, BIANCA MACHADO, VIVAS, MARCELO, & AMARAL JÚNIOR, ANTONIO TEIXEIRA DO. (2017). ANALYSIS OF STRUCTURES OF COVARIANCE AND REPEATABILITY IN GUAVA SEGREGANTING POPULATION. Revista Caatinga, 30(4), 885-891. https://doi.org/10.1590/1983-21252017v30n408rc

  • McNeish, D., Harring, J. Covariance pattern mixture models: Eliminating random effects to improve convergence and performance. Behav Res 52, 947–979 (2020). https://doi.org/10.3758/s13428-019-01292-4

And more

  • Giesbrecht, F. G., and Burns, J. C. (1985), "Two-Stage Analysis Based on a Mixed Model: Large-sample Asymptotic Theory and Small-Sample Simulation Results," Biometrics, 41, 853-862.

  • Jennrich, R., & Schluchter, M. (1986). Unbalanced Repeated-Measures Models with Structured Covariance Matrices. Biometrics, 42(4), 805-820. doi:10.2307/2530695

  • Fletcher, Roger (1987), Practical methods of optimization (2nd ed.), New York: John Wiley & Sons, ISBN 978-0-471-91547-8

  • Wolfinger et al., (1994) Computing gaussian likelihoods and their derivatives for general linear mixed models doi: 10.1137/0915079

  • Hrong-Tai Fai & Cornelius (1996) Approximate F-tests of multiple degree of freedom hypotheses in generalized least squares analyses of unbalanced split-plot experiments, Journal of Statistical Computation and Simulation, 54:4, 363-378, DOI: 10.1080/00949659608811740

  • Schaalje GB, McBride JB, Fellingham GW. Adequacy of approximations to distributions of test statistics in complex mixed linear models. J Agric Biol Environ Stat. 2002;7:512–24.

  • Wright, Stephen, and Jorge Nocedal (2006) "Numerical optimization." Springer

  • Van Peer, A. (2010), Variability and Impact on Design of Bioequivalence Studies. Basic & Clinical Pharmacology & Toxicology, 106: 146-153. doi:10.1111/j.1742-7843.2009.00485.x

Julia packages

  • Revels, Jarrett & Lubin, Miles & Papamarkou, Theodore. (2016). Forward-Mode Automatic Differentiation in Julia.

  • Mogensen et al., (2018). Optim: A mathematical optimization package for Julia. Journal of Open Source Software, 3(24), 615,doi: 10.21105/joss.00615

CuSolver & CuBLAS

  • https://docs.nvidia.com/cuda/cusolver/index.html

  • https://docs.nvidia.com/cuda/cublas/index.htm

Reference dataset

  • Bioequivalence reference datasets: Schütz, H., Labes, D., Tomashevskiy, M. et al. Reference Datasets for Studies in a Replicate Design Intended for Average Bioequivalence with Expanding Limits. AAPS J 22, 44 (2020). https://doi.org/10.1208/s12248-020-0427-6

  • sleepstudy.csv: Gregory Belenky, Nancy J. Wesensten, David R. Thorne, Maria L. Thomas, Helen C. Sing, Daniel P. Redmond, Michael B. Russo and Thomas J. Balkin (2003) Patterns of performance degradation and restoration during sleep restriction and subsequent recovery: a sleep dose-response study. Journal of Sleep Research 12, 1–12.

  • Penicillin.csv: O.L. Davies and P.L. Goldsmith (eds), Statistical Methods in Research and Production, 4th ed., Oliver and Boyd, (1972), section 6.6

  • Pastes.csv: O.L. Davies and P.L. Goldsmith (eds), Statistical Methods in Research and Production, 4th ed., Oliver and Boyd, (1972), section 6.5

  • ChickWeight.csv:

    • Crowder, M. and Hand, D. (1990), Analysis of Repeated Measures, Chapman and Hall (example 5.3)
    • Hand, D. and Crowder, M. (1996), Practical Longitudinal Data Analysis, Chapman and Hall (table A.2)
    • Pinheiro, J. C. and Bates, D. M. (2000) Mixed-effects Models in S and S-PLUS, Springer.
  • RepeatedPulse.csv: Data supplied by a student at Oberlin College.

See also: https://vincentarelbundock.github.io/Rdatasets/datasets.html

+Citation & Reference · Metida.jl

Citation & Reference

Sweep algorithm

  • Sweep based on SweepOperator.jl. Thanks to @joshday and @Hua-Zhou.

  • http://hua-zhou.github.io/teaching/biostatm280-2019spring/slides/12-sweep/sweep.html

More:

  • Section 7.4-7.6 of Numerical Analysis for Statisticians by Kenneth Lange (2010).

  • The paper A tutorial on the SWEEP operator by James H. Goodnight (1979).

REML & Parameter estimation

  • Henderson, C. R., et al. “The Estimation of Environmental and Genetic Trends from Records Subject to Culling.” Biometrics, vol. 15, no. 2, 1959, pp. 192–218. JSTOR, www.jstor.org/stable/2527669.

  • Laird, Nan M., and James H. Ware. “Random-Effects Models for Longitudinal Data.” Biometrics, vol. 38, no. 4, 1982, pp. 963–974. JSTOR, www.jstor.org/stable/2529876.

  • Lindstrom & J.; Bates, M. (1988). Newton—Raphson and EM Algorithms for Linear Mixed-Effects Models for Repeated-Measures Data. Journal of the American Statistical Association. 83. 1014. 10.1080/01621459.1988.10478693.

  • Gurka, Matthew. (2006). Selecting the Best Linear Mixed Model under REML. The American Statistician. 60. 19-26. 10.1198/000313006X90396.

  • Sang Hong Lee, Julius H.J. van der Werf. An efficient variance component approach implementing an average information REML suitable for combined LD and linkage mapping with a general complex pedigree. Genetics Selection Evolution, BioMed Central, 2006, 38 (1), pp.25-43. ⟨hal-00894558⟩

  • F.N. Gumedze, T.T. Dunne, Parameter estimation and inference in the linear mixed model, Linear Algebra and its Applications, Volume 435, Issue 8, 2011, Pages 1920-1944, ISSN 0024-3795, https://doi.org/10.1016/j.laa.2011.04.015. (http://www.sciencedirect.com/science/article/pii/S002437951100320X)

AI algorithm

  • D.L. Johnson, R. Thompson, Restricted Maximum Likelihood Estimation of Variance Components for Univariate Animal Models Using Sparse Matrix Techniques and Average Information, Journal of Dairy Science, Volume 78, Issue 2, 1995, Pages 449-456, ISSN 0022-0302, https://doi.org/10.3168/jds.S0022-0302(95)76654-1. (http://www.sciencedirect.com/science/article/pii/S0022030295766541)

  • Mishchenko, Kateryna & Holmgren, Sverker & Rönnegård, Lars. (2007). Newton-type Methods for REML Estimation in Genetic Analysis of Quantitative Traits. Journal of Computational Methods in Science and Engineering. 8. 10.3233/JCM-2008-81-203.

  • Matilainen K, Mäntysaari EA, Lidauer MH, Strandén I, Thompson R. Employing a Monte Carlo algorithm in Newton-type methods for restricted maximum likelihood estimation of genetic parameters. PLoS One. 2013;8(12):e80821. Published 2013 Dec 10. doi:10.1371/journal.pone.0080821

Covariance structures

  • Wolfinger, Russ. (1993). Covariance structure selection in general mixed models. Communications in Statistics-simulation and Computation - COMMUN STATIST-SIMULAT COMPUT. 22. 1079-1106. 10.1080/03610919308813143.

  • Wolfinger, Russ. (1996). Heterogeneous Variance: Covariance Structures for Repeated Measures. Journal of Agricultural, Biological, and Environmental Statistics. 1. 205. 10.2307/1400366.

  • Littell, Ramon & Pendergast, Jane & Natarajan, Ranjini. (2000). Modelling covariance structure in the analysis of repeated measures data. Statistics in Medicine. 19. 1793-1819. 10.1002/1097-0258(20000715)19:13%3C1793::AID-SIM482%3E3.0.CO;2-Q.

  • QUINTAL, SILVANA SILVA RED, VIANA, ALEXANDRE PIO, CAMPOS, BIANCA MACHADO, VIVAS, MARCELO, & AMARAL JÚNIOR, ANTONIO TEIXEIRA DO. (2017). ANALYSIS OF STRUCTURES OF COVARIANCE AND REPEATABILITY IN GUAVA SEGREGANTING POPULATION. Revista Caatinga, 30(4), 885-891. https://doi.org/10.1590/1983-21252017v30n408rc

  • McNeish, D., Harring, J. Covariance pattern mixture models: Eliminating random effects to improve convergence and performance. Behav Res 52, 947–979 (2020). https://doi.org/10.3758/s13428-019-01292-4

And more

  • Giesbrecht, F. G., and Burns, J. C. (1985), "Two-Stage Analysis Based on a Mixed Model: Large-sample Asymptotic Theory and Small-Sample Simulation Results," Biometrics, 41, 853-862.

  • Jennrich, R., & Schluchter, M. (1986). Unbalanced Repeated-Measures Models with Structured Covariance Matrices. Biometrics, 42(4), 805-820. doi:10.2307/2530695

  • Fletcher, Roger (1987), Practical methods of optimization (2nd ed.), New York: John Wiley & Sons, ISBN 978-0-471-91547-8

  • Wolfinger et al., (1994) Computing gaussian likelihoods and their derivatives for general linear mixed models doi: 10.1137/0915079

  • Hrong-Tai Fai & Cornelius (1996) Approximate F-tests of multiple degree of freedom hypotheses in generalized least squares analyses of unbalanced split-plot experiments, Journal of Statistical Computation and Simulation, 54:4, 363-378, DOI: 10.1080/00949659608811740

  • Schaalje GB, McBride JB, Fellingham GW. Adequacy of approximations to distributions of test statistics in complex mixed linear models. J Agric Biol Environ Stat. 2002;7:512–24.

  • Wright, Stephen, and Jorge Nocedal (2006) "Numerical optimization." Springer

  • Van Peer, A. (2010), Variability and Impact on Design of Bioequivalence Studies. Basic & Clinical Pharmacology & Toxicology, 106: 146-153. doi:10.1111/j.1742-7843.2009.00485.x

Julia packages

  • Revels, Jarrett & Lubin, Miles & Papamarkou, Theodore. (2016). Forward-Mode Automatic Differentiation in Julia.

  • Mogensen et al., (2018). Optim: A mathematical optimization package for Julia. Journal of Open Source Software, 3(24), 615,doi: 10.21105/joss.00615

CuSolver & CuBLAS

  • https://docs.nvidia.com/cuda/cusolver/index.html

  • https://docs.nvidia.com/cuda/cublas/index.htm

Reference dataset

  • Bioequivalence reference datasets: Schütz, H., Labes, D., Tomashevskiy, M. et al. Reference Datasets for Studies in a Replicate Design Intended for Average Bioequivalence with Expanding Limits. AAPS J 22, 44 (2020). https://doi.org/10.1208/s12248-020-0427-6

  • sleepstudy.csv: Gregory Belenky, Nancy J. Wesensten, David R. Thorne, Maria L. Thomas, Helen C. Sing, Daniel P. Redmond, Michael B. Russo and Thomas J. Balkin (2003) Patterns of performance degradation and restoration during sleep restriction and subsequent recovery: a sleep dose-response study. Journal of Sleep Research 12, 1–12.

  • Penicillin.csv: O.L. Davies and P.L. Goldsmith (eds), Statistical Methods in Research and Production, 4th ed., Oliver and Boyd, (1972), section 6.6

  • Pastes.csv: O.L. Davies and P.L. Goldsmith (eds), Statistical Methods in Research and Production, 4th ed., Oliver and Boyd, (1972), section 6.5

  • ChickWeight.csv:

    • Crowder, M. and Hand, D. (1990), Analysis of Repeated Measures, Chapman and Hall (example 5.3)
    • Hand, D. and Crowder, M. (1996), Practical Longitudinal Data Analysis, Chapman and Hall (table A.2)
    • Pinheiro, J. C. and Bates, D. M. (2000) Mixed-effects Models in S and S-PLUS, Springer.
  • RepeatedPulse.csv: Data supplied by a student at Oberlin College.

See also: https://vincentarelbundock.github.io/Rdatasets/datasets.html

diff --git a/dev/search_index.js b/dev/search_index.js index 99a2b3f..de79ec8 100644 --- a/dev/search_index.js +++ b/dev/search_index.js @@ -1,3 +1,3 @@ var documenterSearchIndex = {"docs": -[{"location":"nlopt/#NLopt","page":"NLopt","title":"NLopt","text":"","category":"section"},{"location":"nlopt/","page":"NLopt","title":"NLopt","text":"Optimization with NLopt.jl.","category":"page"},{"location":"nlopt/","page":"NLopt","title":"NLopt","text":"Install:","category":"page"},{"location":"nlopt/","page":"NLopt","title":"NLopt","text":"using Pkg\nPkg.add(\"MetidaNLopt\")","category":"page"},{"location":"nlopt/","page":"NLopt","title":"NLopt","text":"Using:","category":"page"},{"location":"nlopt/","page":"NLopt","title":"NLopt","text":"using Metida, MetidaNLopt, StatsBase, StatsModels, CSV, DataFrames\ndf = CSV.File(dirname(pathof(Metida))*\"\\\\..\\\\test\\\\csv\\\\df0.csv\") |> DataFrame\nlmm = LMM(@formula(var ~ sequence + period + formulation), df;\nrandom = VarEffect(@covstr(formulation|subject), CSH),\nrepeated = VarEffect(@covstr(formulation|subject), VC))\nfit!(lmm; solver = :nlopt)","category":"page"},{"location":"nlopt/","page":"NLopt","title":"NLopt","text":"NLopt is a free/open-source library for nonlinear optimization, providing a common interface for a number of different free optimization routines available online as well as original implementations of various other algorithms.","category":"page"},{"location":"nlopt/","page":"NLopt","title":"NLopt","text":"Optimization with NLopt.jl using gradient-free algirithms is less stable, that why two-step optimization schema used. Results can be slightly different for differens OS and Julia versions. Always look into logs. ","category":"page"},{"location":"cuda/#CUDA","page":"CUDA","title":"CUDA","text":"","category":"section"},{"location":"cuda/","page":"CUDA","title":"CUDA","text":"Use CuBLAS & CuSOLVER for REML calculation. Optimization with NLopt.jl.","category":"page"},{"location":"cuda/","page":"CUDA","title":"CUDA","text":"Install:","category":"page"},{"location":"cuda/","page":"CUDA","title":"CUDA","text":"using Pkg\nPkg.add(\"MetidaCu\")","category":"page"},{"location":"cuda/","page":"CUDA","title":"CUDA","text":"Using:","category":"page"},{"location":"cuda/","page":"CUDA","title":"CUDA","text":"using Metida, MetidaCu, StatsBase, StatsModels, CSV, DataFrames\ndf = CSV.File(dirname(pathof(Metida))*\"\\\\..\\\\test\\\\csv\\\\df0.csv\") |> DataFrame\nlmm = LMM(@formula(var ~ sequence + period + formulation), df;\nrandom = VarEffect(@covstr(formulation|subject), CSH),\nrepeated = VarEffect(@covstr(formulation|subject), VC))\nfit!(lmm; solver = :cuda)","category":"page"},{"location":"bioequivalence/#Type-B","page":"Bioequivalence","title":"Type B","text":"","category":"section"},{"location":"bioequivalence/","page":"Bioequivalence","title":"Bioequivalence","text":"using Metida, CSV, DataFrames, CategoricalArrays\n# example data\ndf = CSV.File(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"csv\", \"df0.csv\")) |> DataFrame;\ntransform!(df, :subject => categorical, renamecols=false)\ntransform!(df, :period => categorical, renamecols=false)\ntransform!(df, :sequence => categorical, renamecols=false)\ntransform!(df, :formulation => categorical, renamecols=false)\n\nlmm = LMM(@formula(var~sequence+period+formulation), df;\nrandom = VarEffect(@covstr(1|subject), SI),\n)\nfit!(lmm)\nci = confint(lmm)[end]\nexp.(ci) .* 100.0","category":"page"},{"location":"bioequivalence/#Type-C","page":"Bioequivalence","title":"Type C","text":"","category":"section"},{"location":"bioequivalence/","page":"Bioequivalence","title":"Bioequivalence","text":"lmm =LMM(@formula(var~sequence+period+formulation), df;\nrandom = VarEffect(@covstr(formulation|subject), CSH),\nrepeated = VarEffect(@covstr(formulation|subject), DIAG),\n)\nfit!(lmm)\nci = confint(lmm)[end]\nexp.(ci) .* 100.0","category":"page"},{"location":"bioequivalence/#Reference","page":"Bioequivalence","title":"Reference","text":"","category":"section"},{"location":"bioequivalence/","page":"Bioequivalence","title":"Bioequivalence","text":"Annex I for EMA’s Guideline on the Investigation of Bioequivalence\nFDA Guidance for Industry: Statistical Approaches to Establishing Bioequivalence, APPENDIX F","category":"page"},{"location":"boot/#Parametric-bootstrap","page":"Bootstrap","title":"Parametric bootstrap","text":"","category":"section"},{"location":"boot/#Metida.bootstrap","page":"Bootstrap","title":"Metida.bootstrap","text":"","category":"section"},{"location":"boot/","page":"Bootstrap","title":"Bootstrap","text":"Metida.bootstrap","category":"page"},{"location":"boot/#Metida.bootstrap","page":"Bootstrap","title":"Metida.bootstrap","text":"bootstrap(lmm::LMM; double = false, n = 100, verbose = true, init = lmm.result.theta, rng = default_rng())\n\nParametric bootstrap.\n\nwarning: Warning\nExperimental: API not stable\n\ndouble - use double approach (default - false);\nn - number of bootstrap samples;\nverbose - show progress bar;\ninit - initial values for lmm;\nrng - random number generator.\n\nParametric bootstrap based on generating random responce vector from known distribution, that given from fitted LMM model.\n\nSimple bootstrap:\n\nFor one-stage bootstrap variance parameters and coefficients simulated in one step. \n\nDouble bootstrap:\n\nFor double bootstrap (two-tage) variance parameters simulated in first cycle, than they used for simulating coefficients and var(β) on stage two. On second stage parent-model β used for simulations. \n\nlmm = Metida.LMM(@formula(var~sequence+period+formulation), df0m;\nrandom = Metida.VarEffect(Metida.@covstr(formulation|subject), Metida.CSH),\n)\nMetida.fit!(lmm)\nbt = Metida.bootstrap(lmm; n = 1000, double = true, rng = MersenneTwister(1234))\nconfint(bt)\n\nSee also: confint, Metida.miboot, Metida.nvar, Metida.tvar, Metida.straps, Metida.sdstraps, Metida.thetastraps\n\n\n\n\n\n","category":"function"},{"location":"boot/#Metida.nvar","page":"Bootstrap","title":"Metida.nvar","text":"","category":"section"},{"location":"boot/","page":"Bootstrap","title":"Bootstrap","text":"Metida.nvar","category":"page"},{"location":"boot/#Metida.nvar","page":"Bootstrap","title":"Metida.nvar","text":"nvar(br::BootstrapResult)\n\nNumber of coefficient in the model.\n\n\n\n\n\n","category":"function"},{"location":"boot/#Metida.tvar","page":"Bootstrap","title":"Metida.tvar","text":"","category":"section"},{"location":"boot/","page":"Bootstrap","title":"Bootstrap","text":"Metida.tvar","category":"page"},{"location":"boot/#Metida.tvar","page":"Bootstrap","title":"Metida.tvar","text":"tvar(br::BootstrapResult) = length(br.theta)\n\nNumber of theta parameters in the model.\n\n\n\n\n\n","category":"function"},{"location":"boot/#Metida.straps","page":"Bootstrap","title":"Metida.straps","text":"","category":"section"},{"location":"boot/","page":"Bootstrap","title":"Bootstrap","text":"Metida.straps","category":"page"},{"location":"boot/#Metida.straps","page":"Bootstrap","title":"Metida.straps","text":"straps(br::BootstrapResult, idx::Int)\n\nReturn coefficients vector.\n\n\n\n\n\n","category":"function"},{"location":"boot/#Metida.sdstraps","page":"Bootstrap","title":"Metida.sdstraps","text":"","category":"section"},{"location":"boot/","page":"Bootstrap","title":"Bootstrap","text":"Metida.sdstraps","category":"page"},{"location":"boot/#Metida.sdstraps","page":"Bootstrap","title":"Metida.sdstraps","text":"sdstraps(br::BootstrapResult, idx::Int)\n\nReturn sqrt(var(β)) vector.\n\n\n\n\n\n","category":"function"},{"location":"boot/#Metida.thetastraps","page":"Bootstrap","title":"Metida.thetastraps","text":"","category":"section"},{"location":"boot/","page":"Bootstrap","title":"Bootstrap","text":"Metida.thetastraps","category":"page"},{"location":"boot/#Metida.thetastraps","page":"Bootstrap","title":"Metida.thetastraps","text":"straps(br::BootstrapResult, idx::Int)\n\nReturn theta vector.\n\n\n\n\n\n","category":"function"},{"location":"details/#Details","page":"Details","title":"Details","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"The solution to the mixed model equations is a maximum likelihood estimate when the distribution of the errors is normal. Maximum likelihood estimates are based on the probability model for the observed responses. In the probability model the distribution of the responses is expressed as a function of one or more parameters. PROC MIXED in SAS used restricted maximum likelihood (REML) approach by default. REML equation can be described with following (Henderson, 1959;Laird et.al. 1982; Jennrich 1986; Lindstrom & Bates, 1988; Gurka et.al 2006).","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"Metida.jl using optimization with Optim.jl package (Newton's Method) by default. Because variance have only positive values and ρ is limited as -1 ≤ ρ ≤ 1 in Metida.jl \"link\" function is used. Exponential values is optimizing in variance part and ρ is linked with sigmoid function. All steps perform with differentiable functions with forward automatic differentiation using ForwardDiff.jl package. Also MetidaNLopt.jl and MetidaCu.jl available for optimization with NLopt.jl and solving on CUDA GPU. Sweep algorithm using for variance-covariance matrix inversing in REML calculation.","category":"page"},{"location":"details/#Model","page":"Details","title":"Model","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"In matrix notation a mixed effect model can be represented as:","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"y = Xbeta + Zu + epsilon","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"where:","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"epsilon sim N(0 R)\n\n\n\nu sim N(0 G)\n\n\n\ny sim N(Xbeta V)\n","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"where V depends on covariance sructure and parameters theta:","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"V = CovStruct(theta)\n","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"The unknown parameters include the regression parameters in beta and covariance parameters in theta.","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"Estimation of these model parameters relies on the use of a Newton-Ralphson (by default) algorithm. When we use either algorithm for finding REML solutions, we need to compute V^-1 and its derivatives with respect to theta, which are computationally difficult for large n, therefor SWEEP (see https://github.com/joshday/SweepOperator.jl) algorithm used to meke oprtimization less computationaly expensive.","category":"page"},{"location":"details/#V","page":"Details","title":"V","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"V_i = Z_iGZ_i+R_i","category":"page"},{"location":"details/#Henderson's-«mixed-model-equations»","page":"Details","title":"Henderson's «mixed model equations»","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"beginpmatrixXR^-1XXR^-1ZZR^-1XZR^-1Z+G_-1endpmatrix beginpmatrixwidehatbeta widehatu endpmatrix= beginpmatrixXR^-1yZR^-1yendpmatrix","category":"page"},{"location":"details/#REML","page":"Details","title":"REML","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"logREML(thetabeta) = -fracN-p2 - frac12sum_i=1^nlogV_theta i-\n\n-frac12logsum_i=1^nX_iV_theta i^-1X_i-frac12sum_i=1^n(y_i - X_ibeta)V_theta i^-1(y_i - X_ibeta)","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"Actually L(theta) = -2logREML = L_1(theta) + L_2(theta) + L_3(theta) + c used for optimization, where:","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"L_1(theta) = frac12sum_i=1^nlogV_i \n\nL_2(theta) = frac12logsum_i=1^nX_iV_i^-1X_i \n\nL_3(theta) = frac12sum_i=1^n(y_i - X_ibeta)V_i^-1(y_i - X_ibeta)","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"nablamathcalL(theta) = nabla L_1(theta) + nabla L_2(theta) + nabla L_3(theta)","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"mathcalHmathcalL(theta) = mathcalHL_1(theta) + mathcalHL_2(theta) + mathcalH L_3(theta)","category":"page"},{"location":"details/#weights_header","page":"Details","title":"Weights","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"If weights defined:","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"\nW_i = diag(wts_i)\n\n\n\nV_i = Z_i G Z_i+ W^- frac12_i R_i W^- frac12_i","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"where W - diagonal matrix of weights.","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"If wts is matrix then:","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"\nW_i = wts_i\n\n\n\nV_i = Z_i G Z_i+ R_i circ W_i","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"where circ - element-wise multiplication.","category":"page"},{"location":"details/#Multiple-random-and-repeated-effects","page":"Details","title":"Multiple random and repeated effects","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"If model include multiple effects ( with n random and m repeated effects) final V will be:","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"V_i = Z_i 1 G_1 Z_i 1 + + Z_i n G_1 Z_i n+ W^- frac12_i ( R_i 1 + + R_i m) W^- frac12_i","category":"page"},{"location":"details/#Initial-step","page":"Details","title":"Initial step","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"Initial (first) step before optimization may be done:","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"theta_n+1 = theta_n - nablamathcalL(theta_n) * mathcalH^(theta_n) where \n\nmathcalH^(theta_n) = - mathcalHL_1(theta_n) + mathcalH L_3(theta) if score \n\nmathcalH^(theta_n) = mathcalH L_3(theta_n) if ai\n","category":"page"},{"location":"details/#Beta-(β)","page":"Details","title":"Beta (β)","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"beta = (sum_i=1^n X_iV_i^-1X_i)^-1(sum_i=1^n X_iV_i^-1y_i)","category":"page"},{"location":"details/#F","page":"Details","title":"F","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"F = fracbetaL(LCL)^-1Lbetarank(LCL)","category":"page"},{"location":"details/#Variance-covariance-matrix-of-β","page":"Details","title":"Variance covariance matrix of β","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"C = (sum_i=1^n X_iV_i^-1X_i)^-1","category":"page"},{"location":"details/#Sweep","page":"Details","title":"Sweep","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"Details see: https://github.com/joshday/SweepOperator.jl","category":"page"},{"location":"details/#varlink_header","page":"Details","title":"Variance parameters link function","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"Apply special function to some part of theta vector.","category":"page"},{"location":"details/#Variance-(var)-part","page":"Details","title":"Variance (var) part","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"Applied only to variance part.","category":"page"},{"location":"details/#Exponential-function-(:exp)","page":"Details","title":"Exponential function (:exp)","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"Exponential function applied.","category":"page"},{"location":"details/","page":"Details","title":"Details","text":" f(x) = exp(x)","category":"page"},{"location":"details/","page":"Details","title":"Details","text":" f^-1(x) = log(x)","category":"page"},{"location":"details/#Square-function-(:sq)","page":"Details","title":"Square function (:sq)","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":" f(x) = x^2","category":"page"},{"location":"details/","page":"Details","title":"Details","text":" f^-1(x) = sqrt(x)","category":"page"},{"location":"details/#Identity-function-(:identity)","page":"Details","title":"Identity function (:identity)","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":" f(x) = x","category":"page"},{"location":"details/","page":"Details","title":"Details","text":" f^-1(x) = x","category":"page"},{"location":"details/#Covariance-(rho)-part","page":"Details","title":"Covariance (rho) part","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"Applied only to covariance part.","category":"page"},{"location":"details/#Sigmoid-function-(:sigm)","page":"Details","title":"Sigmoid function (:sigm)","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":" f(x) = 1 (1 + exp(- x * k)) * 2 - 1","category":"page"},{"location":"details/","page":"Details","title":"Details","text":" f^-1(x) = -log(1 (x + 1) * 2 - 1) k","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"where k = 01","category":"page"},{"location":"details/#Arctangent-function-(:atan)","page":"Details","title":"Arctangent function (:atan)","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":" f(x) = atan(x)pi*2","category":"page"},{"location":"details/","page":"Details","title":"Details","text":" f^-1(x) = tan(x*pi2)","category":"page"},{"location":"details/#\"Square\"-sigmoid-function-(:sqsigm)","page":"Details","title":"\"Square\" sigmoid function (:sqsigm)","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":" f(x) = x sqrt1 + (x)^2","category":"page"},{"location":"details/","page":"Details","title":"Details","text":" f^-1(x) = sign(x) * sqrtx^2(1 - x^2)","category":"page"},{"location":"details/#Positive-sigmoid-function-(:psigm)","page":"Details","title":"Positive sigmoid function (:psigm)","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":" f(x) = 1(1 + exp(-x 2))","category":"page"},{"location":"details/","page":"Details","title":"Details","text":" f^-1(x) = -log(1x - 1) * 2","category":"page"},{"location":"details/#Additional-parameters-(theta)-part","page":"Details","title":"Additional parameters (theta) part","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"No function applied.","category":"page"},{"location":"mi/#Multiple-imputation","page":"Multiple imputation","title":"Multiple imputation","text":"","category":"section"},{"location":"mi/#Metida.milmm","page":"Multiple imputation","title":"Metida.milmm","text":"","category":"section"},{"location":"mi/","page":"Multiple imputation","title":"Multiple imputation","text":"Metida.milmm","category":"page"},{"location":"mi/#Metida.milmm","page":"Multiple imputation","title":"Metida.milmm","text":"milmm(mi::MILMM; n = 100, verbose = true, rng = default_rng())\n\nMultiple imputation.\n\nwarning: Warning\nExperimental: API not stable\n\nFor each subject random vector of missing values generated from distribution:\n\nX_imp sim N(mu_miss mid obs Sigma_miss mid obs)\n\nmu_miss mid obs = mu_1+ Sigma_12 Sigma_22^-1 (x_obs- mu_2)\n\nSigma_miss mid obs = Sigma_11- Sigma_12 Sigma_22^-1 Sigma_21\n\nx = beginbmatrixx_miss x_obs endbmatrix\nmu = beginbmatrixmu_1 mu_2 endbmatrix\nSigma = beginbmatrix Sigma_11 Sigma_12 Sigma_21 Sigma_22 endbmatrix\n\nExample:\n\nlmm = Metida.LMM(@formula(var~sequence+period+formulation), df0m;\nrandom = Metida.VarEffect(Metida.@covstr(formulation|subject), Metida.CSH),\n)\nMetida.fit!(lmm)\nmi = Metida.MILMM(lmm, df0m)\nbm = Metida.milmm(mi; n = 100, rng = MersenneTwister(1234))\n\n\n\n\n\nmilmm(lmm::LMM, data; n = 100, verbose = true, rng = default_rng())\n\nMultiple imputation in one step. data for lmm and for milmm should be the same, if different data used resulst can be unpredictable.\n\n\n\n\n\n","category":"function"},{"location":"mi/#Metida.miboot","page":"Multiple imputation","title":"Metida.miboot","text":"","category":"section"},{"location":"mi/","page":"Multiple imputation","title":"Multiple imputation","text":"Metida.miboot","category":"page"},{"location":"mi/#Metida.miboot","page":"Multiple imputation","title":"Metida.miboot","text":"miboot(mi::MILMM{T}; n = 100, double = true, bootn = 100, verbose = true, rng = default_rng())\n\nMultiple imputation with parametric bootstrap step.\n\nwarning: Warning\nExperimental: API not stable\n\nExample:\n\nlmm = Metida.LMM(@formula(var~sequence+period+formulation), df0m;\nrandom = Metida.VarEffect(Metida.@covstr(formulation|subject), Metida.CSH),\n)\nMetida.fit!(lmm)\nmi = Metida.MILMM(lmm, df0m)\nbm = Metida.miboot(mi; n = 100, rng = MersenneTwister(1234))\n\n\n\n\n\n","category":"function"},{"location":"instanduse/#Installation","page":"First step","title":"Installation","text":"","category":"section"},{"location":"instanduse/","page":"First step","title":"First step","text":"ENV[\"GKSwstype\"] = \"nul\"\nusing Plots, StatsPlots, CSV, DataFrames, Metida\n\ngr()\n\nPlots.reset_defaults()\n\nrds = CSV.File(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"csv\", \"1fptime.csv\"); types = [String, String, Float64, Float64]) |> DataFrame\n\np = @df rds plot(:time, :response, group = (:subject, :factor), colour = [:red :blue], legend = false)\n\npng(p, \"plot1.png\")\n\nrds = CSV.File(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"csv\", \"1freparma.csv\"); types = [String, String, Float64, Float64]) |> DataFrame\n\np = @df rds plot(:time, :response, group = (:subject, :factor), colour = [:red :blue], legend = false)\n\npng(p, \"plot2.png\")","category":"page"},{"location":"instanduse/","page":"First step","title":"First step","text":"import Pkg; Pkg.add(\"Metida\")","category":"page"},{"location":"instanduse/#Simple-example","page":"First step","title":"Simple example","text":"","category":"section"},{"location":"instanduse/","page":"First step","title":"First step","text":"LMM\nMetida.@covstr\nMetida.VarEffect\nfit!","category":"page"},{"location":"instanduse/#Step-1:-Load-data","page":"First step","title":"Step 1: Load data","text":"","category":"section"},{"location":"instanduse/","page":"First step","title":"First step","text":"Load provided data with CSV and DataFrames:","category":"page"},{"location":"instanduse/","page":"First step","title":"First step","text":"using Metida, CSV, DataFrames, CategoricalArrays\n\ndf = CSV.File(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"csv\", \"df0.csv\")) |> DataFrame;\nnothing # hide","category":"page"},{"location":"instanduse/","page":"First step","title":"First step","text":"note: Note\nCheck that all categorical variables are categorical.","category":"page"},{"location":"instanduse/","page":"First step","title":"First step","text":"transform!(df, :subject => categorical, renamecols=false)\ntransform!(df, :period => categorical, renamecols=false)\ntransform!(df, :sequence => categorical, renamecols=false)\ntransform!(df, :formulation => categorical, renamecols=false)\nnothing # hide","category":"page"},{"location":"instanduse/#Step-2:-Make-model","page":"First step","title":"Step 2: Make model","text":"","category":"section"},{"location":"instanduse/","page":"First step","title":"First step","text":"Make model with @formula macro from StatsModels. Define random and repreated effects with Metida.VarEffect using Metida.@covstr macros. Left side of @covstr is model of effect and right side is a effect itself. Metida.HeterogeneousCompoundSymmetry and Metida.Diag (Diagonal) in example bellow is a model of variance-covariance structure. See also Metida.@lmmformula macro.","category":"page"},{"location":"instanduse/","page":"First step","title":"First step","text":"note: Note\nIn some cases levels of repeated effect should not be equal inside each level of subject or model will not have any sense. For example, it is assumed that usually CSH or UN (Unstructured) using with levels of repeated effect is different inside each level of subject. Metida does not check this!","category":"page"},{"location":"instanduse/","page":"First step","title":"First step","text":"lmm = LMM(@formula(var~sequence+period+formulation), df;\nrandom = VarEffect(@covstr(formulation|subject), CSH),\nrepeated = VarEffect(@covstr(formulation|subject), DIAG));","category":"page"},{"location":"instanduse/","page":"First step","title":"First step","text":"Also Metida.@lmmformula macro can be used:","category":"page"},{"location":"instanduse/","page":"First step","title":"First step","text":"lmm = LMM(@lmmformula(var~sequence+period+formulation,\n random = formulation|subject:CSH,\n repeated = formulation|subject:DIAG),\n df)","category":"page"},{"location":"instanduse/#Step-3:-Fit","page":"First step","title":"Step 3: Fit","text":"","category":"section"},{"location":"instanduse/","page":"First step","title":"First step","text":"Just fit the model.","category":"page"},{"location":"instanduse/","page":"First step","title":"First step","text":"fit!(lmm)","category":"page"},{"location":"instanduse/#Check-warnings-and-errors-in-log.","page":"First step","title":"Check warnings and errors in log.","text":"","category":"section"},{"location":"instanduse/","page":"First step","title":"First step","text":"lmm.log","category":"page"},{"location":"instanduse/#Confidence-intervals-for-coefficients","page":"First step","title":"Confidence intervals for coefficients","text":"","category":"section"},{"location":"instanduse/","page":"First step","title":"First step","text":"confint(lmm)","category":"page"},{"location":"instanduse/","page":"First step","title":"First step","text":"note: Note\nSatterthwaite approximation for the denominator degrees of freedom used by default.","category":"page"},{"location":"instanduse/#StatsBsae-API","page":"First step","title":"StatsBsae API","text":"","category":"section"},{"location":"instanduse/","page":"First step","title":"First step","text":"StatsBsae API implemented: Metida.islinear, Metida.confint, Metida.coef, Metida.coefnames, Metida.dof_residual, Metida.dof, Metida.loglikelihood, Metida.aic, Metida.bic, Metida.aicc, Metida.isfitted, Metida.vcov, Metida.stderror, Metida.modelmatrix, Metida.response, Metida.crossmodelmatrix, Metida.coeftable, Metida.responsename","category":"page"},{"location":"instanduse/#Type-III-Tests-of-Fixed-Effects","page":"First step","title":"Type III Tests of Fixed Effects","text":"","category":"section"},{"location":"instanduse/","page":"First step","title":"First step","text":"warning: Warning\nExperimental","category":"page"},{"location":"instanduse/","page":"First step","title":"First step","text":"typeiii(lmm)","category":"page"},{"location":"instanduse/#Model-construction","page":"First step","title":"Model construction","text":"","category":"section"},{"location":"instanduse/","page":"First step","title":"First step","text":"To construct model you can use LMM constructor. ","category":"page"},{"location":"instanduse/","page":"First step","title":"First step","text":"model - example: @formula(var ~ sequence + period + formulation)\nrandom - effects can be specified like this: VarEffect(@covstr(formulation|subject), CSH). @covstr is a effect model: @covstr(formulation|subject). CSH is a CovarianceType structure. Premade constants: SI, DIAG, AR, ARH, CS, CSH, ARMA, TOEP, TOEPH, UN, ets. If not specified only repeated used.\nrepeated - can be specified like random effect. If not specified VarEffect(@covstr(1|1), SI) used. If no repeated effects specified vector of ones used.","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Q1: Why it working so slow?","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Metida.jl work with small and medium datasets. Model fitting is based on variance-covariance matrix inversion at each iteration. That's why if you have big blocks it will work slow. If you have big blocks you can try to use MetidaCu.jl for optimization on CUDA GPU. You can use MetidaNLopt.jl for better performance, but you will not get Hessian matrix at the end of optimization. Also if you don't need to specify repeated-measures (R) covariance part and use SI, DIAG, CS, CSH covariance types for random-effect part (G) you can use MixedModels.jl - it work much faster.","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Q2: What blocks is?","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Blocks depend on subjects. If you have only one random effect block is equivalent to subject. If you have more than one random effect blocks will be made as non-crossing combination for all subject variables. ","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Q3: Why model does not converge?","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Optimization of REML function can depend on many factors. In some cases covariance parameters can be correlated (ill-conditioned/singular covariance matrix). So hypersurface in the maximum area can be very flat, that why the result can be different for different starting values (or for different software even REML is near equal). Also, some models can not be fitted for specific data at all. If the model not fitted try to check how meaningful and reasonable is the model or try to guess more robust initial conditions.","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Q4: Is model fitting is correct?","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Use 'lmm.log' to see warnings and errors. If you have warnings and error maybe this model is overspecified. Try to change variance structure or guess more robust initial conditions.","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Q5: How to choose best variance-covariance structure?","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"SAS Manual, Mixed Models Analyses Using the SAS System Course Notes:","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Unfortunately, our attempt to share a very RECENT perspective by a relatively small number of statistics and statistics related research has somewhat sidetracked the focus of lesson 1. Would like to attempt to provide some clarity to some of the discussion on the discussion forum about the bar chart vs. interval charts. You can use information criteria produced by the MIXED procedure as a tool to help you select the model with the most appropriate covariance structure. The smaller the information criteria value is, the better the model is. Theoretically, the smaller the -2 Res Log Likelihood is, the better the model is. However, you can always make this value smaller by adding parameters to the model. Information criteria attached penalties to the negative -2 Res Log Likelihood value; that is, the more the parameters, the bigger the penalties. Two commonly used information criteria are Akaike's (1974) and Schwartz's (1978). Generally speaking, BIC tends to choose less complex models than AIC. Because choosing a model that is too simple inflates Type I error rate, when Type I error control is the highest priority, you may want to use AIC. On the other hand, if loss of power is more of a concern, BIC might be preferable (Guerin and Stroup 2000). Starting in the Release 8.1, the MIXED procedure produces another information criteria, AICC. AICC is a finite-sample corrected Akaike Information Criterion. For small samples, it reduces the bias produced by AIC; for large samples, AICC converges to AIC. In general, AICC is preferred to AIC. For more information on information criteria, especially AICC, refer to Burnham, K. P. and Anderson, D. R. (1998). The basic idea for repeated measures analysis is that, among plausible within-subject covariance models given a particular study, the model that minimizes AICC or BIC (your choice) is preferable. When AICC or BIC are close, the simpler model is generally preferred.","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Q6: I have a slightly different results for DF calculation, what's wrong?","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Check logs. If final hessian matrix for REML function is ill-conditioned results on differet OS can be slightly different. If possible, try to use more stable covariance structure. Or make an issue on github.","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Q7: I changed maxthreads settings but nothing happend. ","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Check the number of execution threads: Threads.nthreads(), maybe you should change julia startup settings. See also julia threads docs.","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"See also:","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Barnett, A.G., Koper, N., Dobson, A.J., Schmiegelow, F. and Manseau, M. (2010), Using information criteria to select the correct variance–covariance structure for longitudinal data in ecology. Methods in Ecology and Evolution, 1: 15-24. https://doi.org/10.1111/j.2041-210X.2009.00009.x\nGuidelines for Selecting the Covariance Structure in Mixed Model Analysis\nH. J. Keselman,James Algina,Rhonda K. Kowalchuk &Russell D. Wolfinger. A comparison of two approaches for selecting covariance structures in the analysis of repeated measurements. https://doi.org/10.1080/03610919808813497","category":"page"},{"location":"api/#API","page":"API","title":"API","text":"","category":"section"},{"location":"api/#Basic","page":"API","title":"Basic","text":"","category":"section"},{"location":"api/#@covstr","page":"API","title":"@covstr","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.@covstr","category":"page"},{"location":"api/#Metida.@covstr","page":"API","title":"Metida.@covstr","text":"@covstr(ex)\n\nMacros for random/repeated effect model.\n\nExample\n\n@covstr(factor|subject)\n\n\n\n\n\n","category":"macro"},{"location":"api/#@lmmformula","page":"API","title":"@lmmformula","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.@lmmformula","category":"page"},{"location":"api/#Metida.@lmmformula","page":"API","title":"Metida.@lmmformula","text":"@lmmformula(formula, args...)\n\nMacro for made formula with variance-covariance structure representation. @lmmformula could be used for shorter LMM construction.\n\nExample:\n\nlmm = Metida.LMM(@lmmformula(var~sequence+period+formulation,\nrandom = formulation|subject:CSH,\nrepeated = formulation|subject:DIAG),\ndf0)\n\nequal to:\n\nlmm = LMM(@formula(var~sequence+period+formulation), df0;\nrandom = VarEffect(@covstr(formulation|subject), CSH),\nrepeated = VarEffect(@covstr(formulation|subject), DIAG),\n)\n\n@lmmformula have 3 components - 1'st is a formula for fixed effect, it's defined like in StstsModels (1st argument just provided to @formula macro). Other arguments should be defined like keywords. repeated keyword define repeated effect part, random - define random effect part. You can use several random factors as in example bellow:\n\nlmm = LMM(@lmmformula(var~sequence+period+formulation,\nrandom = formulation|subject:CSH,\nrandom = 1|subject:DIAG,\nrepeated = formulation|subject:DIAG),\ndf0)\n\nrandom or repeated structure made by template:\n\neffect formula | blocking factor [/ nested factor] [: covariance structure]\n\n| - devide effect formula form blocking factor definition (necessarily), / and : modificator are optional.\n\n/ 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.\n\n: - covariance structure defined right after : (SI, DIAG, CS, CSH, ets...), if : not used then SI used for this effect.\n\nTerms like a+b or a*b shuould not be used as a blocking factors.\n\n\n\n\n\n","category":"macro"},{"location":"api/#Metida.CovarianceType","page":"API","title":"Metida.CovarianceType","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.CovarianceType","category":"page"},{"location":"api/#Metida.CovarianceType","page":"API","title":"Metida.CovarianceType","text":"CovarianceType(cm::AbstractCovmatMethod)\n\nMake covariance type with AbstractCovmatMethod.\n\n\n\n\n\n","category":"type"},{"location":"api/#LMM","page":"API","title":"LMM","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.LMM","category":"page"},{"location":"api/#Metida.LMM","page":"API","title":"Metida.LMM","text":"LMM(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)\n\nMake Linear-Mixed Model object.\n\nmodel: is a fixed-effect model (@formula)\n\ndata: tabular data\n\ncontrasts: contrasts for fixed factors\n\nrandom: vector of random effects or single random effect\n\nrepeated: is a repeated effect or vector\n\nwts: regression weights (residuals).\n\nWeigts 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.\n\nSee also: @lmmformula\n\n\n\n\n\n","category":"type"},{"location":"api/#VarEffect","page":"API","title":"VarEffect","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.VarEffect","category":"page"},{"location":"api/#Metida.VarEffect","page":"API","title":"Metida.VarEffect","text":"VarEffect(formula, covtype::T, coding) where T <: AbstractCovarianceType\n\nVarEffect(formula, covtype::T; coding = nothing) where T <: AbstractCovarianceType\n\nVarEffect(formula; coding = nothing)\n\nRandom/repeated effect.\n\nformula from @covstr(ex) macros.\ncovtype - covariance type (SI, DIAG, CS, CSH, AR, ARH, ARMA, TOEP, TOEPH, TOEPP, TOEPHP)\n\nnote: Note\nCategorical factors are coded with FullDummyCoding() by default, use coding for other contrast codeing.\n\nExample\n\nVarEffect(@covstr(1+factor|subject), CSH)\n\nVarEffect(@covstr(1 + formulation|subject), CSH; coding = Dict(:formulation => StatsModels.DummyCoding()))\n\n\n\n\n\n","category":"type"},{"location":"api/#Covariance-structures","page":"API","title":"Covariance structures","text":"","category":"section"},{"location":"api/#Metida.Autoregressive","page":"API","title":"Metida.Autoregressive","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.Autoregressive","category":"page"},{"location":"api/#Metida.Autoregressive","page":"API","title":"Metida.Autoregressive","text":"Autoregressive()\n\nAutoregressive covariance type.\n\nAR = Autoregressive()\n\nbeginbmatrix 1 rho rho^2 rho^3 \nrho 1 rho rho^2 rho^2 rho 1 rho \nrho^3 rho^2 rho 1\nendbmatrixsigma^2\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.AutoregressiveMovingAverage","page":"API","title":"Metida.AutoregressiveMovingAverage","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.AutoregressiveMovingAverage","category":"page"},{"location":"api/#Metida.AutoregressiveMovingAverage","page":"API","title":"Metida.AutoregressiveMovingAverage","text":"AutoregressiveMovingAverage()\n\nAutoregressive moving average covariance type.\n\nARMA = AutoregressiveMovingAverage()\n\nbeginbmatrix 1 gamma gammarho gammarho^2 \ngamma 1 gamma gammarho \ngammarho gamma 1 gamma \ngammarho^2 gammarho gamma 1\nendbmatrixsigma^2\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.CompoundSymmetry","page":"API","title":"Metida.CompoundSymmetry","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.CompoundSymmetry","category":"page"},{"location":"api/#Metida.CompoundSymmetry","page":"API","title":"Metida.CompoundSymmetry","text":"CompoundSymmetry()\n\nCompound symmetry covariance type.\n\nCS = CompoundSymmetry()\n\nbeginbmatrix 1 rho rho rho \nrho 1 rho rho \nrho rho 1 rho \nrho rho rho 1\nendbmatrixsigma^2\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.Diag","page":"API","title":"Metida.Diag","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.Diag","category":"page"},{"location":"api/#Metida.Diag","page":"API","title":"Metida.Diag","text":"Diag()\n\nDiagonal covariance type.\n\nDIAG = Diag()\n\nbeginbmatrix sigma_a^2 0 0 0 sigma_b^2 0 0 0 sigma_c^2 endbmatrix\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.HeterogeneousAutoregressive","page":"API","title":"Metida.HeterogeneousAutoregressive","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.HeterogeneousAutoregressive","category":"page"},{"location":"api/#Metida.HeterogeneousAutoregressive","page":"API","title":"Metida.HeterogeneousAutoregressive","text":"HeterogeneousAutoregressive()\n\nHeterogeneous autoregressive covariance type.\n\nARH = HeterogeneousAutoregressive()\n\nbeginbmatrix\nsigma_a^2 rhosigma_asigma_b rho^2sigma_asigma_c rho^3sigma_asigma_d \nrhosigma_bsigma_a sigma_b^2 rhosigma_bsigma_c rho^2sigma_bsigma_d \nrho^2sigma_csigma_a rhosigma_csigma_b sigma_c^2 rhosigma_csigma_d \nrho^3sigma_dsigma_a rho^2sigma_dsigma_b rhosigma_dsigma_c sigma_d^2\nendbmatrix\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.HeterogeneousCompoundSymmetry","page":"API","title":"Metida.HeterogeneousCompoundSymmetry","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.HeterogeneousCompoundSymmetry","category":"page"},{"location":"api/#Metida.HeterogeneousCompoundSymmetry","page":"API","title":"Metida.HeterogeneousCompoundSymmetry","text":"HeterogeneousCompoundSymmetry()\n\nHeterogeneous compound symmetry covariance type.\n\nCSH = HeterogeneousCompoundSymmetry()\n\nbeginbmatrix\nsigma_a^2 rhosigma_asigma_b rhosigma_asigma_c rhosigma_asigma_d \nrhosigma_bsigma_a sigma_b^2 rhosigma_bsigma_c rhosigma_bsigma_d \nrhosigma_csigma_a rhosigma_csigma_b sigma_c^2 rhosigma_csigma_d \nrhosigma_dsigma_a rhosigma_dsigma_b rhosigma_dsigma_c sigma_d^2\nendbmatrix\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.HeterogeneousToeplitz","page":"API","title":"Metida.HeterogeneousToeplitz","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.HeterogeneousToeplitz","category":"page"},{"location":"api/#Metida.HeterogeneousToeplitz","page":"API","title":"Metida.HeterogeneousToeplitz","text":"HeterogeneousToeplitz()\n\nHeterogeneous toeplitz covariance type. Only for G matrix.\n\nTOEPH = HeterogeneousToeplitz()\n\nbeginbmatrix\nsigma_a^2 rho_1 sigma_a sigma_b rho_2 sigma_a sigma_c rho_3 sigma_a sigma_d \nrho_1 sigma_b sigma_a sigma_b^2 rho_1 sigma_b sigma_c rho_2 sigma_b sigma_d \nrho_2 sigma_c sigma_a rho_1 sigma_c sigma_b sigma_c^2 rho_1 sigma_c sigma_d \nrho_3 sigma_d sigma_a rho_2 sigma_d sigma_b rho_1 sigma_d sigma_c sigma_d^2\nendbmatrix\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.HeterogeneousToeplitzParameterized","page":"API","title":"Metida.HeterogeneousToeplitzParameterized","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.HeterogeneousToeplitzParameterized","category":"page"},{"location":"api/#Metida.HeterogeneousToeplitzParameterized","page":"API","title":"Metida.HeterogeneousToeplitzParameterized","text":"HeterogeneousToeplitzParameterized(p::Int)\n\nHeterogeneous toeplitz covariance type with parameter p, (number of bands = p - 1, if p = 1 it's equal DIAG structure).\n\nTOEPHP(p) = HeterogeneousToeplitzParameterized(p)\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.ScaledIdentity","page":"API","title":"Metida.ScaledIdentity","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.ScaledIdentity","category":"page"},{"location":"api/#Metida.ScaledIdentity","page":"API","title":"Metida.ScaledIdentity","text":"ScaledIdentity()\n\nScaled identity covariance type.\n\nSI = ScaledIdentity()\n\nbeginbmatrix 1 0 0 0 1 0 0 0 1 endbmatrixsigma^2\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.SpatialExponential","page":"API","title":"Metida.SpatialExponential","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.SpatialExponential","category":"page"},{"location":"api/#Metida.SpatialExponential","page":"API","title":"Metida.SpatialExponential","text":"SpatialExponential()\n\nSpatian Exponential covariance structure. Used only for repeated effect.\n\nR_ij = sigma^2 * exp(-dist(ij)theta)\n\nwhere dist - Euclidean distance between row-vectors of repeated effect matrix for subject i and j, θ > 0.\n\nSPEXP = SpatialExponential()\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.SpatialGaussian","page":"API","title":"Metida.SpatialGaussian","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.SpatialGaussian","category":"page"},{"location":"api/#Metida.SpatialGaussian","page":"API","title":"Metida.SpatialGaussian","text":"SpatialGaussian()\n\nSpatian Gaussian covariance structure. Used only for repeated effect.\n\nR_ij = sigma^2 * exp(- dist(ij)^2 theta^2)\n\nwhere dist - Euclidean distance between row-vectors of repeated effect matrix for subject i and j, θ ≠ 0.\n\nSPGAU = SpatialGaussian()\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.SpatialPower","page":"API","title":"Metida.SpatialPower","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.SpatialPower","category":"page"},{"location":"api/#Metida.SpatialPower","page":"API","title":"Metida.SpatialPower","text":"SpatialPower()\n\nSpatian Power covariance structure. Used only for repeated effect.\n\nR_ij = sigma^2 * rho^dist(ij)\n\nwhere dist - Euclidean distance between row-vectors of repeated effect matrix for subject i and j, 1 > ρ > -1.\n\nSPPOW = SpatialPower()\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.Toeplitz","page":"API","title":"Metida.Toeplitz","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.Toeplitz","category":"page"},{"location":"api/#Metida.Toeplitz","page":"API","title":"Metida.Toeplitz","text":"Toeplitz()\n\nToeplitz covariance type. Only for G matrix.\n\nTOEP = Toeplitz()\n\nbeginbmatrix 1 rho_1 rho_2 rho_3 \nrho_1 1 rho_1 rho_2 \nrho_2 rho_1 1 rho_1 \nrho_3 rho_2 rho_1 1\nendbmatrixsigma^2\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.ToeplitzParameterized","page":"API","title":"Metida.ToeplitzParameterized","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.ToeplitzParameterized","category":"page"},{"location":"api/#Metida.ToeplitzParameterized","page":"API","title":"Metida.ToeplitzParameterized","text":"ToeplitzParameterized(p::Int)\n\nToeplitz covariance type with parameter p, (number of bands = p - 1, if p = 1 it's equal SI structure).\n\nTOEPP(p) = ToeplitzParameterized(p)\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.Unstructured","page":"API","title":"Metida.Unstructured","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.Unstructured","category":"page"},{"location":"api/#Metida.Unstructured","page":"API","title":"Metida.Unstructured","text":"Unstructured()\n\nUnstructured 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.\n\nUN = Unstructured()\n\n\n\n\n\n","category":"function"},{"location":"api/#Methods","page":"API","title":"Methods","text":"","category":"section"},{"location":"api/#Metida.caic","page":"API","title":"Metida.caic","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.caic","category":"page"},{"location":"api/#Metida.caic","page":"API","title":"Metida.caic","text":"caic(lmm::LMM)\n\nConditional Akaike Information Criterion.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.coefn","page":"API","title":"Metida.coefn","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.coefn","category":"page"},{"location":"api/#Metida.coefn","page":"API","title":"Metida.coefn","text":"coefn(lmm)\n\nCoef number.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.dof_satter","page":"API","title":"Metida.dof_satter","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.dof_satter","category":"page"},{"location":"api/#Metida.dof_satter","page":"API","title":"Metida.dof_satter","text":"dof_satter(lmm::LMM{T}, l) where T\n\nReturn Satterthwaite approximation for the denominator degrees of freedom, where l is a contrast vector (estimable linear combination of fixed effect coefficients vector (β).\n\ndf = frac2(LCL)^2gAg\n\nWhere: A = 2H^-1, g = triangledown_theta(LC^-1_thetaL)\n\n\n\n\n\ndof_satter(lmm::LMM{T}, n::Int) where T\n\nReturn Satterthwaite approximation for the denominator degrees of freedom, where n - coefficient number.\n\n\n\n\n\ndof_satter(lmm::LMM{T}) where T\n\nReturn Satterthwaite approximation for the denominator degrees of freedom for all coefficients.\n\n\n\n\n\ndof_satter(lmm::LMM{T}, l::Matrix) where T\n\nReturn Satterthwaite approximation for the denominator degrees of freedom for conrast matrix l.\n\nFor size(l, 1) > 1:\n\ndf = frac2EE - rank(LCL)\n\nwhere:\n\nlet LCL = QΛQ^-1, where QΛQ^-1 - spectral decomposition of LCL\nLq_i is the i-th row of Q^-1L\nA = 2H^-1, g = triangledown_theta(Lq_i C^-1_theta Lq_i)\nv_i = frac2*Λ_ii^2g * A * g\nE = sum_i=1^n fracv_i(v_i - 2) for v_i 2\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.estimate","page":"API","title":"Metida.estimate","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.estimate","category":"page"},{"location":"api/#Metida.estimate","page":"API","title":"Metida.estimate","text":"estimate(lmm, l::AbstractVector; level = 0.95, name = \"Estimate\")\n\nEstimate table for l vector. Satter DF used.\n\n\n\n\n\nestimate(lmm; level = 0.95)\n\nEstimates table. Satter DF used.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.getlog","page":"API","title":"Metida.getlog","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.getlog","category":"page"},{"location":"api/#Metida.getlog","page":"API","title":"Metida.getlog","text":"getlog(lmm::LMM)\n\nReturn fitting log.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.gmatrix","page":"API","title":"Metida.gmatrix","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.gmatrix","category":"page"},{"location":"api/#Metida.gmatrix","page":"API","title":"Metida.gmatrix","text":"gmatrix(lmm::LMM{T}, r::Int) where T\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.hessian","page":"API","title":"Metida.hessian","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.hessian","category":"page"},{"location":"api/#Metida.hessian","page":"API","title":"Metida.hessian","text":"hessian(lmm, theta)\n\nCalculate Hessian matrix of REML for theta.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.lcontrast","page":"API","title":"Metida.lcontrast","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.lcontrast","category":"page"},{"location":"api/#Metida.lcontrast","page":"API","title":"Metida.lcontrast","text":"lcontrast(lmm::LMM, i::Int)\n\nL-contrast matrix for i fixed effect.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.nblocks","page":"API","title":"Metida.nblocks","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.nblocks","category":"page"},{"location":"api/#Metida.nblocks","page":"API","title":"Metida.nblocks","text":"Number of blocks\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.rand","page":"API","title":"Metida.rand","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.rand","category":"page"},{"location":"api/#Base.rand","page":"API","title":"Base.rand","text":"rand(rng::AbstractRNG, lmm::LMM{T}) where T\n\nGenerate random responce vector for fitted 'lmm' model.\n\n\n\n\n\nrand(rng::AbstractRNG, lmm::LMM{T}; theta) where T\n\nGenerate random responce vector 'lmm' model, theta covariance vector, and zero means.\n\n\n\n\n\nrand(rng::AbstractRNG, lmm::LMM{T}; theta, beta) where T\n\nGenerate random responce vector 'lmm' model, theta covariance vector and mean's vector.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.rand-2","page":"API","title":"Metida.rand","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.rand!","category":"page"},{"location":"api/#Random.rand!","page":"API","title":"Random.rand!","text":"rand!(v::AbstractVector, lmm::LMM) = rand!(default_rng(), v, lmm, lmm.result.theta, lmm.result.beta)\n\nGenerate random responce vector for fitted 'lmm' model, store results in v.\n\n\n\n\n\nrand!(rng::AbstractRNG, lmm::LMM{T}; theta) where T\n\nGenerate random responce vector 'lmm' model, theta covariance vector, and zero means, store results in v.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.raneff","page":"API","title":"Metida.raneff","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.raneff","category":"page"},{"location":"api/#Metida.raneff","page":"API","title":"Metida.raneff","text":"raneff(lmm::LMM{T}, i)\n\nVector of random effect coefficients for block i.\n\n\n\n\n\nraneff(lmm::LMM{T})\n\nVector of random effect coefficients for all subjects by each random effect.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.raneffn","page":"API","title":"Metida.raneffn","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.raneffn","category":"page"},{"location":"api/#Metida.raneffn","page":"API","title":"Metida.raneffn","text":"raneffn(lmm)\n\nRetuen number of random effects.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.rankx","page":"API","title":"Metida.rankx","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.rankx","category":"page"},{"location":"api/#Metida.rankx","page":"API","title":"Metida.rankx","text":"rankx(lmm::LMM)\n\nReturn rank of X matrix.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.rmatrix","page":"API","title":"Metida.rmatrix","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.rmatrix","category":"page"},{"location":"api/#Metida.rmatrix","page":"API","title":"Metida.rmatrix","text":"rmatrix(lmm::LMM{T}, i::Int) where T\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.theta","page":"API","title":"Metida.theta","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.theta","category":"page"},{"location":"api/#Metida.theta","page":"API","title":"Metida.theta","text":"theta(lmm::LMM)\n\nReturn theta vector.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.thetalength","page":"API","title":"Metida.thetalength","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.thetalength","category":"page"},{"location":"api/#Metida.thetalength","page":"API","title":"Metida.thetalength","text":"thetalength(lmm::LMM)\n\nLength of theta vector.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.vmatrix","page":"API","title":"Metida.vmatrix","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.vmatrix!","category":"page"},{"location":"api/#Metida.vmatrix!","page":"API","title":"Metida.vmatrix!","text":"vmatrix!(V, θ, lmm, i)\n\nUpdate variance-covariance matrix V for i bolock. Upper triangular updated.\n\n\n\n\n\n","category":"function"},{"location":"api/#StatsAPI","page":"API","title":"StatsAPI","text":"","category":"section"},{"location":"api/#Metida.aic","page":"API","title":"Metida.aic","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.aic","category":"page"},{"location":"api/#StatsAPI.aic","page":"API","title":"StatsAPI.aic","text":"StatsBase.aic(lmm::LMM)\n\nAkaike Information Criterion.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.aicc","page":"API","title":"Metida.aicc","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.aicc","category":"page"},{"location":"api/#StatsAPI.aicc","page":"API","title":"StatsAPI.aicc","text":"StatsBase.aicc(lmm::LMM)\n\nCorrected Akaike Information Criterion.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.bic","page":"API","title":"Metida.bic","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.bic","category":"page"},{"location":"api/#StatsAPI.bic","page":"API","title":"StatsAPI.bic","text":"StatsBase.bic(lmm::LMM)\n\nBayesian information criterion.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.coef","page":"API","title":"Metida.coef","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.coef","category":"page"},{"location":"api/#StatsAPI.coef","page":"API","title":"StatsAPI.coef","text":"StatsBase.coef(lmm::LMM) = copy(lmm.result.beta)\n\nModel coefficients (β).\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.coefnames","page":"API","title":"Metida.coefnames","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.coefnames","category":"page"},{"location":"api/#StatsAPI.coefnames","page":"API","title":"StatsAPI.coefnames","text":"StatsBase.coefnames(lmm::LMM) = StatsBase.coefnames(lmm.mf)\n\nCoefficients names.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.coeftable","page":"API","title":"Metida.coeftable","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.coeftable","category":"page"},{"location":"api/#StatsAPI.coeftable","page":"API","title":"StatsAPI.coeftable","text":"coeftable(lmm::LMM)\n\nReturn coefficients table.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.confint","page":"API","title":"Metida.confint","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.confint","category":"page"},{"location":"api/#StatsAPI.confint","page":"API","title":"StatsAPI.confint","text":"StatsBase.confint(lmm::LMM{T}; level::Real=0.95, ddf::Symbol = :satter) where T\n\nConfidece interval for coefficients.\n\nddf = :satter/:residual\n\nCI_UL = β SE * t_ddf 1-α2\n\nSee also: dof_satter, dof_residual\n\n\n\n\n\nStatsBase.confint(lmm::LMM{T}, i::Int; level::Real=0.95, ddf::Symbol = :satter) where T\n\nConfidece interval for coefficient i.\n\n\n\n\n\nStatsBase.confint(br::BootstrapResult, n::Int; level::Float64=0.95, method=:bp, metric = :coef, delrml = false)\n\nConfidence interval for bootstrap result.\n\n*method:\n\n:bp - bootstrap percentile;\n:rbp - reverse bootstrap percentile;\n:norm - Normal distribution;\n:bcnorm - Bias corrected Normal distribution;\n:jn - bias corrected (jackknife resampling).\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.crossmodelmatrix","page":"API","title":"Metida.crossmodelmatrix","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.crossmodelmatrix","category":"page"},{"location":"api/#StatsAPI.crossmodelmatrix","page":"API","title":"StatsAPI.crossmodelmatrix","text":"crossmodelmatrix(lmm::LMM)\n\nReturn X'X.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.dof","page":"API","title":"Metida.dof","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.dof","category":"page"},{"location":"api/#StatsAPI.dof","page":"API","title":"StatsAPI.dof","text":"StatsBase.dof(lmm::LMM)\n\nDOF.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.dof_residual","page":"API","title":"Metida.dof_residual","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.dof_residual","category":"page"},{"location":"api/#StatsAPI.dof_residual","page":"API","title":"StatsAPI.dof_residual","text":"StatsBase.dof_residual(lmm::LMM)\n\nDOF residuals: N - rank(X), where N - total number of observations.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.fit","page":"API","title":"Metida.fit","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.fit","category":"page"},{"location":"api/#StatsAPI.fit","page":"API","title":"StatsAPI.fit","text":"fit(::Type{T}, f::FormulaTerm, data;\ncontrasts=Dict{Symbol,Any}(), \nrandom::Union{Nothing, VarEffect, Vector{VarEffect}} = nothing, \nrepeated::Union{Nothing, VarEffect} = nothing,\nkwargs...)\n\nFit LMM model with @formula.\n\nKeywords see fit!\n\n\n\n\n\nfit(::Type{T}, f::LMMformula, data;\ncontrasts=Dict{Symbol,Any}(), \nkwargs...) where T <: LMM\n\nFit LMM model with @lmmformula.\n\nKeywords see fit!\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.fit-2","page":"API","title":"Metida.fit","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.fit!","category":"page"},{"location":"api/#StatsAPI.fit!","page":"API","title":"StatsAPI.fit!","text":"fit!(lmm::LMM{T}; kwargs...\n) where T\n\nFit LMM model.\n\nKeywords:\n\nsolver - :default / :nlopt for using with MetidaNLopt.jl/ :cuda for using with MetidaCu.jl\nverbose - :auto / 1 / 2 / 3 - - 1 - only log, 2 - log and print, 3 - print only errors, other log, 0 (or any other value) - no logging\nvarlinkf - :exp / :sq / :identity ref\nrholinkf - :sigm / :atan / :sqsigm / :psigm\naifirst - first iteration with AI-like method - :default / :ai / :score\naifmax - maximum pre-optimization steps\ng_tol - absolute tolerance in the gradient\nx_tol - absolute tolerance of theta vector\nf_tol - absolute tolerance in changes of the REML\nhes - calculate REML Hessian\ninit - initial theta values\nio - output IO\ntime_limit - time limit = 120 sec\niterations - maximum iterations = 300\nrefitinit - true/false - if true - use last values for initial condition (false by default)\noptmethod - Optimization method. Look at Optim.jl documentation. (Newton by default)\nsingtol - singular tolerance = 1e-8\nmaxthreads - maximum threads = min(num_cores(), Threads.nthreads())\n\n\n\n\n\n","category":"function"},{"location":"api/#islinear","page":"API","title":"islinear","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.islinear ","category":"page"},{"location":"api/#StatsAPI.islinear","page":"API","title":"StatsAPI.islinear","text":"StatsBase.islinear(model::LMM)\n\n\n\n\n\n","category":"function"},{"location":"api/#isfitted","page":"API","title":"isfitted","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.isfitted","category":"page"},{"location":"api/#StatsAPI.isfitted","page":"API","title":"StatsAPI.isfitted","text":"StatsBase.isfitted(lmm::LMM)\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.loglikelihood","page":"API","title":"Metida.loglikelihood","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.loglikelihood","category":"page"},{"location":"api/#StatsAPI.loglikelihood","page":"API","title":"StatsAPI.loglikelihood","text":"StatsBase.loglikelihood(lmm::LMM)\n\nReturn loglikelihood value.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.modelmatrix","page":"API","title":"Metida.modelmatrix","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.modelmatrix","category":"page"},{"location":"api/#StatsAPI.modelmatrix","page":"API","title":"StatsAPI.modelmatrix","text":"StatsBase.modelmatrix(lmm::LMM)\n\nFixed effects matrix.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.nobs","page":"API","title":"Metida.nobs","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.nobs","category":"page"},{"location":"api/#StatsAPI.nobs","page":"API","title":"StatsAPI.nobs","text":"StatsBase.nobs(lmm::MetiaModel)\n\nNumber of observations.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.response","page":"API","title":"Metida.response","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.response","category":"page"},{"location":"api/#StatsAPI.response","page":"API","title":"StatsAPI.response","text":"StatsBase.response(lmm::LMM)\n\nResponse vector.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.responsename","page":"API","title":"Metida.responsename","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.responsename","category":"page"},{"location":"api/#StatsAPI.responsename","page":"API","title":"StatsAPI.responsename","text":"responsename(lmm::LMM)\n\nResponce varible name.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.stderror","page":"API","title":"Metida.stderror","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.stderror","category":"page"},{"location":"api/#StatsAPI.stderror","page":"API","title":"StatsAPI.stderror","text":"StatsBase.stderror(lmm::LMM)\n\nStandard error\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.vcov","page":"API","title":"Metida.vcov","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.vcov","category":"page"},{"location":"api/#StatsAPI.vcov","page":"API","title":"StatsAPI.vcov","text":"StatsBase.vcov(lmm::LMM)\n\nVariance-covariance matrix of β.\n\n\n\n\n\n","category":"function"},{"location":"api/#Experimental","page":"API","title":"Experimental","text":"","category":"section"},{"location":"api/#Metida.SpatialExponentialD","page":"API","title":"Metida.SpatialExponentialD","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.SpatialExponentialD","category":"page"},{"location":"api/#Metida.SpatialExponentialD","page":"API","title":"Metida.SpatialExponentialD","text":"SpatialExponentialD()\n\nwarning: Warning\nExperimental\n\nSame as SpatialExponential, but add D to all diagonal elements.\n\nSPEXPD = SpatialExponentialD()\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.SpatialGaussianD","page":"API","title":"Metida.SpatialGaussianD","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.SpatialGaussianD","category":"page"},{"location":"api/#Metida.SpatialGaussianD","page":"API","title":"Metida.SpatialGaussianD","text":"SpatialGaussianD()\n\nwarning: Warning\nExperimental\n\nSame as SpatialGaussianD, but add D to all diagonal elements.\n\nSPGAUD = SpatialGaussianD()\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.SpatialPowerD","page":"API","title":"Metida.SpatialPowerD","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.SpatialPowerD","category":"page"},{"location":"api/#Metida.SpatialPowerD","page":"API","title":"Metida.SpatialPowerD","text":"SpatialPowerD()\n\nwarning: Warning\nExperimental\n\nSame as SpatialPower, but add D to all diagonal elements.\n\nSPPOWD = SpatialPowerD()\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.ScaledWeightedCov","page":"API","title":"Metida.ScaledWeightedCov","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.ScaledWeightedCov","category":"page"},{"location":"api/#Metida.ScaledWeightedCov","page":"API","title":"Metida.ScaledWeightedCov","text":"ScaledWeightedCov(wtsm::AbstractMatrix{T})\n\nwarning: Warning\nExperimental\n\nScaled weighted covariance matrix, where wtsm - NxN within block correlation matrix (N - total number of observations). Used only for repeated effect. \n\nSWC = ScaledWeightedCov\n\nR = Corr(W) * sigma_c^2\n\nwhere Corr(W) - diagonal correlation matrix. \n\nexample:\n\nmatwts = Symmetric(UnitUpperTriangular(rand(size(df0,1), size(df0,1))))\nlmm = LMM(@formula(var~sequence+period+formulation), df0;\n repeated = VarEffect(@covstr(1|subject), SWC(matwts)))\nfit!(lmm)\n\n\nnote: Note\n\n\nThere is no wtsm checks for symmetricity or values.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.dof_contain","page":"API","title":"Metida.dof_contain","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.dof_contain","category":"page"},{"location":"api/#Metida.dof_contain","page":"API","title":"Metida.dof_contain","text":"dof_contain(lmm, i)\n\nwarning: Warning\nExperimental! 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.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.typeiii","page":"API","title":"Metida.typeiii","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.typeiii","category":"page"},{"location":"api/#Metida.typeiii","page":"API","title":"Metida.typeiii","text":"typeiii(lmm::LMM{T}; ddf::Symbol = :satter) where T\n\nwarning: Warning\nExperimental\n\nType III table.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.MILMM","page":"API","title":"Metida.MILMM","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.MILMM","category":"page"},{"location":"api/#Metida.MILMM","page":"API","title":"Metida.MILMM","text":"MILMM(lmm::LMM, data)\n\nMultiple imputation model.\n\n\n\n\n\n","category":"type"},{"location":"api/#Metida.RawCoding","page":"API","title":"Metida.RawCoding","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.RawCoding","category":"page"},{"location":"api/#Metida.RawCoding","page":"API","title":"Metida.RawCoding","text":"mutable struct RawCoding <: AbstractContrasts\n\nContrast for CategoricalTerm to get column \"as it is\" for model matrix.\n\n\n\n\n\n","category":"type"},{"location":"api/#Not-API-functions","page":"API","title":"Not API functions","text":"","category":"section"},{"location":"api/#Metida.contrast","page":"API","title":"Metida.contrast","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.contrast","category":"page"},{"location":"api/#Metida.contrast","page":"API","title":"Metida.contrast","text":"contrast(lmm, l::AbstractMatrix; name::String = \"Contrast\", ddf = :satter)\n\nUser contrast table. ddf = :satter or :residual or any number for direct ddf setting.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.fvalue","page":"API","title":"Metida.fvalue","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.fvalue","category":"page"},{"location":"api/#Metida.fvalue","page":"API","title":"Metida.fvalue","text":"fvalue(lmm::LMM, l::Matrix)\n\nF value for contrast matrix l.\n\nF = fracbetaL(LCL)^-1Lbetarank(LCL)\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.mulαβαtinc","page":"API","title":"Metida.mulαβαtinc","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.mulαβαtinc!","category":"page"},{"location":"api/#Metida.mulαβαtinc!","page":"API","title":"Metida.mulαβαtinc!","text":"mulαβαtinc!(θ::AbstractMatrix, A::AbstractMatrix, B::AbstractMatrix)\n\nθ + A * B * A'\n\nChange θ (only upper triangle). B is symmetric.\n\n\n\n\n\nmulαβαtinc!(θ::AbstractMatrix, A::AbstractMatrix, B::AbstractMatrix, alpha)\n\nθ + A * B * A' * alpha\n\nChange θ (only upper triangle). B is symmetric.\n\n\n\n\n\nmulαβαtinc!(θ::AbstractVector{T}, A::AbstractMatrix, B::AbstractMatrix, a::AbstractVector, b::AbstractVector, alpha) where T\n\nθ + A * B * (a - b) * alpha\n\nChange θ (only upper triangle). B is symmetric.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.mulθ","page":"API","title":"Metida.mulθ₃","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.mulθ₃","category":"page"},{"location":"api/#Metida.mulθ₃","page":"API","title":"Metida.mulθ₃","text":"mulθ₃(y, X, β, V::AbstractMatrix{T})::T where T\n\n(y - X * β)' * (-V) * (y - X * β)\n\nuse only upper triangle of V\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.mulαtβinc","page":"API","title":"Metida.mulαtβinc","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.mulαtβinc!","category":"page"},{"location":"api/#Metida.mulαtβinc!","page":"API","title":"Metida.mulαtβinc!","text":"mulαtβinc!(θ::AbstractVector{T}, A::AbstractMatrix, b::AbstractVector) where T\n\nθ + A' * b\n\nChange θ.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.tname","page":"API","title":"Metida.tname","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.tname ","category":"page"},{"location":"api/#Metida.tname","page":"API","title":"Metida.tname","text":"Term name.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.raneflenv","page":"API","title":"Metida.raneflenv","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.raneflenv ","category":"page"},{"location":"api/#Metida.raneflenv","page":"API","title":"Metida.raneflenv","text":"Return number of subject foe each random effet in current block.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.edistance","page":"API","title":"Metida.edistance","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.edistance ","category":"page"},{"location":"api/#Metida.edistance","page":"API","title":"Metida.edistance","text":"edistance(mx::AbstractMatrix{T}, i::Int, j::Int) where T\n\nDistance between vector mx[i, :] and mx[j, :].\n\n\n\n\n\n","category":"function"},{"location":"custom/#Custom-structures","page":"Custom structures","title":"Custom structures","text":"","category":"section"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"To make your own covariance structure first you should make struct that <: AbstractCovarianceType:","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"Example:","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"struct YourCovarianceStruct <: AbstractCovarianceType end","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"You also can specify additional field if you need to use them inside gmat!/rmat! functions.","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"Then you can make function for construction random effect matrix (gmat!) and repeated effect (rmat!). Only upper triangular can be updated.","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"Function gmat! have 3 arguments: mx - zero matrix, θ - theta vector for this effect, and your custom structure object.","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"Next this function used to make \"random\" part of variance-covariance matrix: V' = Z * G * Z'","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"function Metida.gmat!(mx, θ, ::YourCovarianceStruct)\n @inbounds @simd for i = 1:size(mx, 1)\n mx[i, i] = θ[i] ^ 2\n end\n nothing\nend","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"Function rmat! have 5 arguments and add repeated effect to V': V = V' + R (so V = Z * G * Z' + R), mx - V' matrix, θ - theta vector for this effect, rz - subject effect matrix, ct - your covariance type object, sb = block number. For example, rmat! for Heterogeneous Toeplitz Parameterized structure is specified bellow (TOEPHP_ <: AbstractCovarianceType).","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"function Metida.rmat!(mx, θ, rz, ct::TOEPHP_, ::Int)\n l = size(rz, 2)\n vec = rz * (θ[1:l])\n s = size(mx, 1)\n if s > 1 && ct.p > 1\n for m = 1:s - 1\n for n = m + 1:(m + ct.p - 1 > s ? s : m + ct.p - 1)\n @inbounds mx[m, n] += vec[m] * vec[n] * θ[n - m + l]\n end\n end\n end\n @inbounds @simd for m = 1:s\n mx[m, m] += vec[m] * vec[m]\n end\n nothing\nend","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"One more function you shoud make is covstrparam, this function need to know how many parameters included in theta vector for optimization. Function returns number of variance parameters and rho parameters for this structure. Where t - number of columns in individual Z matrix for random effect or number of columns in repeated effect matrix (rZ).","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"Example for Heterogeneous Autoregressive and Heterogeneous Compound Symmetry structures:","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"function Metida.covstrparam(ct::Union{ARH_, CSH_}, t::Int)::Tuple{Int, Int}\n return (t, 1)\nend","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"For better printing you can add:","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"function Metida.rcoefnames(s, t, ct::YourCovarianceStruct)\n return [\"σ² \", \"γ \", \"ρ \"]\nend","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"Where, s - effect schema, t - number of parameters, this function returns names for your covariance structure for printing in LMM output.","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"Add this method for better printing:","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"function Base.show(io::IO, ct::YourCovarianceStruct)\n print(io, \"YourCovarianceStruct\")\nend","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"Then just make model and fit it:","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"lmm = Metida.LMM(@formula(response ~ 1 + factor*time), ftdf2;\n random = Metida.VarEffect(Metida.@covstr(factor|subject&factor), YourCovarianceStruct()),\n repeated = Metida.VarEffect(Metida.@covstr(1|subject&factor), YourCovarianceStruct()),\n )\n Metida.fit!(lmm)","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"Example:","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"using Metida, DataFrames, CSV, CategoricalArrays\n\nspatdf = CSV.File(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"csv\", \"spatialdata.csv\"); types = [Int, Int, String, Float64, Float64, Float64, Float64, Float64]) |> DataFrame\nftdf = CSV.File(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"csv\", \"1fptime.csv\"); types = [String, String, Float64, Float64]) |> DataFrame\ndf0 = CSV.File(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"csv\", \"df0.csv\"); types = [String, String, String, String,Float64, Float64, Float64]) |> DataFrame\n\nstruct CustomCovarianceStructure <: Metida.AbstractCovarianceType end\nfunction Metida.covstrparam(ct::CustomCovarianceStructure, t::Int)::Tuple{Int, Int}\n return (t, 1)\nend\nfunction Metida.gmat!(mx, θ, ct::CustomCovarianceStructure)\n s = size(mx, 1)\n @inbounds @simd for m = 1:s\n mx[m, m] = θ[m]\n end\n if s > 1\n for m = 1:s - 1\n @inbounds @simd for n = m + 1:s\n mx[m, n] = mx[m, m] * mx[n, n] * θ[end]\n end\n end\n end\n @inbounds @simd for m = 1:s\n mx[m, m] = mx[m, m] * mx[m, m]\n end\n nothing\nend\n\nlmm = Metida.LMM(@formula(response ~1 + factor*time), ftdf;\nrandom = Metida.VarEffect(Metida.@covstr(1 + time|subject&factor), CustomCovarianceStructure()),\n)\nMetida.fit!(lmm)\n\n# for R matrix\n\nfunction Metida.rmat!(mx, θ, rz, ::CustomCovarianceStructure, ::Int)\n vec = Metida.tmul_unsafe(rz, θ)\n rn = size(mx, 1)\n if rn > 1\n for m = 1:rn - 1\n @inbounds @simd for n = m + 1:rn\n mx[m, n] += vec[m] * vec[n] * θ[end]\n end\n end\n end\n @inbounds for m ∈ axes(mx, 1)\n mx[m, m] += vec[m] * vec[m]\n end\n nothing\nend\n\nlmm = Metida.LMM(@formula(var~sequence+period+formulation), df0;\nrepeated = Metida.VarEffect(Metida.@covstr(period|subject), CustomCovarianceStructure()),\n)\nMetida.fit!(lmm)","category":"page"},{"location":"custom/#Custom-distance-estimation-for-spatial-structures","page":"Custom structures","title":"Custom distance estimation for spatial structures","text":"","category":"section"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"If you want to use coordinates or some other structures for distance estimation you can define method Metida.edistance to calculate distance:","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"function Metida.edistance(mx::AbstractMatrix{<:CartesianIndex}, i::Int, j::Int)\n return sqrt((mx[i, 1][1] - mx[j, 1][1])^2 + (mx[i, 1][2] - mx[j, 1][2])^2)\nend","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"For example this method returns distance between two vectors represented as CartesianIndex.","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"Make vector of CartesianIndex:","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"spatdf.ci = map(x -> CartesianIndex(x[:x], x[:y]), eachrow(spatdf))","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"Then use new column as \"raw\" variable with Metida.RawCoding contrast and fit the model:","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"lmm = Metida.LMM(@formula(r2 ~ f), spatdf;\n repeated = Metida.VarEffect(Metida.@covstr(ci|1), Metida.SPEXP; coding = Dict(:ci => Metida.RawCoding())),\n )\nMetida.fit!(lmm)","category":"page"},{"location":"examples/#Example-1-Continuous-and-categorical-predictors","page":"Examples","title":"Example 1 - Continuous and categorical predictors","text":"","category":"section"},{"location":"examples/","page":"Examples","title":"Examples","text":"using Metida, CSV, DataFrames, CategoricalArrays, MixedModels;\n\nrds = CSV.File(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"csv\", \"1fptime.csv\"); types = [String, String, Float64, Float64]) |> DataFrame\n\nnothing; # hide","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"(Image: )","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"Metida result:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"lmm = LMM(@formula(response ~1 + factor*time), rds;\nrandom = VarEffect(@covstr(1 + time|subject&factor), CSH),\n)\nfit!(lmm)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"MixedModels result:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"fm = @formula(response ~ 1 + factor*time + (1 + time|subject&factor))\nmm = fit(MixedModel, fm, rds, REML=true)\nprintln(mm) #hide","category":"page"},{"location":"examples/#Example-2-Two-random-factors-(Penicillin-data)","page":"Examples","title":"Example 2 - Two random factors (Penicillin data)","text":"","category":"section"},{"location":"examples/","page":"Examples","title":"Examples","text":"Metida:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"\ndf = CSV.File(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"csv\", \"Penicillin.csv\"); types = [String, Float64, String, String]) |> DataFrame\ndf.diameter = float.(df.diameter)\n\nlmm = LMM(@formula(diameter ~ 1), df;\nrandom = [VarEffect(@covstr(1|plate), SI), VarEffect(@covstr(1|sample), SI)]\n)\nfit!(lmm)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"MixedModels:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"\nfm2 = @formula(diameter ~ 1 + (1|plate) + (1|sample))\nmm = fit(MixedModel, fm2, df, REML=true)\nprintln(mm) #hide","category":"page"},{"location":"examples/#Example-3-Repeated-ARMA/AR/ARH","page":"Examples","title":"Example 3 - Repeated ARMA/AR/ARH","text":"","category":"section"},{"location":"examples/","page":"Examples","title":"Examples","text":"rds = CSV.File(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"csv\", \"1freparma.csv\"); types = [String, String, Float64, Float64]) |> DataFrame\n\nnothing # hide","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"(Image: )","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"ARMA:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"lmm = LMM(@formula(response ~ 1 + factor*time), rds;\nrandom = VarEffect(@covstr(factor|subject&factor), DIAG),\nrepeated = VarEffect(@covstr(1|subject&factor), ARMA),\n)\nfit!(lmm)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"AR:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"lmm = Metida.LMM(@formula(response ~ 1 + factor*time), rds;\nrandom = VarEffect(@covstr(factor|subject&factor), DIAG),\nrepeated = VarEffect(@covstr(1|subject&factor), AR),\n)\nfit!(lmm)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"ARH:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"lmm = Metida.LMM(@formula(response ~ 1 + factor*time), rds;\nrandom = VarEffect(@covstr(factor|subject&factor), DIAG),\nrepeated = VarEffect(@covstr(1|subject&factor), ARH),\n)\nfit!(lmm)","category":"page"},{"location":"examples/#Example-4-SAS-relation","page":"Examples","title":"Example 4 - SAS relation","text":"","category":"section"},{"location":"examples/#Model-1","page":"Examples","title":"Model 1","text":"","category":"section"},{"location":"examples/","page":"Examples","title":"Examples","text":"df0 = CSV.File(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"csv\", \"df0.csv\")) |> DataFrame\n\nlmm = LMM(@formula(var ~ sequence + period + formulation), df0;\nrandom = VarEffect(@covstr(formulation|subject), CSH),\nrepeated = VarEffect(@covstr(formulation|subject), DIAG),\n)\nfit!(lmm)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"SAS code:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"PROC MIXED data=df0;\nCLASSES subject sequence period formulation;\nMODEL var = sequence period formulation/ DDFM=SATTERTH s;\nRANDOM formulation/TYPE=CSH SUB=subject G V;\nREPEATED/GRP=formulation SUB=subject R;\nRUN;","category":"page"},{"location":"examples/#Model-2","page":"Examples","title":"Model 2","text":"","category":"section"},{"location":"examples/","page":"Examples","title":"Examples","text":"lmm = LMM(\n @formula(var ~ sequence + period + formulation), df0;\n random = VarEffect(@covstr(formulation|subject), SI),\n repeated = VarEffect(@covstr(formulation|subject), DIAG),\n)\nfit!(lmm)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"SAS code:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"PROC MIXED data=df0;\nCLASSES subject sequence period formulation;\nMODEL var = sequence period formulation/ DDFM=SATTERTH s;\nRANDOM formulation/TYPE=VC SUB=subject G V;\nREPEATED/GRP=formulation SUB=subject R;\nRUN;","category":"page"},{"location":"examples/#Model-3","page":"Examples","title":"Model 3","text":"","category":"section"},{"location":"examples/","page":"Examples","title":"Examples","text":"lmm = LMM(@formula(var ~ sequence + period + formulation), df0;\n random = VarEffect(@covstr(subject|1), SI)\n )\nfit!(lmm)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"SAS code:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"PROC MIXED data=df0;\nCLASSES subject sequence period formulation;\nMODEL var = sequence period formulation/ DDFM=SATTERTH s;\nRANDOM subject/TYPE=VC G V;\nRUN;","category":"page"},{"location":"examples/#Example-5-Working-with-Effects.jl","page":"Examples","title":"Example 5 - Working with Effects.jl","text":"","category":"section"},{"location":"examples/","page":"Examples","title":"Examples","text":"using Effects, StatsModels\n\nlmm = LMM(@formula(var ~ sequence + period + formulation), df0;\n random = VarEffect(@covstr(subject|1), SI)\n )\nfit!(lmm)\n\ntable_model = StatsModels.TableRegressionModel(lmm, lmm.mf, lmm.mm)\n\nemmeans(tm)\n\neffects(Dict(:period => [\"1\", \"2\", \"3\", \"4\"]), tm)","category":"page"},{"location":"validation/#Validation","page":"Validation","title":"Validation","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"Validation provided with 3 sections:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"REML validation for public datasets with Metida & SPSS\nParameters validation for public datasets Metida & SPSS & MixedModels\nValidation with bioequivalence datasets with Metida & SPSS","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"To run validation:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"using Metida; include(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"validation.jl\"))","category":"page"},{"location":"validation/#Section-1:-REML-validation-for-public-datasets-Metida-and-SPSS","page":"Validation","title":"Section 1: REML validation for public datasets Metida & SPSS","text":"","category":"section"},{"location":"validation/#REML-result-table","page":"Validation","title":"REML result table","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"Model DataSet Used cov. types REML Metida REML SPSS\n1 sleepstudy.csv SI/SI 1729.4925602367025 1729.492560\n2 sleepstudy.csv CS/SI 1904.3265170722132 1904.327\n3 sleepstudy.csv CSH/SI 1772.0953251997046 1772.095\n4 sleepstudy.csv ARH/SI 1730.1895427398322 1730.189543\n5 Pastes.csv SI,SI/SI 246.99074585348623 246.990746\n6 Pastes.csv ARMA/SI 246.81895071012508 246.818951\n7 Penicillin.csv SI,SI/SI 330.86058899109184 330.860589\n8 RepeatedPulse.csv SI/AR 453.3395435627574 453.339544\n9 RepeatedPulse.csv 0/AR 471.85107712169827 471.851077\n10 RepeatedPulse.csv AR/SI 453.3395560121246 453.339555","category":"page"},{"location":"validation/#sleepstudy.csv","page":"Validation","title":"sleepstudy.csv","text":"","category":"section"},{"location":"validation/#Model-1","page":"Validation","title":"Model 1","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"lmm = LMM(@formula(Reaction~Days), df;\n random = VarEffect(@covstr(1|Subject), SI),\n )\n fit!(lmm)","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"SPSS:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"MIXED Reaction BY Days\n /CRITERIA=DFMETHOD(SATTERTHWAITE) CIN(95) MXITER(100) MXSTEP(10) SCORING(1)\n SINGULAR(0.000000000001) HCONVERGE(0, ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE)\n /FIXED=Days | SSTYPE(3)\n /METHOD=REML\n /RANDOM=INTERCEPT | SUBJECT(Subject) COVTYPE(ID).","category":"page"},{"location":"validation/#Model-2","page":"Validation","title":"Model 2","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"lmm = LMM(@formula(Reaction~1), df;\n random = VarEffect(Metida.@covstr(Days|Subject), CS),\n )\n fit!(lmm)","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"SPSS:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"MIXED Reaction BY Days\n /CRITERIA=DFMETHOD(SATTERTHWAITE) CIN(95) MXITER(100) MXSTEP(10) SCORING(1)\n SINGULAR(0.000000000001) HCONVERGE(0, ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE)\n /FIXED=INTERCEPT | SSTYPE(3)\n /METHOD=REML\n /RANDOM=Days | SUBJECT(Subject) COVTYPE(CS).","category":"page"},{"location":"validation/#Model-3","page":"Validation","title":"Model 3","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"lmm = LMM(@formula(Reaction~1), df;\n random = VarEffect(@covstr(Days|Subject), CSH)\n )\n fit!(lmm)","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"SPSS:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"MIXED Reaction BY Days\n /CRITERIA=DFMETHOD(SATTERTHWAITE) CIN(95) MXITER(100) MXSTEP(10) SCORING(1)\n SINGULAR(0.000000000001) HCONVERGE(0, ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE)\n /FIXED=INTERCEPT | SSTYPE(3)\n /METHOD=REML\n /RANDOM=Days | SUBJECT(Subject) COVTYPE(CSH).","category":"page"},{"location":"validation/#Model-4","page":"Validation","title":"Model 4","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"lmm = LMM(@formula(Reaction~1), df;\n random = VarEffect(@covstr(Days|Subject), ARH)\n )\n fit!(lmm)","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"SPSS:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"MIXED Reaction BY Days\n /CRITERIA=DFMETHOD(SATTERTHWAITE) CIN(95) MXITER(100) MXSTEP(10) SCORING(1)\n SINGULAR(0.000000000001) HCONVERGE(0, ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE)\n /FIXED=INTERCEPT | SSTYPE(3)\n /METHOD=REML\n /RANDOM=Days | SUBJECT(Subject) COVTYPE(ARH1).","category":"page"},{"location":"validation/#pastes.csv","page":"Validation","title":"pastes.csv","text":"","category":"section"},{"location":"validation/#Model-5","page":"Validation","title":"Model 5","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"lmm = LMM(@formula(strength~1), df;\nrandom = [VarEffect(@covstr(1|batch), SI), VarEffect(@covstr(1|batch & cask), SI)]\n)\nfit!(lmm)","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"SPSS:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"MIXED strength\n /CRITERIA=DFMETHOD(SATTERTHWAITE) CIN(95) MXITER(100) MXSTEP(10) SCORING(1)\n SINGULAR(0.000000000001) HCONVERGE(0, ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE)\n /FIXED=| SSTYPE(3)\n /METHOD=REML\n /RANDOM=INTERCEPT | SUBJECT(batch) COVTYPE(ID)\n /RANDOM=INTERCEPT | SUBJECT(cask * batch) COVTYPE(ID).","category":"page"},{"location":"validation/#Model-6","page":"Validation","title":"Model 6","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"lmm = LMM(@formula(strength~1), df;\nrandom = VarEffect(Metida.@covstr(cask|batch), ARMA),\n)\nfit!(lmm)","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"SPSS:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"MIXED strength by cask\n /CRITERIA=DFMETHOD(SATTERTHWAITE) CIN(95) MXITER(100) MXSTEP(10) SCORING(1)\n SINGULAR(0.000000000001) HCONVERGE(0, ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE)\n /FIXED=| SSTYPE(3)\n /METHOD=REML\n /RANDOM=cask | SUBJECT(batch) COVTYPE(ARMA11).","category":"page"},{"location":"validation/#penicillin.csv","page":"Validation","title":"penicillin.csv","text":"","category":"section"},{"location":"validation/#Model-7","page":"Validation","title":"Model 7","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"lmm = LMM(@formula(diameter ~ 1), df;\nrandom = [VarEffect(@covstr(1|plate), SI), VarEffect(@covstr(1|sample), SI)]\n)\nfit!(lmm)","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"SPSS:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"MIXED diameter\n /CRITERIA=DFMETHOD(SATTERTHWAITE) CIN(95) MXITER(100) MXSTEP(10) SCORING(1)\n SINGULAR(0.000000000001) HCONVERGE(0, ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE)\n /FIXED=| SSTYPE(3)\n /METHOD=REML\n /RANDOM=INTERCEPT | SUBJECT(plate) COVTYPE(ID)\n /RANDOM=INTERCEPT | SUBJECT(sample) COVTYPE(ID).","category":"page"},{"location":"validation/#RepeatedPulse.csv","page":"Validation","title":"RepeatedPulse.csv","text":"","category":"section"},{"location":"validation/#Model-8","page":"Validation","title":"Model 8","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"sort!(df, :Day)\nlmm = LMM(@formula(Pulse~1), df;\nrandom = VarEffect(Metida.@covstr(Time|Time), SI),\nrepeated = VarEffect(Metida.@covstr(Day|Time), AR),\n)\nfit!(lmm)","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"SPSS:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"MIXED Pulse BY Day Time\n /CRITERIA=DFMETHOD(SATTERTHWAITE) CIN(95) MXITER(100) MXSTEP(10) SCORING(1)\n SINGULAR(0.000000000001) HCONVERGE(0, ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE)\n /FIXED=| SSTYPE(3)\n /METHOD=REML\n /RANDOM=Time | SUBJECT(Time) COVTYPE(ID)\n /REPEATED = Day | SUBJCET(Time) COVTYPE(AR1).","category":"page"},{"location":"validation/#Model-9","page":"Validation","title":"Model 9","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"sort!(df, :Day)\nlmm = LMM(@formula(Pulse~1), df;\nrepeated = VarEffect(Metida.@covstr(Day|Time), AR),\n)\n fit!(lmm)","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"SPSS:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"MIXED Pulse BY Day Time\n /CRITERIA=DFMETHOD(SATTERTHWAITE) CIN(95) MXITER(100) MXSTEP(10) SCORING(1)\n SINGULAR(0.000000000001) HCONVERGE(0, ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE)\n /FIXED=| SSTYPE(3)\n /METHOD=REML\n /REPEATED = Day | SUBJCET(Time) COVTYPE(AR1).","category":"page"},{"location":"validation/#Model-10","page":"Validation","title":"Model 10","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"sort!(df, :Day)\nlmm = LMM(@formula(Pulse~1), df;\nrandom = VarEffect(Metida.@covstr(Day|Time), AR),\n)\n fit!(lmm)","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"SPSS:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"MIXED Pulse BY Day Time\n /CRITERIA=DFMETHOD(SATTERTHWAITE) CIN(95) MXITER(100) MXSTEP(10) SCORING(1)\n SINGULAR(0.000000000001) HCONVERGE(0, ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE)\n /FIXED=| SSTYPE(3)\n /METHOD=REML\n /RANDOM=Day | SUBJECT(Time) COVTYPE(AR1).","category":"page"},{"location":"validation/#Section-2:-Parameters-validation-for-public-datasets-Metida-and-SPSS-and-MixedModels","page":"Validation","title":"Section 2: Parameters validation for public datasets Metida & SPSS & MixedModels","text":"","category":"section"},{"location":"validation/#Model-7-2","page":"Validation","title":"Model 7","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"Metida:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"lmm = LMM(@formula(diameter ~ 1), df;\nrandom = [VarEffect(@covstr(1|plate), SI), VarEffect(@covstr(1|sample), SI)]\n)\nfit!(lmm)","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"MixedModels:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"fm = @formula(diameter ~ 1 + (1|plate) + (1|sample))\nmm = fit(MixedModel, fm, df, REML=true)","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"SPSS:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"MIXED diameter\n /CRITERIA=DFMETHOD(SATTERTHWAITE) CIN(95) MXITER(100) MXSTEP(10) SCORING(1)\n SINGULAR(0.000000000001) HCONVERGE(0, ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE)\n /FIXED=| SSTYPE(3)\n /METHOD=REML\n /EMMEANS=TABLES(OVERALL)\n /RANDOM=INTERCEPT | SUBJECT(plate) COVTYPE(ID)\n /RANDOM=INTERCEPT | SUBJECT(sample) COVTYPE(ID).","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"Model Parameter Value Metida Value MM Value SPSS\n7 (Intercept) estimate 22.9722 22.9722 22.972\n7 (Intercept) SE 0.808573 0.808572 0.809\n7 plate σ² 0.716908 0.716908 0.716908\n7 sample σ² 3.73092 3.730901 3.730918\n7 Residual σ² 0.302415 0.302416 0.302415","category":"page"},{"location":"validation/#Section-3:-Validation-with-bioequivalence-datasets-with-Metida-and-SPSS","page":"Validation","title":"Section 3: Validation with bioequivalence datasets with Metida & SPSS","text":"","category":"section"},{"location":"validation/#Model-BE-B","page":"Validation","title":"Model BE-B","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"lmm = LMM(@formula(lnpk~sequence+period+treatment), dfrds;\nrandom = VarEffect(Metida.@covstr(1|subject), SI),\n)\nfit!(lmm)","category":"page"},{"location":"validation/#Model-BE-C","page":"Validation","title":"Model BE-C","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"lmm = LMM(@formula(lnpk~sequence+period+treatment), dfrds;\n random = VarEffect(Metida.@covstr(treatment|subject), CSH),\n repeated = VarEffect(Metida.@covstr(treatment|subject), DIAG),\n )\n fit!(lmm)","category":"page"},{"location":"validation/#Typical-SPSS-code","page":"Validation","title":"Typical SPSS code","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"MIXED lnpk BY period sequence treatment subject\n /CRITERIA=DFMETHOD(SATTERTHWAITE) CIN(95) MXITER(100) MXSTEP(10) SCORING(1)\n SINGULAR(0.000000000001) HCONVERGE(0, ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE)\n /FIXED=period sequence treatment | SSTYPE(3)\n /METHOD=REML\n /RANDOM= subject(sequence) | COVTYPE(ID)\n /EMMEANS=TABLES(treatment) COMPARE REFCAT(FIRST) ADJ(LSD).\n\nMIXED lnpk BY period treatment sequence subject\n /CRITERIA=CIN(90) MXITER(200) MXSTEP(20) SCORING(2) SINGULAR(0.000000000001) HCONVERGE(0,\n RELATIVE) LCONVERGE(0.0000000000001, RELATIVE) PCONVERGE(0, RELATIVE)\n /FIXED=period treatment sequence | SSTYPE(3)\n /METHOD=REML\n /RANDOM=treatment | SUBJECT(subject) COVTYPE(CSH)\n /REPEATED=treatment | SUBJECT(subject*period) COVTYPE(DIAG)\n /EMMEANS=TABLES(treatment) COMPARE REFCAT(FIRST) ADJ(LSD).","category":"page"},{"location":"validation/#Results","page":"Validation","title":"Results","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"using Metida; # hide\ninclude(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"validation_init.jl\")); # hide\ninclude(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"validation_s3.jl\"))","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"Full SPSS code provided in validation folder (here).","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"SPSS output in DOCX format.","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"Validation dataset available here, 122482020427MOESM2ESM.xls.","category":"page"},{"location":"validation/#Validation-report","page":"Validation","title":"Validation report","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"Validation and report can be done on local machine with Weave.jl and Pandoc.","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"using Weave, Metida\nweave(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"validation_report.jmd\");\ndoctype = \"pandoc2pdf\",\nout_path = :pwd,\npandoc_options=[\"--toc\", \"-V colorlinks=true\" , \"-V linkcolor=blue\", \"-V urlcolor=red\", \"-V toccolor=gray\"])","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"Report will be saved in Julia working directory. For your own purpose you can edit validation_report.jmd template.","category":"page"},{"location":"ref/#Citation-and-Reference","page":"Citation & Reference","title":"Citation & Reference","text":"","category":"section"},{"location":"ref/#Sweep-algorithm","page":"Citation & Reference","title":"Sweep algorithm","text":"","category":"section"},{"location":"ref/","page":"Citation & Reference","title":"Citation & Reference","text":"Sweep based on SweepOperator.jl. Thanks to @joshday and @Hua-Zhou.\nhttp://hua-zhou.github.io/teaching/biostatm280-2019spring/slides/12-sweep/sweep.html","category":"page"},{"location":"ref/","page":"Citation & Reference","title":"Citation & Reference","text":"More:","category":"page"},{"location":"ref/","page":"Citation & Reference","title":"Citation & Reference","text":"Section 7.4-7.6 of Numerical Analysis for Statisticians by Kenneth Lange (2010).\nThe paper A tutorial on the SWEEP operator by James H. Goodnight (1979).","category":"page"},{"location":"ref/#REML-and-Parameter-estimation","page":"Citation & Reference","title":"REML & Parameter estimation","text":"","category":"section"},{"location":"ref/","page":"Citation & Reference","title":"Citation & Reference","text":"Henderson, C. R., et al. “The Estimation of Environmental and Genetic Trends from Records Subject to Culling.” Biometrics, vol. 15, no. 2, 1959, pp. 192–218. JSTOR, www.jstor.org/stable/2527669.\nLaird, Nan M., and James H. Ware. “Random-Effects Models for Longitudinal Data.” Biometrics, vol. 38, no. 4, 1982, pp. 963–974. JSTOR, www.jstor.org/stable/2529876.\nLindstrom & J.; Bates, M. (1988). Newton—Raphson and EM Algorithms for Linear Mixed-Effects Models for Repeated-Measures Data. Journal of the American Statistical Association. 83. 1014. 10.1080/01621459.1988.10478693.\nGurka, Matthew. (2006). Selecting the Best Linear Mixed Model under REML. The American Statistician. 60. 19-26. 10.1198/000313006X90396.\nSang Hong Lee, Julius H.J. van der Werf. An efficient variance component approach implementing an average information REML suitable for combined LD and linkage mapping with a general complex pedigree. Genetics Selection Evolution, BioMed Central, 2006, 38 (1), pp.25-43. ⟨hal-00894558⟩\nF.N. Gumedze, T.T. Dunne, Parameter estimation and inference in the linear mixed model, Linear Algebra and its Applications, Volume 435, Issue 8, 2011, Pages 1920-1944, ISSN 0024-3795, https://doi.org/10.1016/j.laa.2011.04.015. (http://www.sciencedirect.com/science/article/pii/S002437951100320X)","category":"page"},{"location":"ref/#AI-algorithm","page":"Citation & Reference","title":"AI algorithm","text":"","category":"section"},{"location":"ref/","page":"Citation & Reference","title":"Citation & Reference","text":"D.L. Johnson, R. Thompson, Restricted Maximum Likelihood Estimation of Variance Components for Univariate Animal Models Using Sparse Matrix Techniques and Average Information, Journal of Dairy Science, Volume 78, Issue 2, 1995, Pages 449-456, ISSN 0022-0302, https://doi.org/10.3168/jds.S0022-0302(95)76654-1. (http://www.sciencedirect.com/science/article/pii/S0022030295766541)\nMishchenko, Kateryna & Holmgren, Sverker & Rönnegård, Lars. (2007). Newton-type Methods for REML Estimation in Genetic Analysis of Quantitative Traits. Journal of Computational Methods in Science and Engineering. 8. 10.3233/JCM-2008-81-203.\nMatilainen K, Mäntysaari EA, Lidauer MH, Strandén I, Thompson R. Employing a Monte Carlo algorithm in Newton-type methods for restricted maximum likelihood estimation of genetic parameters. PLoS One. 2013;8(12):e80821. Published 2013 Dec 10. doi:10.1371/journal.pone.0080821","category":"page"},{"location":"ref/#Covariance-structures","page":"Citation & Reference","title":"Covariance structures","text":"","category":"section"},{"location":"ref/","page":"Citation & Reference","title":"Citation & Reference","text":"Wolfinger, Russ. (1993). Covariance structure selection in general mixed models. Communications in Statistics-simulation and Computation - COMMUN STATIST-SIMULAT COMPUT. 22. 1079-1106. 10.1080/03610919308813143.\nWolfinger, Russ. (1996). Heterogeneous Variance: Covariance Structures for Repeated Measures. Journal of Agricultural, Biological, and Environmental Statistics. 1. 205. 10.2307/1400366. \nLittell, Ramon & Pendergast, Jane & Natarajan, Ranjini. (2000). Modelling covariance structure in the analysis of repeated measures data. Statistics in Medicine. 19. 1793-1819. 10.1002/1097-0258(20000715)19:13%3C1793::AID-SIM482%3E3.0.CO;2-Q.\nQUINTAL, SILVANA SILVA RED, VIANA, ALEXANDRE PIO, CAMPOS, BIANCA MACHADO, VIVAS, MARCELO, & AMARAL JÚNIOR, ANTONIO TEIXEIRA DO. (2017). ANALYSIS OF STRUCTURES OF COVARIANCE AND REPEATABILITY IN GUAVA SEGREGANTING POPULATION. Revista Caatinga, 30(4), 885-891. https://doi.org/10.1590/1983-21252017v30n408rc\nMcNeish, D., Harring, J. Covariance pattern mixture models: Eliminating random effects to improve convergence and performance. Behav Res 52, 947–979 (2020). https://doi.org/10.3758/s13428-019-01292-4","category":"page"},{"location":"ref/#And-more","page":"Citation & Reference","title":"And more","text":"","category":"section"},{"location":"ref/","page":"Citation & Reference","title":"Citation & Reference","text":"Giesbrecht, F. G., and Burns, J. C. (1985), \"Two-Stage Analysis Based on a Mixed Model: Large-sample Asymptotic Theory and Small-Sample Simulation Results,\" Biometrics, 41, 853-862.\nJennrich, R., & Schluchter, M. (1986). Unbalanced Repeated-Measures Models with Structured Covariance Matrices. Biometrics, 42(4), 805-820. doi:10.2307/2530695\nFletcher, Roger (1987), Practical methods of optimization (2nd ed.), New York: John Wiley & Sons, ISBN 978-0-471-91547-8\nWolfinger et al., (1994) Computing gaussian likelihoods and their derivatives for general linear mixed models doi: 10.1137/0915079\nHrong-Tai Fai & Cornelius (1996) Approximate F-tests of multiple degree of freedom hypotheses in generalized least squares analyses of unbalanced split-plot experiments, Journal of Statistical Computation and Simulation, 54:4, 363-378, DOI: 10.1080/00949659608811740\nSchaalje GB, McBride JB, Fellingham GW. Adequacy of approximations to distributions of test statistics in complex mixed linear models. J Agric Biol Environ Stat. 2002;7:512–24.\nWright, Stephen, and Jorge Nocedal (2006) \"Numerical optimization.\" Springer\nVan Peer, A. (2010), Variability and Impact on Design of Bioequivalence Studies. Basic & Clinical Pharmacology & Toxicology, 106: 146-153. doi:10.1111/j.1742-7843.2009.00485.x","category":"page"},{"location":"ref/#Julia-packages","page":"Citation & Reference","title":"Julia packages","text":"","category":"section"},{"location":"ref/","page":"Citation & Reference","title":"Citation & Reference","text":"Revels, Jarrett & Lubin, Miles & Papamarkou, Theodore. (2016). Forward-Mode Automatic Differentiation in Julia.\nMogensen et al., (2018). Optim: A mathematical optimization package for Julia. Journal of Open Source Software, 3(24), 615,doi: 10.21105/joss.00615","category":"page"},{"location":"ref/#CuSolver-and-CuBLAS","page":"Citation & Reference","title":"CuSolver & CuBLAS","text":"","category":"section"},{"location":"ref/","page":"Citation & Reference","title":"Citation & Reference","text":"https://docs.nvidia.com/cuda/cusolver/index.html\nhttps://docs.nvidia.com/cuda/cublas/index.htm","category":"page"},{"location":"ref/#Reference-dataset","page":"Citation & Reference","title":"Reference dataset","text":"","category":"section"},{"location":"ref/","page":"Citation & Reference","title":"Citation & Reference","text":"Bioequivalence reference datasets: Schütz, H., Labes, D., Tomashevskiy, M. et al. Reference Datasets for Studies in a Replicate Design Intended for Average Bioequivalence with Expanding Limits. AAPS J 22, 44 (2020). https://doi.org/10.1208/s12248-020-0427-6\nsleepstudy.csv: Gregory Belenky, Nancy J. Wesensten, David R. Thorne, Maria L. Thomas, Helen C. Sing, Daniel P. Redmond, Michael B. Russo and Thomas J. Balkin (2003) Patterns of performance degradation and restoration during sleep restriction and subsequent recovery: a sleep dose-response study. Journal of Sleep Research 12, 1–12.\nPenicillin.csv: O.L. Davies and P.L. Goldsmith (eds), Statistical Methods in Research and Production, 4th ed., Oliver and Boyd, (1972), section 6.6\nPastes.csv: O.L. Davies and P.L. Goldsmith (eds), Statistical Methods in Research and Production, 4th ed., Oliver and Boyd, (1972), section 6.5\nChickWeight.csv:\nCrowder, M. and Hand, D. (1990), Analysis of Repeated Measures, Chapman and Hall (example 5.3)\nHand, D. and Crowder, M. (1996), Practical Longitudinal Data Analysis, Chapman and Hall (table A.2)\nPinheiro, J. C. and Bates, D. M. (2000) Mixed-effects Models in S and S-PLUS, Springer.\nRepeatedPulse.csv: Data supplied by a student at Oberlin College.","category":"page"},{"location":"ref/","page":"Citation & Reference","title":"Citation & Reference","text":"See also: https://vincentarelbundock.github.io/Rdatasets/datasets.html","category":"page"},{"location":"bench/#Benchmark","page":"Benchmark","title":"Benchmark","text":"","category":"section"},{"location":"bench/#System","page":"Benchmark","title":"System","text":"","category":"section"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"CPU: Ryzen 5950x\nRAM: 64Gb 3200\nGTX 1070Ti","category":"page"},{"location":"bench/#Data","page":"Benchmark","title":"Data","text":"","category":"section"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"using Metida, CSV, DataFrames, MixedModels, BenchmarkTools;\n\nrds = CSV.File(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"csv\", \"1fptime.csv\"); types = [String, String, Float64, Float64]) |> DataFrame","category":"page"},{"location":"bench/#MixedModels","page":"Benchmark","title":"MixedModels","text":"","category":"section"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"fm = @formula(response ~ 1 + factor*time + (1 + time|subject&factor))\n@benchmark mm = fit($MixedModel, $fm, $rds, REML=true) seconds = 15","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"BenchmarkTools.Trial: 10000 samples with 1 evaluation.\n Range (min … max): 1.140 ms … 10.909 ms ┊ GC (min … max): 0.00% … 86.12%\n Time (median): 1.175 ms ┊ GC (median): 0.00%\n Time (mean ± σ): 1.215 ms ± 563.839 μs ┊ GC (mean ± σ): 2.78% ± 5.31%\n\n ▄██▆▃▁ \n ▁▁▁▂▂▃▅▇██████▇▅▄▃▃▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▂\n 1.14 ms Histogram: frequency by time 1.33 ms <\n\n Memory estimate: 409.52 KiB, allocs estimate: 6130.","category":"page"},{"location":"bench/#Metida","page":"Benchmark","title":"Metida","text":"","category":"section"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"lmm = LMM(@formula(response ~1 + factor*time), rds;\nrandom = VarEffect(@covstr(1 + time|subject&factor), CSH),\n)\n@benchmark fit!($lmm, hes = false) seconds = 15","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"Metida v0.12.0","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"BenchmarkTools.Trial: 1316 samples with 1 evaluation.\n Range (min … max): 5.394 ms … 186.301 ms ┊ GC (min … max): 0.00% … 95.48%\n Time (median): 7.648 ms ┊ GC (median): 0.00%\n Time (mean ± σ): 11.391 ms ± 19.135 ms ┊ GC (mean ± σ): 32.70% ± 17.73%\n\n ██▆\n ███▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▄▁▆▅▄▄▅▄▅▄▄▆▄▆▄▄▄ █\n 5.39 ms Histogram: log(frequency) by time 112 ms <\n\n Memory estimate: 22.63 MiB, allocs estimate: 37224.","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"MetidaNLopt v0.4.0 (Metida 0.12.0)","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"@benchmark fit!($lmm, solver = :nlopt, hes = false, f_tol=1e-8, x_tol=1e-8) seconds = 15","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"BenchmarkTools.Trial: 274 samples with 1 evaluation.\n Range (min … max): 47.312 ms … 153.284 ms ┊ GC (min … max): 0.00% … 67.58%\n Time (median): 49.064 ms ┊ GC (median): 0.00%\n Time (mean ± σ): 54.854 ms ± 19.559 ms ┊ GC (mean ± σ): 10.55% ± 15.98%\n\n ▅█ \n ███▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▆▅▁▁▄▁▁▄▁▄▁▁▄▄▅▁▁▁▁▁▁▁▁▁▁▁▄▁▄▄▁▅▄▁▅▄▄ ▅\n 47.3 ms Histogram: log(frequency) by time 135 ms <\n\n Memory estimate: 35.45 MiB, allocs estimate: 301141.","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"MetidaCu v0.4.0 (Metida 0.4)","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"@benchmark fit!($lmm, solver = :cuda, hes = false, f_tol=1e-8, x_tol=1e-8) seconds = 15","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"BenchmarkTools.Trial: 42 samples with 1 evaluation.\n Range (min … max): 347.642 ms … 461.104 ms ┊ GC (min … max): 0.00% … 4.12%\n Time (median): 350.603 ms ┊ GC (median): 0.00%\n Time (mean ± σ): 358.874 ms ± 23.939 ms ┊ GC (mean ± σ): 0.27% ± 0.98%\n\n ▁█ \n ███▁▃▁▁▁▁▁▁▁▁▅▄▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▃▁▁▃ ▁\n 348 ms Histogram: frequency by time 461 ms <\n\n Memory estimate: 6.86 MiB, allocs estimate: 115020.","category":"page"},{"location":"bench/#Cancer-data:","page":"Benchmark","title":"Cancer data:","text":"","category":"section"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"File: hdp.csv , 8525 observations.","category":"page"},{"location":"bench/#Model-1:-maximum-377-observation-per-subject-(35-subjects)","page":"Benchmark","title":"Model 1: maximum 377 observation-per-subject (35 subjects)","text":"","category":"section"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"lmm = Metida.LMM(@formula(tumorsize ~ 1 + CancerStage), hdp;\nrandom = Metida.VarEffect(Metida.@covstr(1|HID), Metida.DIAG),\n)","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"Metida v0.12.0","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"@benchmark Metida.fit!(lmm, hes = false)","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"BenchmarkTools.Trial: 1 sample with 1 evaluation.\n Single result which took 6.519 s (1.38% GC) to evaluate,\n with a memory estimate of 2.33 GiB, over 41654 allocations.","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"MetidaNLopt v0.4.0 (Metida v0.12.0)","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"@benchmark fit!($lmm, solver = :nlopt, hes = false, f_tol=1e-8, x_tol=1e-8) seconds = 15","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"BenchmarkTools.Trial: 25 samples with 1 evaluation.\n Range (min … max): 555.136 ms … 700.605 ms ┊ GC (min … max): 0.00% … 16.09%\n Time (median): 605.713 ms ┊ GC (median): 7.98%\n Time (mean ± σ): 608.768 ms ± 27.220 ms ┊ GC (mean ± σ): 7.62% ± 3.82%\n\n █ ▂\n ▅▁▁▅▁▁▁▁▁▅▁▁▁▁▁▅▁▅█▅▅▅▅█▅▁▁▅▅▁▅█▁▁▅▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▅ ▁\n 555 ms Histogram: frequency by time 701 ms <\n\n Memory estimate: 921.54 MiB, allocs estimate: 62203.","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"MetidaCu v0.4.0 (Metida 0.12.0)","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"@benchmark fit!($lmm, solver = :cuda, hes = false, f_tol=1e-8, x_tol=1e-8) seconds = 15","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"BenchmarkTools.Trial: 5 samples with 1 evaluation.\n Range (min … max): 3.482 s … 3.650 s ┊ GC (min … max): 0.00% … 2.73%\n Time (median): 3.496 s ┊ GC (median): 0.00%\n Time (mean ± σ): 3.547 s ± 77.924 ms ┊ GC (mean ± σ): 1.07% ± 1.43%\n\n ▁ █ ▁ ▁\n █▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁█ ▁\n 3.48 s Histogram: frequency by time 3.65 s <\n\n Memory estimate: 913.96 MiB, allocs estimate: 410438.","category":"page"},{"location":"bench/#Model-2:-maximum-875-observation-per-subject-(20-subjects)","page":"Benchmark","title":"Model 2: maximum 875 observation-per-subject (20 subjects)","text":"","category":"section"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"lmm = Metida.LMM(@formula(tumorsize ~ 1 + CancerStage), hdp;\nrandom = Metida.VarEffect(Metida.@covstr(1|Experience), Metida.SI),\n)","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"MetidaNLopt v0.2.0 (Metida 0.5.1)","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"@benchmark fit!($lmm, solver = :nlopt, hes = false, f_tol=1e-8, x_tol=1e-8) seconds = 1","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"BenchmarkTools.Trial: 9 samples with 1 evaluation.\n Range (min … max): 1.651 s … 1.952 s ┊ GC (min … max): 3.10% … 4.27%\n Time (median): 1.797 s ┊ GC (median): 4.15%\n Time (mean ± σ): 1.815 s ± 101.277 ms ┊ GC (mean ± σ): 3.83% ± 0.82%\n\n ▁ ▁ ▁ ▁ ▁ ▁ ▁ █\n █▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█▁▁█▁█▁▁▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁█▁█▁▁▁▁▁▁▁▁▁▁▁▁▁█ ▁\n 1.65 s Histogram: frequency by time 1.95 s <\n\n Memory estimate: 2.47 GiB, allocs estimate: 57729.","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"MetidaCu v0.2.0 (Metida 0.5.1)","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"@benchmark fit!($lmm, solver = :cuda, hes = false, f_tol=1e-8, x_tol=1e-8) seconds = 15","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"BenchmarkTools.Trial: 3 samples with 1 evaluation.\n Range (min … max): 5.137 s … 5.216 s ┊ GC (min … max): 1.03% … 2.19%\n Time (median): 5.166 s ┊ GC (median): 1.43%\n Time (mean ± σ): 5.173 s ± 39.699 ms ┊ GC (mean ± σ): 1.55% ± 0.59%\n\n █ █ █\n █▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█ ▁\n 5.14 s Histogram: frequency by time 5.22 s <\n\n Memory estimate: 2.46 GiB, allocs estimate: 372716.","category":"page"},{"location":"bench/#Model-3:-maximum-1437-observation-per-subject-(10-subjects)","page":"Benchmark","title":"Model 3: maximum 1437 observation-per-subject (10 subjects)","text":"","category":"section"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"lmm = Metida.LMM(@formula(tumorsize ~ 1 + CancerStage), hdp;\nrandom = Metida.VarEffect(Metida.@covstr(1|ntumors), Metida.SI),\n)","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"MetidaNLopt v0.4.0 (Metida 0.12.0)","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"@benchmark fit!($lmm, solver = :nlopt, hes = false, f_tol=1e-8, x_tol=1e-8) seconds = 15","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"BenchmarkTools.Trial: 4 samples with 1 evaluation.\n Range (min … max): 4.305 s … 4.476 s ┊ GC (min … max): 2.49% … 3.52%\n Time (median): 4.372 s ┊ GC (median): 3.23%\n Time (mean ± σ): 4.381 s ± 80.689 ms ┊ GC (mean ± σ): 3.12% ± 0.47%\n\n █ █ █ █\n █▁▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█ ▁\n 4.3 s Histogram: frequency by time 4.48 s <\n\n Memory estimate: 3.83 GiB, allocs estimate: 28068.","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"MetidaCu v0.4.0 (Metida 0.12.0)","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"@benchmark fit!($lmm, solver = :cuda, hes = false, f_tol=1e-8, x_tol=1e-8) seconds = 15","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"BenchmarkTools.Trial: 4 samples with 1 evaluation.\n Range (min … max): 4.928 s … 4.970 s ┊ GC (min … max): 1.83% … 1.78%\n Time (median): 4.957 s ┊ GC (median): 1.85%\n Time (mean ± σ): 4.953 s ± 18.996 ms ┊ GC (mean ± σ): 1.90% ± 0.15%\n\n █ █ █ █\n █▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█▁▁▁▁█ ▁\n 4.93 s Histogram: frequency by time 4.97 s <\n\n Memory estimate: 3.39 GiB, allocs estimate: 149182.","category":"page"},{"location":"bench/#Model-4:-maximum-3409-observation-per-subject-(4-subjects)","page":"Benchmark","title":"Model 4: maximum 3409 observation-per-subject (4 subjects)","text":"","category":"section"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"MetidaCu v0.4.0 (Metida 0.12.0)","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"lmm = Metida.LMM(@formula(tumorsize ~ 1 + CancerStage), hdp;\nrandom = Metida.VarEffect(Metida.@covstr(1|CancerStage), Metida.SI),\n)","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"@benchmark fit!($lmm, solver = :cuda, hes = false, f_tol=1e-8, x_tol=1e-8) seconds = 15","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"julia> @benchmark fit!($lmm, solver = :cuda, hes = false, f_tol=1e-8, x_tol=1e-8) seconds = 15\nBenchmarkTools.Trial: 3 samples with 1 evaluation.\n Range (min … max): 7.343 s … 7.372 s ┊ GC (min … max): 1.62% … 1.48%\n Time (median): 7.346 s ┊ GC (median): 1.49%\n Time (mean ± σ): 7.354 s ± 15.657 ms ┊ GC (mean ± σ): 1.50% ± 0.11%\n\n █ █ █\n █▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█ ▁\n 7.34 s Histogram: frequency by time 7.37 s <\n\n Memory estimate: 5.04 GiB, allocs estimate: 46549.","category":"page"},{"location":"bench/#Conclusion","page":"Benchmark","title":"Conclusion","text":"","category":"section"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"MixedModels.jl faster than Metida.jl in similar cases, but Metida.jl can be used with different covariance structures for random and repeated effects. MetidaNLopt have better performance but not estimate Hessian matrix of REML. MetidaCu have advantage only for big observation-pes-subject number.","category":"page"},{"location":"#Metida","page":"Home","title":"Metida","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"CurrentModule = Metida","category":"page"},{"location":"#Mixed-Models","page":"Home","title":"Mixed Models","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Multilevel models (also known as hierarchical linear models, linear mixed-effect model, mixed models, nested data models, random coefficient, random-effects models, random parameter models, or split-plot designs) are statistical models of parameters that vary at more than one level. An example could be a model of student performance that contains measures for individual students as well as measures for classrooms within which the students are grouped. These models can be seen as generalizations of linear models (in particular, linear regression), although they can also extend to non-linear models. These models became much more popular after sufficient computing power and software became available. (Wiki)","category":"page"},{"location":"","page":"Home","title":"Home","text":"Metida.jl is a Julia package for fitting mixed-effects models with flexible covariance structure.","category":"page"},{"location":"","page":"Home","title":"Home","text":"Implemented covariance structures:","category":"page"},{"location":"","page":"Home","title":"Home","text":"Scaled Identity (SI)\nDiagonal (DIAG)\nAutoregressive (AR)\nHeterogeneous Autoregressive (ARH)\nCompound Symmetry (CS)\nHeterogeneous Compound Symmetry (CSH)\nAutoregressive Moving Average (ARMA)\nToeplitz (TOEP)\nToeplitz Parameterized (TOEPP)\nHeterogeneous Toeplitz (TOEPH)\nHeterogeneous Toeplitz Parameterized (TOEPHP)\nSpatial Exponential (SPEXP)\nSpatial Power (SPPOW)\nSpatial Gaussian (SPGAU)\nUnstructured (UN) \nCustom Covariance Type","category":"page"},{"location":"#Limitations","page":"Home","title":"Limitations","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Maximum length of block more than ~400 (observation-per-subject).\nObservation number more than 160 000.\nFor MetidaCu number of blocks more than 40 (maximum length of block more than 4000).","category":"page"},{"location":"","page":"Home","title":"Home","text":"Actually Metida can fit datasets with wore than 160k observation and 40k subjects levels on PC with 64 GB RAM. This is not \"hard-coded\" limitation, but depends on your model and data structure. Fitting of big datasets can take a lot of time. Optimal dataset size is less than 100k observations with maximum length of block less than 400.","category":"page"},{"location":"","page":"Home","title":"Home","text":"warning: Warning\nJulia v1.8 or higher required.","category":"page"},{"location":"#Contents","page":"Home","title":"Contents","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Pages = [\n \"details.md\",\n \"examples.md\",\n \"validation.md\",\n \"api.md\"]\nDepth = 3","category":"page"},{"location":"","page":"Home","title":"Home","text":"See also:","category":"page"},{"location":"","page":"Home","title":"Home","text":"MixedModels.jl\nGLM.jl\nSweepOperator.jl","category":"page"},{"location":"#Reference","page":"Home","title":"Reference","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Gelman, A.; Hill, J. (2007). Data Analysis Using Regression and Multilevel/Hierarchical Models. New York: Cambridge University Press. pp. 235–299. ISBN 978-0-521-68689-1.","category":"page"}] +[{"location":"nlopt/#NLopt","page":"NLopt","title":"NLopt","text":"","category":"section"},{"location":"nlopt/","page":"NLopt","title":"NLopt","text":"Optimization with NLopt.jl.","category":"page"},{"location":"nlopt/","page":"NLopt","title":"NLopt","text":"Install:","category":"page"},{"location":"nlopt/","page":"NLopt","title":"NLopt","text":"using Pkg\nPkg.add(\"MetidaNLopt\")","category":"page"},{"location":"nlopt/","page":"NLopt","title":"NLopt","text":"Using:","category":"page"},{"location":"nlopt/","page":"NLopt","title":"NLopt","text":"using Metida, MetidaNLopt, StatsBase, StatsModels, CSV, DataFrames\ndf = CSV.File(dirname(pathof(Metida))*\"\\\\..\\\\test\\\\csv\\\\df0.csv\") |> DataFrame\nlmm = LMM(@formula(var ~ sequence + period + formulation), df;\nrandom = VarEffect(@covstr(formulation|subject), CSH),\nrepeated = VarEffect(@covstr(formulation|subject), VC))\nfit!(lmm; solver = :nlopt)","category":"page"},{"location":"nlopt/","page":"NLopt","title":"NLopt","text":"NLopt is a free/open-source library for nonlinear optimization, providing a common interface for a number of different free optimization routines available online as well as original implementations of various other algorithms.","category":"page"},{"location":"nlopt/","page":"NLopt","title":"NLopt","text":"Optimization with NLopt.jl using gradient-free algirithms is less stable, that why two-step optimization schema used. Results can be slightly different for differens OS and Julia versions. Always look into logs. ","category":"page"},{"location":"cuda/#CUDA","page":"CUDA","title":"CUDA","text":"","category":"section"},{"location":"cuda/","page":"CUDA","title":"CUDA","text":"Use CuBLAS & CuSOLVER for REML calculation. Optimization with NLopt.jl.","category":"page"},{"location":"cuda/","page":"CUDA","title":"CUDA","text":"Install:","category":"page"},{"location":"cuda/","page":"CUDA","title":"CUDA","text":"using Pkg\nPkg.add(\"MetidaCu\")","category":"page"},{"location":"cuda/","page":"CUDA","title":"CUDA","text":"Using:","category":"page"},{"location":"cuda/","page":"CUDA","title":"CUDA","text":"using Metida, MetidaCu, StatsBase, StatsModels, CSV, DataFrames\ndf = CSV.File(dirname(pathof(Metida))*\"\\\\..\\\\test\\\\csv\\\\df0.csv\") |> DataFrame\nlmm = LMM(@formula(var ~ sequence + period + formulation), df;\nrandom = VarEffect(@covstr(formulation|subject), CSH),\nrepeated = VarEffect(@covstr(formulation|subject), VC))\nfit!(lmm; solver = :cuda)","category":"page"},{"location":"bioequivalence/#Type-B","page":"Bioequivalence","title":"Type B","text":"","category":"section"},{"location":"bioequivalence/","page":"Bioequivalence","title":"Bioequivalence","text":"using Metida, CSV, DataFrames, CategoricalArrays\n# example data\ndf = CSV.File(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"csv\", \"df0.csv\")) |> DataFrame;\ntransform!(df, :subject => categorical, renamecols=false)\ntransform!(df, :period => categorical, renamecols=false)\ntransform!(df, :sequence => categorical, renamecols=false)\ntransform!(df, :formulation => categorical, renamecols=false)\n\nlmm = LMM(@formula(var~sequence+period+formulation), df;\nrandom = VarEffect(@covstr(1|subject), SI),\n)\nfit!(lmm)\nci = confint(lmm)[end]\nexp.(ci) .* 100.0","category":"page"},{"location":"bioequivalence/#Type-C","page":"Bioequivalence","title":"Type C","text":"","category":"section"},{"location":"bioequivalence/","page":"Bioequivalence","title":"Bioequivalence","text":"lmm =LMM(@formula(var~sequence+period+formulation), df;\nrandom = VarEffect(@covstr(formulation|subject), CSH),\nrepeated = VarEffect(@covstr(formulation|subject), DIAG),\n)\nfit!(lmm)\nci = confint(lmm)[end]\nexp.(ci) .* 100.0","category":"page"},{"location":"bioequivalence/#Reference","page":"Bioequivalence","title":"Reference","text":"","category":"section"},{"location":"bioequivalence/","page":"Bioequivalence","title":"Bioequivalence","text":"Annex I for EMA’s Guideline on the Investigation of Bioequivalence\nFDA Guidance for Industry: Statistical Approaches to Establishing Bioequivalence, APPENDIX F","category":"page"},{"location":"boot/#Parametric-bootstrap","page":"Bootstrap","title":"Parametric bootstrap","text":"","category":"section"},{"location":"boot/#Metida.bootstrap","page":"Bootstrap","title":"Metida.bootstrap","text":"","category":"section"},{"location":"boot/","page":"Bootstrap","title":"Bootstrap","text":"Metida.bootstrap","category":"page"},{"location":"boot/#Metida.bootstrap","page":"Bootstrap","title":"Metida.bootstrap","text":"bootstrap(lmm::LMM; double = false, n = 100, verbose = true, init = lmm.result.theta, rng = default_rng())\n\nParametric bootstrap.\n\nwarning: Warning\nExperimental: API not stable\n\ndouble - use double approach (default - false);\nn - number of bootstrap samples;\nverbose - show progress bar;\ninit - initial values for lmm;\nrng - random number generator.\n\nParametric bootstrap based on generating random responce vector from known distribution, that given from fitted LMM model.\n\nSimple bootstrap:\n\nFor one-stage bootstrap variance parameters and coefficients simulated in one step. \n\nDouble bootstrap:\n\nFor double bootstrap (two-tage) variance parameters simulated in first cycle, than they used for simulating coefficients and var(β) on stage two. On second stage parent-model β used for simulations. \n\nlmm = Metida.LMM(@formula(var~sequence+period+formulation), df0m;\nrandom = Metida.VarEffect(Metida.@covstr(formulation|subject), Metida.CSH),\n)\nMetida.fit!(lmm)\nbt = Metida.bootstrap(lmm; n = 1000, double = true, rng = MersenneTwister(1234))\nconfint(bt)\n\nSee also: confint, Metida.miboot, Metida.nvar, Metida.tvar, Metida.straps, Metida.sdstraps, Metida.thetastraps\n\n\n\n\n\n","category":"function"},{"location":"boot/#Metida.nvar","page":"Bootstrap","title":"Metida.nvar","text":"","category":"section"},{"location":"boot/","page":"Bootstrap","title":"Bootstrap","text":"Metida.nvar","category":"page"},{"location":"boot/#Metida.nvar","page":"Bootstrap","title":"Metida.nvar","text":"nvar(br::BootstrapResult)\n\nNumber of coefficient in the model.\n\n\n\n\n\n","category":"function"},{"location":"boot/#Metida.tvar","page":"Bootstrap","title":"Metida.tvar","text":"","category":"section"},{"location":"boot/","page":"Bootstrap","title":"Bootstrap","text":"Metida.tvar","category":"page"},{"location":"boot/#Metida.tvar","page":"Bootstrap","title":"Metida.tvar","text":"tvar(br::BootstrapResult) = length(br.theta)\n\nNumber of theta parameters in the model.\n\n\n\n\n\n","category":"function"},{"location":"boot/#Metida.straps","page":"Bootstrap","title":"Metida.straps","text":"","category":"section"},{"location":"boot/","page":"Bootstrap","title":"Bootstrap","text":"Metida.straps","category":"page"},{"location":"boot/#Metida.straps","page":"Bootstrap","title":"Metida.straps","text":"straps(br::BootstrapResult, idx::Int)\n\nReturn coefficients vector.\n\n\n\n\n\n","category":"function"},{"location":"boot/#Metida.sdstraps","page":"Bootstrap","title":"Metida.sdstraps","text":"","category":"section"},{"location":"boot/","page":"Bootstrap","title":"Bootstrap","text":"Metida.sdstraps","category":"page"},{"location":"boot/#Metida.sdstraps","page":"Bootstrap","title":"Metida.sdstraps","text":"sdstraps(br::BootstrapResult, idx::Int)\n\nReturn sqrt(var(β)) vector.\n\n\n\n\n\n","category":"function"},{"location":"boot/#Metida.thetastraps","page":"Bootstrap","title":"Metida.thetastraps","text":"","category":"section"},{"location":"boot/","page":"Bootstrap","title":"Bootstrap","text":"Metida.thetastraps","category":"page"},{"location":"boot/#Metida.thetastraps","page":"Bootstrap","title":"Metida.thetastraps","text":"straps(br::BootstrapResult, idx::Int)\n\nReturn theta vector.\n\n\n\n\n\n","category":"function"},{"location":"details/#Details","page":"Details","title":"Details","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"The solution to the mixed model equations is a maximum likelihood estimate when the distribution of the errors is normal. Maximum likelihood estimates are based on the probability model for the observed responses. In the probability model the distribution of the responses is expressed as a function of one or more parameters. PROC MIXED in SAS used restricted maximum likelihood (REML) approach by default. REML equation can be described with following (Henderson, 1959;Laird et.al. 1982; Jennrich 1986; Lindstrom & Bates, 1988; Gurka et.al 2006).","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"Metida.jl using optimization with Optim.jl package (Newton's Method) by default. Because variance have only positive values and ρ is limited as -1 ≤ ρ ≤ 1 in Metida.jl \"link\" function is used. Exponential values is optimizing in variance part and ρ is linked with sigmoid function. All steps perform with differentiable functions with forward automatic differentiation using ForwardDiff.jl package. Also MetidaNLopt.jl and MetidaCu.jl available for optimization with NLopt.jl and solving on CUDA GPU. Sweep algorithm using for variance-covariance matrix inversing in REML calculation.","category":"page"},{"location":"details/#Model","page":"Details","title":"Model","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"In matrix notation a mixed effect model can be represented as:","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"y = Xbeta + Zu + epsilon","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"where:","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"epsilon sim N(0 R)\n\n\n\nu sim N(0 G)\n\n\n\ny sim N(Xbeta V)\n","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"where V depends on covariance sructure and parameters theta:","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"V = CovStruct(theta)\n","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"The unknown parameters include the regression parameters in beta and covariance parameters in theta.","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"Estimation of these model parameters relies on the use of a Newton-Ralphson (by default) algorithm. When we use either algorithm for finding REML solutions, we need to compute V^-1 and its derivatives with respect to theta, which are computationally difficult for large n, therefor SWEEP (see https://github.com/joshday/SweepOperator.jl) algorithm used to meke oprtimization less computationaly expensive.","category":"page"},{"location":"details/#V","page":"Details","title":"V","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"V_i = Z_iGZ_i+R_i","category":"page"},{"location":"details/#Henderson's-«mixed-model-equations»","page":"Details","title":"Henderson's «mixed model equations»","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"beginpmatrixXR^-1XXR^-1ZZR^-1XZR^-1Z+G_-1endpmatrix beginpmatrixwidehatbeta widehatu endpmatrix= beginpmatrixXR^-1yZR^-1yendpmatrix","category":"page"},{"location":"details/#REML","page":"Details","title":"REML","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"logREML(thetabeta) = -fracN-p2 - frac12sum_i=1^nlogV_theta i-\n\n-frac12logsum_i=1^nX_iV_theta i^-1X_i-frac12sum_i=1^n(y_i - X_ibeta)V_theta i^-1(y_i - X_ibeta)","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"Actually L(theta) = -2logREML = L_1(theta) + L_2(theta) + L_3(theta) + c used for optimization, where:","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"L_1(theta) = frac12sum_i=1^nlogV_i \n\nL_2(theta) = frac12logsum_i=1^nX_iV_i^-1X_i \n\nL_3(theta) = frac12sum_i=1^n(y_i - X_ibeta)V_i^-1(y_i - X_ibeta)","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"nablamathcalL(theta) = nabla L_1(theta) + nabla L_2(theta) + nabla L_3(theta)","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"mathcalHmathcalL(theta) = mathcalHL_1(theta) + mathcalHL_2(theta) + mathcalH L_3(theta)","category":"page"},{"location":"details/#weights_header","page":"Details","title":"Weights","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"If weights defined:","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"\nW_i = diag(wts_i)\n\n\n\nV_i = Z_i G Z_i+ W^- frac12_i R_i W^- frac12_i","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"where W - diagonal matrix of weights.","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"If wts is matrix then:","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"\nW_i = wts_i\n\n\n\nV_i = Z_i G Z_i+ R_i circ W_i","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"where circ - element-wise multiplication.","category":"page"},{"location":"details/#Multiple-random-and-repeated-effects","page":"Details","title":"Multiple random and repeated effects","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"If model include multiple effects ( with n random and m repeated effects) final V will be:","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"V_i = Z_i 1 G_1 Z_i 1 + + Z_i n G_1 Z_i n+ W^- frac12_i ( R_i 1 + + R_i m) W^- frac12_i","category":"page"},{"location":"details/#Initial-step","page":"Details","title":"Initial step","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"Initial (first) step before optimization may be done:","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"theta_n+1 = theta_n - nablamathcalL(theta_n) * mathcalH^(theta_n) where \n\nmathcalH^(theta_n) = - mathcalHL_1(theta_n) + mathcalH L_3(theta) if score \n\nmathcalH^(theta_n) = mathcalH L_3(theta_n) if ai\n","category":"page"},{"location":"details/#Beta-(β)","page":"Details","title":"Beta (β)","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"beta = (sum_i=1^n X_iV_i^-1X_i)^-1(sum_i=1^n X_iV_i^-1y_i)","category":"page"},{"location":"details/#F","page":"Details","title":"F","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"F = fracbetaL(LCL)^-1Lbetarank(LCL)","category":"page"},{"location":"details/#Variance-covariance-matrix-of-β","page":"Details","title":"Variance covariance matrix of β","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"C = (sum_i=1^n X_iV_i^-1X_i)^-1","category":"page"},{"location":"details/#Sweep","page":"Details","title":"Sweep","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"Details see: https://github.com/joshday/SweepOperator.jl","category":"page"},{"location":"details/#varlink_header","page":"Details","title":"Variance parameters link function","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"Apply special function to some part of theta vector.","category":"page"},{"location":"details/#Variance-(var)-part","page":"Details","title":"Variance (var) part","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"Applied only to variance part.","category":"page"},{"location":"details/#Exponential-function-(:exp)","page":"Details","title":"Exponential function (:exp)","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"Exponential function applied.","category":"page"},{"location":"details/","page":"Details","title":"Details","text":" f(x) = exp(x)","category":"page"},{"location":"details/","page":"Details","title":"Details","text":" f^-1(x) = log(x)","category":"page"},{"location":"details/#Square-function-(:sq)","page":"Details","title":"Square function (:sq)","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":" f(x) = x^2","category":"page"},{"location":"details/","page":"Details","title":"Details","text":" f^-1(x) = sqrt(x)","category":"page"},{"location":"details/#Identity-function-(:identity)","page":"Details","title":"Identity function (:identity)","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":" f(x) = x","category":"page"},{"location":"details/","page":"Details","title":"Details","text":" f^-1(x) = x","category":"page"},{"location":"details/#Covariance-(rho)-part","page":"Details","title":"Covariance (rho) part","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"Applied only to covariance part.","category":"page"},{"location":"details/#Sigmoid-function-(:sigm)","page":"Details","title":"Sigmoid function (:sigm)","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":" f(x) = 1 (1 + exp(- x * k)) * 2 - 1","category":"page"},{"location":"details/","page":"Details","title":"Details","text":" f^-1(x) = -log(1 (x + 1) * 2 - 1) k","category":"page"},{"location":"details/","page":"Details","title":"Details","text":"where k = 01","category":"page"},{"location":"details/#Arctangent-function-(:atan)","page":"Details","title":"Arctangent function (:atan)","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":" f(x) = atan(x)pi*2","category":"page"},{"location":"details/","page":"Details","title":"Details","text":" f^-1(x) = tan(x*pi2)","category":"page"},{"location":"details/#\"Square\"-sigmoid-function-(:sqsigm)","page":"Details","title":"\"Square\" sigmoid function (:sqsigm)","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":" f(x) = x sqrt1 + (x)^2","category":"page"},{"location":"details/","page":"Details","title":"Details","text":" f^-1(x) = sign(x) * sqrtx^2(1 - x^2)","category":"page"},{"location":"details/#Positive-sigmoid-function-(:psigm)","page":"Details","title":"Positive sigmoid function (:psigm)","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":" f(x) = 1(1 + exp(-x 2))","category":"page"},{"location":"details/","page":"Details","title":"Details","text":" f^-1(x) = -log(1x - 1) * 2","category":"page"},{"location":"details/#Additional-parameters-(theta)-part","page":"Details","title":"Additional parameters (theta) part","text":"","category":"section"},{"location":"details/","page":"Details","title":"Details","text":"No function applied.","category":"page"},{"location":"mi/#Multiple-imputation","page":"Multiple imputation","title":"Multiple imputation","text":"","category":"section"},{"location":"mi/#Metida.milmm","page":"Multiple imputation","title":"Metida.milmm","text":"","category":"section"},{"location":"mi/","page":"Multiple imputation","title":"Multiple imputation","text":"Metida.milmm","category":"page"},{"location":"mi/#Metida.milmm","page":"Multiple imputation","title":"Metida.milmm","text":"milmm(mi::MILMM; n = 100, verbose = true, rng = default_rng())\n\nMultiple imputation.\n\nwarning: Warning\nExperimental: API not stable\n\nFor each subject random vector of missing values generated from distribution:\n\nX_imp sim N(mu_miss mid obs Sigma_miss mid obs)\n\nmu_miss mid obs = mu_1+ Sigma_12 Sigma_22^-1 (x_obs- mu_2)\n\nSigma_miss mid obs = Sigma_11- Sigma_12 Sigma_22^-1 Sigma_21\n\nx = beginbmatrixx_miss x_obs endbmatrix\nmu = beginbmatrixmu_1 mu_2 endbmatrix\nSigma = beginbmatrix Sigma_11 Sigma_12 Sigma_21 Sigma_22 endbmatrix\n\nExample:\n\nlmm = Metida.LMM(@formula(var~sequence+period+formulation), df0m;\nrandom = Metida.VarEffect(Metida.@covstr(formulation|subject), Metida.CSH),\n)\nMetida.fit!(lmm)\nmi = Metida.MILMM(lmm, df0m)\nbm = Metida.milmm(mi; n = 100, rng = MersenneTwister(1234))\n\n\n\n\n\nmilmm(lmm::LMM, data; n = 100, verbose = true, rng = default_rng())\n\nMultiple imputation in one step. data for lmm and for milmm should be the same, if different data used resulst can be unpredictable.\n\n\n\n\n\n","category":"function"},{"location":"mi/#Metida.miboot","page":"Multiple imputation","title":"Metida.miboot","text":"","category":"section"},{"location":"mi/","page":"Multiple imputation","title":"Multiple imputation","text":"Metida.miboot","category":"page"},{"location":"mi/#Metida.miboot","page":"Multiple imputation","title":"Metida.miboot","text":"miboot(mi::MILMM{T}; n = 100, double = true, bootn = 100, verbose = true, rng = default_rng())\n\nMultiple imputation with parametric bootstrap step.\n\nwarning: Warning\nExperimental: API not stable\n\nExample:\n\nlmm = Metida.LMM(@formula(var~sequence+period+formulation), df0m;\nrandom = Metida.VarEffect(Metida.@covstr(formulation|subject), Metida.CSH),\n)\nMetida.fit!(lmm)\nmi = Metida.MILMM(lmm, df0m)\nbm = Metida.miboot(mi; n = 100, rng = MersenneTwister(1234))\n\n\n\n\n\n","category":"function"},{"location":"instanduse/#Installation","page":"First step","title":"Installation","text":"","category":"section"},{"location":"instanduse/","page":"First step","title":"First step","text":"ENV[\"GKSwstype\"] = \"nul\"\nusing Plots, StatsPlots, CSV, DataFrames, Metida\n\ngr()\n\nPlots.reset_defaults()\n\nrds = CSV.File(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"csv\", \"1fptime.csv\"); types = [String, String, Float64, Float64]) |> DataFrame\n\np = @df rds plot(:time, :response, group = (:subject, :factor), colour = [:red :blue], legend = false)\n\npng(p, \"plot1.png\")\n\nrds = CSV.File(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"csv\", \"1freparma.csv\"); types = [String, String, Float64, Float64]) |> DataFrame\n\np = @df rds plot(:time, :response, group = (:subject, :factor), colour = [:red :blue], legend = false)\n\npng(p, \"plot2.png\")","category":"page"},{"location":"instanduse/","page":"First step","title":"First step","text":"import Pkg; Pkg.add(\"Metida\")","category":"page"},{"location":"instanduse/#Simple-example","page":"First step","title":"Simple example","text":"","category":"section"},{"location":"instanduse/","page":"First step","title":"First step","text":"LMM\nMetida.@covstr\nMetida.VarEffect\nfit!","category":"page"},{"location":"instanduse/#Step-1:-Load-data","page":"First step","title":"Step 1: Load data","text":"","category":"section"},{"location":"instanduse/","page":"First step","title":"First step","text":"Load provided data with CSV and DataFrames:","category":"page"},{"location":"instanduse/","page":"First step","title":"First step","text":"using Metida, CSV, DataFrames, CategoricalArrays\n\ndf = CSV.File(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"csv\", \"df0.csv\")) |> DataFrame;\nnothing # hide","category":"page"},{"location":"instanduse/","page":"First step","title":"First step","text":"note: Note\nCheck that all categorical variables are categorical.","category":"page"},{"location":"instanduse/","page":"First step","title":"First step","text":"transform!(df, :subject => categorical, renamecols=false)\ntransform!(df, :period => categorical, renamecols=false)\ntransform!(df, :sequence => categorical, renamecols=false)\ntransform!(df, :formulation => categorical, renamecols=false)\nnothing # hide","category":"page"},{"location":"instanduse/#Step-2:-Make-model","page":"First step","title":"Step 2: Make model","text":"","category":"section"},{"location":"instanduse/","page":"First step","title":"First step","text":"Make model with @formula macro from StatsModels. Define random and repreated effects with Metida.VarEffect using Metida.@covstr macros. Left side of @covstr is model of effect and right side is a effect itself. Metida.HeterogeneousCompoundSymmetry and Metida.Diag (Diagonal) in example bellow is a model of variance-covariance structure. See also Metida.@lmmformula macro.","category":"page"},{"location":"instanduse/","page":"First step","title":"First step","text":"note: Note\nIn some cases levels of repeated effect should not be equal inside each level of subject or model will not have any sense. For example, it is assumed that usually CSH or UN (Unstructured) using with levels of repeated effect is different inside each level of subject. Metida does not check this!","category":"page"},{"location":"instanduse/","page":"First step","title":"First step","text":"lmm = LMM(@formula(var~sequence+period+formulation), df;\nrandom = VarEffect(@covstr(formulation|subject), CSH),\nrepeated = VarEffect(@covstr(formulation|subject), DIAG));","category":"page"},{"location":"instanduse/","page":"First step","title":"First step","text":"Also Metida.@lmmformula macro can be used:","category":"page"},{"location":"instanduse/","page":"First step","title":"First step","text":"lmm = LMM(@lmmformula(var~sequence+period+formulation,\n random = formulation|subject:CSH,\n repeated = formulation|subject:DIAG),\n df)","category":"page"},{"location":"instanduse/#Step-3:-Fit","page":"First step","title":"Step 3: Fit","text":"","category":"section"},{"location":"instanduse/","page":"First step","title":"First step","text":"Just fit the model.","category":"page"},{"location":"instanduse/","page":"First step","title":"First step","text":"fit!(lmm)","category":"page"},{"location":"instanduse/#Check-warnings-and-errors-in-log.","page":"First step","title":"Check warnings and errors in log.","text":"","category":"section"},{"location":"instanduse/","page":"First step","title":"First step","text":"lmm.log","category":"page"},{"location":"instanduse/#Confidence-intervals-for-coefficients","page":"First step","title":"Confidence intervals for coefficients","text":"","category":"section"},{"location":"instanduse/","page":"First step","title":"First step","text":"confint(lmm)","category":"page"},{"location":"instanduse/","page":"First step","title":"First step","text":"note: Note\nSatterthwaite approximation for the denominator degrees of freedom used by default.","category":"page"},{"location":"instanduse/#StatsBsae-API","page":"First step","title":"StatsBsae API","text":"","category":"section"},{"location":"instanduse/","page":"First step","title":"First step","text":"StatsBsae API implemented: Metida.islinear, Metida.confint, Metida.coef, Metida.coefnames, Metida.dof_residual, Metida.dof, Metida.loglikelihood, Metida.aic, Metida.bic, Metida.aicc, Metida.isfitted, Metida.vcov, Metida.stderror, Metida.modelmatrix, Metida.response, Metida.crossmodelmatrix, Metida.coeftable, Metida.responsename","category":"page"},{"location":"instanduse/#Type-III-Tests-of-Fixed-Effects","page":"First step","title":"Type III Tests of Fixed Effects","text":"","category":"section"},{"location":"instanduse/","page":"First step","title":"First step","text":"warning: Warning\nExperimental","category":"page"},{"location":"instanduse/","page":"First step","title":"First step","text":"typeiii(lmm)","category":"page"},{"location":"instanduse/#Model-construction","page":"First step","title":"Model construction","text":"","category":"section"},{"location":"instanduse/","page":"First step","title":"First step","text":"To construct model you can use LMM constructor. ","category":"page"},{"location":"instanduse/","page":"First step","title":"First step","text":"model - example: @formula(var ~ sequence + period + formulation)\nrandom - effects can be specified like this: VarEffect(@covstr(formulation|subject), CSH). @covstr is a effect model: @covstr(formulation|subject). CSH is a CovarianceType structure. Premade constants: SI, DIAG, AR, ARH, CS, CSH, ARMA, TOEP, TOEPH, UN, ets. If not specified only repeated used.\nrepeated - can be specified like random effect. If not specified VarEffect(@covstr(1|1), SI) used. If no repeated effects specified vector of ones used.","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Q1: Why it working so slow?","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Metida.jl work with small and medium datasets. Model fitting is based on variance-covariance matrix inversion at each iteration. That's why if you have big blocks it will work slow. If you have big blocks you can try to use MetidaCu.jl for optimization on CUDA GPU. You can use MetidaNLopt.jl for better performance, but you will not get Hessian matrix at the end of optimization. Also if you don't need to specify repeated-measures (R) covariance part and use SI, DIAG, CS, CSH covariance types for random-effect part (G) you can use MixedModels.jl - it work much faster.","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Q2: What blocks is?","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Blocks depend on subjects. If you have only one random effect block is equivalent to subject. If you have more than one random effect blocks will be made as non-crossing combination for all subject variables. ","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Q3: Why model does not converge?","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Optimization of REML function can depend on many factors. In some cases covariance parameters can be correlated (ill-conditioned/singular covariance matrix). So hypersurface in the maximum area can be very flat, that why the result can be different for different starting values (or for different software even REML is near equal). Also, some models can not be fitted for specific data at all. If the model not fitted try to check how meaningful and reasonable is the model or try to guess more robust initial conditions.","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Q4: Is model fitting is correct?","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Use 'lmm.log' to see warnings and errors. If you have warnings and error maybe this model is overspecified. Try to change variance structure or guess more robust initial conditions.","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Q5: How to choose best variance-covariance structure?","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"SAS Manual, Mixed Models Analyses Using the SAS System Course Notes:","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Unfortunately, our attempt to share a very RECENT perspective by a relatively small number of statistics and statistics related research has somewhat sidetracked the focus of lesson 1. Would like to attempt to provide some clarity to some of the discussion on the discussion forum about the bar chart vs. interval charts. You can use information criteria produced by the MIXED procedure as a tool to help you select the model with the most appropriate covariance structure. The smaller the information criteria value is, the better the model is. Theoretically, the smaller the -2 Res Log Likelihood is, the better the model is. However, you can always make this value smaller by adding parameters to the model. Information criteria attached penalties to the negative -2 Res Log Likelihood value; that is, the more the parameters, the bigger the penalties. Two commonly used information criteria are Akaike's (1974) and Schwartz's (1978). Generally speaking, BIC tends to choose less complex models than AIC. Because choosing a model that is too simple inflates Type I error rate, when Type I error control is the highest priority, you may want to use AIC. On the other hand, if loss of power is more of a concern, BIC might be preferable (Guerin and Stroup 2000). Starting in the Release 8.1, the MIXED procedure produces another information criteria, AICC. AICC is a finite-sample corrected Akaike Information Criterion. For small samples, it reduces the bias produced by AIC; for large samples, AICC converges to AIC. In general, AICC is preferred to AIC. For more information on information criteria, especially AICC, refer to Burnham, K. P. and Anderson, D. R. (1998). The basic idea for repeated measures analysis is that, among plausible within-subject covariance models given a particular study, the model that minimizes AICC or BIC (your choice) is preferable. When AICC or BIC are close, the simpler model is generally preferred.","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Q6: I have a slightly different results for DF calculation, what's wrong?","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Check logs. If final hessian matrix for REML function is ill-conditioned results on differet OS can be slightly different. If possible, try to use more stable covariance structure. Or make an issue on github.","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Q7: I changed maxthreads settings but nothing happend. ","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Check the number of execution threads: Threads.nthreads(), maybe you should change julia startup settings. See also julia threads docs.","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"See also:","category":"page"},{"location":"faq/","page":"F.A.Q.","title":"F.A.Q.","text":"Barnett, A.G., Koper, N., Dobson, A.J., Schmiegelow, F. and Manseau, M. (2010), Using information criteria to select the correct variance–covariance structure for longitudinal data in ecology. Methods in Ecology and Evolution, 1: 15-24. https://doi.org/10.1111/j.2041-210X.2009.00009.x\nGuidelines for Selecting the Covariance Structure in Mixed Model Analysis\nH. J. Keselman,James Algina,Rhonda K. Kowalchuk &Russell D. Wolfinger. A comparison of two approaches for selecting covariance structures in the analysis of repeated measurements. https://doi.org/10.1080/03610919808813497","category":"page"},{"location":"api/#API","page":"API","title":"API","text":"","category":"section"},{"location":"api/#Basic","page":"API","title":"Basic","text":"","category":"section"},{"location":"api/#@covstr","page":"API","title":"@covstr","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.@covstr","category":"page"},{"location":"api/#Metida.@covstr","page":"API","title":"Metida.@covstr","text":"@covstr(ex)\n\nMacros for random/repeated effect model.\n\nExample\n\n@covstr(factor|subject)\n\n\n\n\n\n","category":"macro"},{"location":"api/#@lmmformula","page":"API","title":"@lmmformula","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.@lmmformula","category":"page"},{"location":"api/#Metida.@lmmformula","page":"API","title":"Metida.@lmmformula","text":"@lmmformula(formula, args...)\n\nMacro for made formula with variance-covariance structure representation. @lmmformula could be used for shorter LMM construction.\n\nExample:\n\nlmm = Metida.LMM(@lmmformula(var~sequence+period+formulation,\nrandom = formulation|subject:CSH,\nrepeated = formulation|subject:DIAG),\ndf0)\n\nequal to:\n\nlmm = LMM(@formula(var~sequence+period+formulation), df0;\nrandom = VarEffect(@covstr(formulation|subject), CSH),\nrepeated = VarEffect(@covstr(formulation|subject), DIAG),\n)\n\n@lmmformula have 3 components - 1'st is a formula for fixed effect, it's defined like in StstsModels (1st argument just provided to @formula macro). Other arguments should be defined like keywords. repeated keyword define repeated effect part, random - define random effect part. You can use several random factors as in example bellow:\n\nlmm = LMM(@lmmformula(var~sequence+period+formulation,\nrandom = formulation|subject:CSH,\nrandom = 1|subject:DIAG,\nrepeated = formulation|subject:DIAG),\ndf0)\n\nrandom or repeated structure made by template:\n\neffect formula | blocking factor [/ nested factor] [: covariance structure]\n\n| - devide effect formula form blocking factor definition (necessarily), / and : modificator are optional.\n\n/ 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.\n\n: - covariance structure defined right after : (SI, DIAG, CS, CSH, ets...), if : not used then SI used for this effect.\n\nTerms like a+b or a*b shuould not be used as a blocking factors.\n\n\n\n\n\n","category":"macro"},{"location":"api/#Metida.CovarianceType","page":"API","title":"Metida.CovarianceType","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.CovarianceType","category":"page"},{"location":"api/#Metida.CovarianceType","page":"API","title":"Metida.CovarianceType","text":"CovarianceType(cm::AbstractCovmatMethod)\n\nMake covariance type with AbstractCovmatMethod.\n\n\n\n\n\n","category":"type"},{"location":"api/#LMM","page":"API","title":"LMM","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.LMM","category":"page"},{"location":"api/#Metida.LMM","page":"API","title":"Metida.LMM","text":"LMM(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)\n\nMake Linear-Mixed Model object.\n\nmodel: is a fixed-effect model (@formula)\n\ndata: tabular data\n\ncontrasts: contrasts for fixed factors\n\nrandom: vector of random effects or single random effect\n\nrepeated: is a repeated effect or vector\n\nwts: regression weights (residuals).\n\nWeigts 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.\n\nSee also: @lmmformula\n\n\n\n\n\n","category":"type"},{"location":"api/#VarEffect","page":"API","title":"VarEffect","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.VarEffect","category":"page"},{"location":"api/#Metida.VarEffect","page":"API","title":"Metida.VarEffect","text":"VarEffect(formula, covtype::T, coding) where T <: AbstractCovarianceType\n\nVarEffect(formula, covtype::T; coding = nothing) where T <: AbstractCovarianceType\n\nVarEffect(formula; coding = nothing)\n\nRandom/repeated effect.\n\nformula from @covstr(ex) macros.\ncovtype - covariance type (SI, DIAG, CS, CSH, AR, ARH, ARMA, TOEP, TOEPH, TOEPP, TOEPHP)\n\nnote: Note\nCategorical factors are coded with FullDummyCoding() by default, use coding for other contrast codeing.\n\nExample\n\nVarEffect(@covstr(1+factor|subject), CSH)\n\nVarEffect(@covstr(1 + formulation|subject), CSH; coding = Dict(:formulation => StatsModels.DummyCoding()))\n\n\n\n\n\n","category":"type"},{"location":"api/#Covariance-structures","page":"API","title":"Covariance structures","text":"","category":"section"},{"location":"api/#Metida.Autoregressive","page":"API","title":"Metida.Autoregressive","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.Autoregressive","category":"page"},{"location":"api/#Metida.Autoregressive","page":"API","title":"Metida.Autoregressive","text":"Autoregressive()\n\nAutoregressive covariance type.\n\nAR = Autoregressive()\n\nbeginbmatrix 1 rho rho^2 rho^3 \nrho 1 rho rho^2 rho^2 rho 1 rho \nrho^3 rho^2 rho 1\nendbmatrixsigma^2\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.AutoregressiveMovingAverage","page":"API","title":"Metida.AutoregressiveMovingAverage","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.AutoregressiveMovingAverage","category":"page"},{"location":"api/#Metida.AutoregressiveMovingAverage","page":"API","title":"Metida.AutoregressiveMovingAverage","text":"AutoregressiveMovingAverage()\n\nAutoregressive moving average covariance type.\n\nARMA = AutoregressiveMovingAverage()\n\nbeginbmatrix 1 gamma gammarho gammarho^2 \ngamma 1 gamma gammarho \ngammarho gamma 1 gamma \ngammarho^2 gammarho gamma 1\nendbmatrixsigma^2\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.CompoundSymmetry","page":"API","title":"Metida.CompoundSymmetry","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.CompoundSymmetry","category":"page"},{"location":"api/#Metida.CompoundSymmetry","page":"API","title":"Metida.CompoundSymmetry","text":"CompoundSymmetry()\n\nCompound symmetry covariance type.\n\nCS = CompoundSymmetry()\n\nbeginbmatrix 1 rho rho rho \nrho 1 rho rho \nrho rho 1 rho \nrho rho rho 1\nendbmatrixsigma^2\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.Diag","page":"API","title":"Metida.Diag","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.Diag","category":"page"},{"location":"api/#Metida.Diag","page":"API","title":"Metida.Diag","text":"Diag()\n\nDiagonal covariance type.\n\nDIAG = Diag()\n\nbeginbmatrix sigma_a^2 0 0 0 sigma_b^2 0 0 0 sigma_c^2 endbmatrix\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.HeterogeneousAutoregressive","page":"API","title":"Metida.HeterogeneousAutoregressive","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.HeterogeneousAutoregressive","category":"page"},{"location":"api/#Metida.HeterogeneousAutoregressive","page":"API","title":"Metida.HeterogeneousAutoregressive","text":"HeterogeneousAutoregressive()\n\nHeterogeneous autoregressive covariance type.\n\nARH = HeterogeneousAutoregressive()\n\nbeginbmatrix\nsigma_a^2 rhosigma_asigma_b rho^2sigma_asigma_c rho^3sigma_asigma_d \nrhosigma_bsigma_a sigma_b^2 rhosigma_bsigma_c rho^2sigma_bsigma_d \nrho^2sigma_csigma_a rhosigma_csigma_b sigma_c^2 rhosigma_csigma_d \nrho^3sigma_dsigma_a rho^2sigma_dsigma_b rhosigma_dsigma_c sigma_d^2\nendbmatrix\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.HeterogeneousCompoundSymmetry","page":"API","title":"Metida.HeterogeneousCompoundSymmetry","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.HeterogeneousCompoundSymmetry","category":"page"},{"location":"api/#Metida.HeterogeneousCompoundSymmetry","page":"API","title":"Metida.HeterogeneousCompoundSymmetry","text":"HeterogeneousCompoundSymmetry()\n\nHeterogeneous compound symmetry covariance type.\n\nCSH = HeterogeneousCompoundSymmetry()\n\nbeginbmatrix\nsigma_a^2 rhosigma_asigma_b rhosigma_asigma_c rhosigma_asigma_d \nrhosigma_bsigma_a sigma_b^2 rhosigma_bsigma_c rhosigma_bsigma_d \nrhosigma_csigma_a rhosigma_csigma_b sigma_c^2 rhosigma_csigma_d \nrhosigma_dsigma_a rhosigma_dsigma_b rhosigma_dsigma_c sigma_d^2\nendbmatrix\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.HeterogeneousToeplitz","page":"API","title":"Metida.HeterogeneousToeplitz","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.HeterogeneousToeplitz","category":"page"},{"location":"api/#Metida.HeterogeneousToeplitz","page":"API","title":"Metida.HeterogeneousToeplitz","text":"HeterogeneousToeplitz()\n\nHeterogeneous toeplitz covariance type. Only for G matrix.\n\nTOEPH = HeterogeneousToeplitz()\n\nbeginbmatrix\nsigma_a^2 rho_1 sigma_a sigma_b rho_2 sigma_a sigma_c rho_3 sigma_a sigma_d \nrho_1 sigma_b sigma_a sigma_b^2 rho_1 sigma_b sigma_c rho_2 sigma_b sigma_d \nrho_2 sigma_c sigma_a rho_1 sigma_c sigma_b sigma_c^2 rho_1 sigma_c sigma_d \nrho_3 sigma_d sigma_a rho_2 sigma_d sigma_b rho_1 sigma_d sigma_c sigma_d^2\nendbmatrix\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.HeterogeneousToeplitzParameterized","page":"API","title":"Metida.HeterogeneousToeplitzParameterized","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.HeterogeneousToeplitzParameterized","category":"page"},{"location":"api/#Metida.HeterogeneousToeplitzParameterized","page":"API","title":"Metida.HeterogeneousToeplitzParameterized","text":"HeterogeneousToeplitzParameterized(p::Int)\n\nHeterogeneous toeplitz covariance type with parameter p, (number of bands = p - 1, if p = 1 it's equal DIAG structure).\n\nTOEPHP(p) = HeterogeneousToeplitzParameterized(p)\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.ScaledIdentity","page":"API","title":"Metida.ScaledIdentity","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.ScaledIdentity","category":"page"},{"location":"api/#Metida.ScaledIdentity","page":"API","title":"Metida.ScaledIdentity","text":"ScaledIdentity()\n\nScaled identity covariance type.\n\nSI = ScaledIdentity()\n\nbeginbmatrix 1 0 0 0 1 0 0 0 1 endbmatrixsigma^2\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.SpatialExponential","page":"API","title":"Metida.SpatialExponential","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.SpatialExponential","category":"page"},{"location":"api/#Metida.SpatialExponential","page":"API","title":"Metida.SpatialExponential","text":"SpatialExponential()\n\nSpatian Exponential covariance structure. Used only for repeated effect.\n\nR_ij = sigma^2 * exp(-dist(ij)theta)\n\nwhere dist - Euclidean distance between row-vectors of repeated effect matrix for subject i and j, θ > 0.\n\nSPEXP = SpatialExponential()\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.SpatialGaussian","page":"API","title":"Metida.SpatialGaussian","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.SpatialGaussian","category":"page"},{"location":"api/#Metida.SpatialGaussian","page":"API","title":"Metida.SpatialGaussian","text":"SpatialGaussian()\n\nSpatian Gaussian covariance structure. Used only for repeated effect.\n\nR_ij = sigma^2 * exp(- dist(ij)^2 theta^2)\n\nwhere dist - Euclidean distance between row-vectors of repeated effect matrix for subject i and j, θ ≠ 0.\n\nSPGAU = SpatialGaussian()\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.SpatialPower","page":"API","title":"Metida.SpatialPower","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.SpatialPower","category":"page"},{"location":"api/#Metida.SpatialPower","page":"API","title":"Metida.SpatialPower","text":"SpatialPower()\n\nSpatian Power covariance structure. Used only for repeated effect.\n\nR_ij = sigma^2 * rho^dist(ij)\n\nwhere dist - Euclidean distance between row-vectors of repeated effect matrix for subject i and j, 1 > ρ > -1.\n\nSPPOW = SpatialPower()\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.Toeplitz","page":"API","title":"Metida.Toeplitz","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.Toeplitz","category":"page"},{"location":"api/#Metida.Toeplitz","page":"API","title":"Metida.Toeplitz","text":"Toeplitz()\n\nToeplitz covariance type. Only for G matrix.\n\nTOEP = Toeplitz()\n\nbeginbmatrix 1 rho_1 rho_2 rho_3 \nrho_1 1 rho_1 rho_2 \nrho_2 rho_1 1 rho_1 \nrho_3 rho_2 rho_1 1\nendbmatrixsigma^2\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.ToeplitzParameterized","page":"API","title":"Metida.ToeplitzParameterized","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.ToeplitzParameterized","category":"page"},{"location":"api/#Metida.ToeplitzParameterized","page":"API","title":"Metida.ToeplitzParameterized","text":"ToeplitzParameterized(p::Int)\n\nToeplitz covariance type with parameter p, (number of bands = p - 1, if p = 1 it's equal SI structure).\n\nTOEPP(p) = ToeplitzParameterized(p)\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.Unstructured","page":"API","title":"Metida.Unstructured","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.Unstructured","category":"page"},{"location":"api/#Metida.Unstructured","page":"API","title":"Metida.Unstructured","text":"Unstructured()\n\nUnstructured 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.\n\nUN = Unstructured()\n\n\n\n\n\n","category":"function"},{"location":"api/#Methods","page":"API","title":"Methods","text":"","category":"section"},{"location":"api/#Metida.caic","page":"API","title":"Metida.caic","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.caic","category":"page"},{"location":"api/#Metida.caic","page":"API","title":"Metida.caic","text":"caic(lmm::LMM)\n\nConditional Akaike Information Criterion.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.coefn","page":"API","title":"Metida.coefn","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.coefn","category":"page"},{"location":"api/#Metida.coefn","page":"API","title":"Metida.coefn","text":"coefn(lmm)\n\nCoef number.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.dof_satter","page":"API","title":"Metida.dof_satter","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.dof_satter","category":"page"},{"location":"api/#Metida.dof_satter","page":"API","title":"Metida.dof_satter","text":"dof_satter(lmm::LMM{T}, l) where T\n\nReturn Satterthwaite approximation for the denominator degrees of freedom, where l is a contrast vector (estimable linear combination of fixed effect coefficients vector (β).\n\ndf = frac2(LCL)^2gAg\n\nWhere: A = 2H^-1, g = triangledown_theta(LC^-1_thetaL)\n\n\n\n\n\ndof_satter(lmm::LMM{T}, n::Int) where T\n\nReturn Satterthwaite approximation for the denominator degrees of freedom, where n - coefficient number.\n\n\n\n\n\ndof_satter(lmm::LMM{T}) where T\n\nReturn Satterthwaite approximation for the denominator degrees of freedom for all coefficients.\n\n\n\n\n\ndof_satter(lmm::LMM{T}, l::Matrix) where T\n\nReturn Satterthwaite approximation for the denominator degrees of freedom for conrast matrix l.\n\nFor size(l, 1) > 1:\n\ndf = frac2EE - rank(LCL)\n\nwhere:\n\nlet LCL = QΛQ^-1, where QΛQ^-1 - spectral decomposition of LCL\nLq_i is the i-th row of Q^-1L\nA = 2H^-1, g = triangledown_theta(Lq_i C^-1_theta Lq_i)\nv_i = frac2*Λ_ii^2g * A * g\nE = sum_i=1^n fracv_i(v_i - 2) for v_i 2\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.estimate","page":"API","title":"Metida.estimate","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.estimate","category":"page"},{"location":"api/#Metida.estimate","page":"API","title":"Metida.estimate","text":"estimate(lmm, l::AbstractVector; level = 0.95, name = \"Estimate\")\n\nEstimate table for l vector. Satter DF used.\n\n\n\n\n\nestimate(lmm; level = 0.95)\n\nEstimates table. Satter DF used.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.getlog","page":"API","title":"Metida.getlog","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.getlog","category":"page"},{"location":"api/#Metida.getlog","page":"API","title":"Metida.getlog","text":"getlog(lmm::LMM)\n\nReturn fitting log.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.gmatrix","page":"API","title":"Metida.gmatrix","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.gmatrix","category":"page"},{"location":"api/#Metida.gmatrix","page":"API","title":"Metida.gmatrix","text":"gmatrix(lmm::LMM{T}, r::Int) where T\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.hessian","page":"API","title":"Metida.hessian","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.hessian","category":"page"},{"location":"api/#Metida.hessian","page":"API","title":"Metida.hessian","text":"hessian(lmm, theta)\n\nCalculate Hessian matrix of REML for theta.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.lcontrast","page":"API","title":"Metida.lcontrast","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.lcontrast","category":"page"},{"location":"api/#Metida.lcontrast","page":"API","title":"Metida.lcontrast","text":"lcontrast(lmm::LMM, i::Int)\n\nL-contrast matrix for i fixed effect.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.nblocks","page":"API","title":"Metida.nblocks","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.nblocks","category":"page"},{"location":"api/#Metida.nblocks","page":"API","title":"Metida.nblocks","text":"Number of blocks\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.rand","page":"API","title":"Metida.rand","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.rand","category":"page"},{"location":"api/#Base.rand","page":"API","title":"Base.rand","text":"rand(rng::AbstractRNG, lmm::LMM{T}) where T\n\nGenerate random responce vector for fitted 'lmm' model.\n\n\n\n\n\nrand(rng::AbstractRNG, lmm::LMM{T}; theta) where T\n\nGenerate random responce vector 'lmm' model, theta covariance vector, and zero means.\n\n\n\n\n\nrand(rng::AbstractRNG, lmm::LMM{T}; theta, beta) where T\n\nGenerate random responce vector 'lmm' model, theta covariance vector and mean's vector.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.rand-2","page":"API","title":"Metida.rand","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.rand!","category":"page"},{"location":"api/#Random.rand!","page":"API","title":"Random.rand!","text":"rand!(v::AbstractVector, lmm::LMM) = rand!(default_rng(), v, lmm, lmm.result.theta, lmm.result.beta)\n\nGenerate random responce vector for fitted 'lmm' model, store results in v.\n\n\n\n\n\nrand!(rng::AbstractRNG, lmm::LMM{T}; theta) where T\n\nGenerate random responce vector 'lmm' model, theta covariance vector, and zero means, store results in v.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.raneff","page":"API","title":"Metida.raneff","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.raneff","category":"page"},{"location":"api/#Metida.raneff","page":"API","title":"Metida.raneff","text":"raneff(lmm::LMM{T}, i)\n\nVector of random effect coefficients for block i.\n\n\n\n\n\nraneff(lmm::LMM{T})\n\nVector of random effect coefficients for all subjects by each random effect.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.raneffn","page":"API","title":"Metida.raneffn","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.raneffn","category":"page"},{"location":"api/#Metida.raneffn","page":"API","title":"Metida.raneffn","text":"raneffn(lmm)\n\nRetuen number of random effects.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.rankx","page":"API","title":"Metida.rankx","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.rankx","category":"page"},{"location":"api/#Metida.rankx","page":"API","title":"Metida.rankx","text":"rankx(lmm::LMM)\n\nReturn rank of X matrix.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.rmatrix","page":"API","title":"Metida.rmatrix","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.rmatrix","category":"page"},{"location":"api/#Metida.rmatrix","page":"API","title":"Metida.rmatrix","text":"rmatrix(lmm::LMM{T}, i::Int) where T\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.theta","page":"API","title":"Metida.theta","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.theta","category":"page"},{"location":"api/#Metida.theta","page":"API","title":"Metida.theta","text":"theta(lmm::LMM)\n\nReturn theta vector.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.thetalength","page":"API","title":"Metida.thetalength","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.thetalength","category":"page"},{"location":"api/#Metida.thetalength","page":"API","title":"Metida.thetalength","text":"thetalength(lmm::LMM)\n\nLength of theta vector.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.vmatrix","page":"API","title":"Metida.vmatrix","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.vmatrix","category":"page"},{"location":"api/#Metida.vmatrix","page":"API","title":"Metida.vmatrix","text":"vmatrix(lmm::LMM, i::Int)\n\nReturn variance-covariance matrix V for i bolock.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.vmatrix!","page":"API","title":"Metida.vmatrix!","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.vmatrix!","category":"page"},{"location":"api/#Metida.vmatrix!","page":"API","title":"Metida.vmatrix!","text":"vmatrix!(V, θ, lmm, i)\n\nUpdate variance-covariance matrix V for i bolock. Upper triangular updated.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.m2logreml","page":"API","title":"Metida.m2logreml","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.m2logreml","category":"page"},{"location":"api/#Metida.m2logreml","page":"API","title":"Metida.m2logreml","text":"m2logreml(lmm::LMM, θ = theta(lmm); maxthreads::Int = num_cores())\n\n-2 logREML\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.logreml","page":"API","title":"Metida.logreml","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.logreml","category":"page"},{"location":"api/#Metida.logreml","page":"API","title":"Metida.logreml","text":"logreml(lmm::LMM, θ = theta(lmm); maxthreads::Int = num_cores())\n\nlogREML\n\n\n\n\n\n","category":"function"},{"location":"api/#StatsAPI","page":"API","title":"StatsAPI","text":"","category":"section"},{"location":"api/#Metida.aic","page":"API","title":"Metida.aic","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.aic","category":"page"},{"location":"api/#StatsAPI.aic","page":"API","title":"StatsAPI.aic","text":"StatsBase.aic(lmm::LMM)\n\nAkaike Information Criterion.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.aicc","page":"API","title":"Metida.aicc","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.aicc","category":"page"},{"location":"api/#StatsAPI.aicc","page":"API","title":"StatsAPI.aicc","text":"StatsBase.aicc(lmm::LMM)\n\nCorrected Akaike Information Criterion.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.bic","page":"API","title":"Metida.bic","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.bic","category":"page"},{"location":"api/#StatsAPI.bic","page":"API","title":"StatsAPI.bic","text":"StatsBase.bic(lmm::LMM)\n\nBayesian information criterion.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.coef","page":"API","title":"Metida.coef","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.coef","category":"page"},{"location":"api/#StatsAPI.coef","page":"API","title":"StatsAPI.coef","text":"StatsBase.coef(lmm::LMM) = copy(lmm.result.beta)\n\nModel coefficients (β).\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.coefnames","page":"API","title":"Metida.coefnames","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.coefnames","category":"page"},{"location":"api/#StatsAPI.coefnames","page":"API","title":"StatsAPI.coefnames","text":"StatsBase.coefnames(lmm::LMM) = StatsBase.coefnames(lmm.mf)\n\nCoefficients names.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.coeftable","page":"API","title":"Metida.coeftable","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.coeftable","category":"page"},{"location":"api/#StatsAPI.coeftable","page":"API","title":"StatsAPI.coeftable","text":"coeftable(lmm::LMM)\n\nReturn coefficients table.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.confint","page":"API","title":"Metida.confint","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.confint","category":"page"},{"location":"api/#StatsAPI.confint","page":"API","title":"StatsAPI.confint","text":"StatsBase.confint(lmm::LMM{T}; level::Real=0.95, ddf::Symbol = :satter) where T\n\nConfidece interval for coefficients.\n\nddf = :satter/:residual\n\nCI_UL = β SE * t_ddf 1-α2\n\nSee also: dof_satter, dof_residual\n\n\n\n\n\nStatsBase.confint(lmm::LMM{T}, i::Int; level::Real=0.95, ddf::Symbol = :satter) where T\n\nConfidece interval for coefficient i.\n\n\n\n\n\nStatsBase.confint(br::BootstrapResult, n::Int; level::Float64=0.95, method=:bp, metric = :coef, delrml = false)\n\nConfidence interval for bootstrap result.\n\n*method:\n\n:bp - bootstrap percentile;\n:rbp - reverse bootstrap percentile;\n:norm - Normal distribution;\n:bcnorm - Bias corrected Normal distribution;\n:jn - bias corrected (jackknife resampling).\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.crossmodelmatrix","page":"API","title":"Metida.crossmodelmatrix","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.crossmodelmatrix","category":"page"},{"location":"api/#StatsAPI.crossmodelmatrix","page":"API","title":"StatsAPI.crossmodelmatrix","text":"crossmodelmatrix(lmm::LMM)\n\nReturn X'X.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.dof","page":"API","title":"Metida.dof","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.dof","category":"page"},{"location":"api/#StatsAPI.dof","page":"API","title":"StatsAPI.dof","text":"StatsBase.dof(lmm::LMM)\n\nDOF.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.dof_residual","page":"API","title":"Metida.dof_residual","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.dof_residual","category":"page"},{"location":"api/#StatsAPI.dof_residual","page":"API","title":"StatsAPI.dof_residual","text":"StatsBase.dof_residual(lmm::LMM)\n\nDOF residuals: N - rank(X), where N - total number of observations.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.fit","page":"API","title":"Metida.fit","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.fit","category":"page"},{"location":"api/#StatsAPI.fit","page":"API","title":"StatsAPI.fit","text":"fit(::Type{T}, f::FormulaTerm, data;\ncontrasts=Dict{Symbol,Any}(), \nrandom::Union{Nothing, VarEffect, Vector{VarEffect}} = nothing, \nrepeated::Union{Nothing, VarEffect} = nothing,\nkwargs...)\n\nFit LMM model with @formula.\n\nKeywords see fit!\n\n\n\n\n\nfit(::Type{T}, f::LMMformula, data;\ncontrasts=Dict{Symbol,Any}(), \nkwargs...) where T <: LMM\n\nFit LMM model with @lmmformula.\n\nKeywords see fit!\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.fit-2","page":"API","title":"Metida.fit","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.fit!","category":"page"},{"location":"api/#StatsAPI.fit!","page":"API","title":"StatsAPI.fit!","text":"fit!(lmm::LMM{T}; kwargs...\n) where T\n\nFit LMM model.\n\nKeywords:\n\nsolver - :default / :nlopt for using with MetidaNLopt.jl/ :cuda for using with MetidaCu.jl\nverbose - :auto / 1 / 2 / 3 - - 1 - only log, 2 - log and print, 3 - print only errors, other log, 0 (or any other value) - no logging\nvarlinkf - :exp / :sq / :identity ref\nrholinkf - :sigm / :atan / :sqsigm / :psigm\naifirst - first iteration with AI-like method - :default / :ai / :score\naifmax - maximum pre-optimization steps\ng_tol - absolute tolerance in the gradient\nx_tol - absolute tolerance of theta vector\nf_tol - absolute tolerance in changes of the REML\nhes - calculate REML Hessian\ninit - initial theta values\nio - output IO\ntime_limit - time limit = 120 sec\niterations - maximum iterations = 300\nrefitinit - true/false - if true - use last values for initial condition (false by default)\noptmethod - Optimization method. Look at Optim.jl documentation. (Newton by default)\nsingtol - singular tolerance = 1e-8\nmaxthreads - maximum threads = min(num_cores(), Threads.nthreads())\n\n\n\n\n\n","category":"function"},{"location":"api/#islinear","page":"API","title":"islinear","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.islinear ","category":"page"},{"location":"api/#StatsAPI.islinear","page":"API","title":"StatsAPI.islinear","text":"StatsBase.islinear(model::LMM)\n\n\n\n\n\n","category":"function"},{"location":"api/#isfitted","page":"API","title":"isfitted","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.isfitted","category":"page"},{"location":"api/#StatsAPI.isfitted","page":"API","title":"StatsAPI.isfitted","text":"StatsBase.isfitted(lmm::LMM)\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.loglikelihood","page":"API","title":"Metida.loglikelihood","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.loglikelihood","category":"page"},{"location":"api/#StatsAPI.loglikelihood","page":"API","title":"StatsAPI.loglikelihood","text":"StatsBase.loglikelihood(lmm::LMM)\n\nReturn loglikelihood value.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.modelmatrix","page":"API","title":"Metida.modelmatrix","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.modelmatrix","category":"page"},{"location":"api/#StatsAPI.modelmatrix","page":"API","title":"StatsAPI.modelmatrix","text":"StatsBase.modelmatrix(lmm::LMM)\n\nFixed effects matrix.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.nobs","page":"API","title":"Metida.nobs","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.nobs","category":"page"},{"location":"api/#StatsAPI.nobs","page":"API","title":"StatsAPI.nobs","text":"StatsBase.nobs(lmm::MetiaModel)\n\nNumber of observations.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.response","page":"API","title":"Metida.response","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.response","category":"page"},{"location":"api/#StatsAPI.response","page":"API","title":"StatsAPI.response","text":"StatsBase.response(lmm::LMM)\n\nResponse vector.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.responsename","page":"API","title":"Metida.responsename","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.responsename","category":"page"},{"location":"api/#StatsAPI.responsename","page":"API","title":"StatsAPI.responsename","text":"responsename(lmm::LMM)\n\nResponce varible name.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.stderror","page":"API","title":"Metida.stderror","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.stderror","category":"page"},{"location":"api/#StatsAPI.stderror","page":"API","title":"StatsAPI.stderror","text":"StatsBase.stderror(lmm::LMM)\n\nStandard error\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.vcov","page":"API","title":"Metida.vcov","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.vcov","category":"page"},{"location":"api/#StatsAPI.vcov","page":"API","title":"StatsAPI.vcov","text":"StatsBase.vcov(lmm::LMM)\n\nVariance-covariance matrix of β.\n\n\n\n\n\n","category":"function"},{"location":"api/#Experimental","page":"API","title":"Experimental","text":"","category":"section"},{"location":"api/#Metida.SpatialExponentialD","page":"API","title":"Metida.SpatialExponentialD","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.SpatialExponentialD","category":"page"},{"location":"api/#Metida.SpatialExponentialD","page":"API","title":"Metida.SpatialExponentialD","text":"SpatialExponentialD()\n\nwarning: Warning\nExperimental\n\nSame as SpatialExponential, but add D to all diagonal elements.\n\nSPEXPD = SpatialExponentialD()\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.SpatialGaussianD","page":"API","title":"Metida.SpatialGaussianD","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.SpatialGaussianD","category":"page"},{"location":"api/#Metida.SpatialGaussianD","page":"API","title":"Metida.SpatialGaussianD","text":"SpatialGaussianD()\n\nwarning: Warning\nExperimental\n\nSame as SpatialGaussianD, but add D to all diagonal elements.\n\nSPGAUD = SpatialGaussianD()\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.SpatialPowerD","page":"API","title":"Metida.SpatialPowerD","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.SpatialPowerD","category":"page"},{"location":"api/#Metida.SpatialPowerD","page":"API","title":"Metida.SpatialPowerD","text":"SpatialPowerD()\n\nwarning: Warning\nExperimental\n\nSame as SpatialPower, but add D to all diagonal elements.\n\nSPPOWD = SpatialPowerD()\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.ScaledWeightedCov","page":"API","title":"Metida.ScaledWeightedCov","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.ScaledWeightedCov","category":"page"},{"location":"api/#Metida.ScaledWeightedCov","page":"API","title":"Metida.ScaledWeightedCov","text":"ScaledWeightedCov(wtsm::AbstractMatrix{T})\n\nwarning: Warning\nExperimental\n\nScaled weighted covariance matrix, where wtsm - NxN within block correlation matrix (N - total number of observations). Used only for repeated effect. \n\nSWC = ScaledWeightedCov\n\nR = Corr(W) * sigma_c^2\n\nwhere Corr(W) - diagonal correlation matrix. \n\nexample:\n\nmatwts = Symmetric(UnitUpperTriangular(rand(size(df0,1), size(df0,1))))\nlmm = LMM(@formula(var~sequence+period+formulation), df0;\n repeated = VarEffect(@covstr(1|subject), SWC(matwts)))\nfit!(lmm)\n\n\nnote: Note\n\n\nThere is no wtsm checks for symmetricity or values.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.dof_contain","page":"API","title":"Metida.dof_contain","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.dof_contain","category":"page"},{"location":"api/#Metida.dof_contain","page":"API","title":"Metida.dof_contain","text":"dof_contain(lmm, i)\n\nwarning: Warning\nExperimental! 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.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.typeiii","page":"API","title":"Metida.typeiii","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.typeiii","category":"page"},{"location":"api/#Metida.typeiii","page":"API","title":"Metida.typeiii","text":"typeiii(lmm::LMM{T}; ddf::Symbol = :satter) where T\n\nwarning: Warning\nExperimental\n\nType III table.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.MILMM","page":"API","title":"Metida.MILMM","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.MILMM","category":"page"},{"location":"api/#Metida.MILMM","page":"API","title":"Metida.MILMM","text":"MILMM(lmm::LMM, data)\n\nMultiple imputation model.\n\n\n\n\n\n","category":"type"},{"location":"api/#Metida.RawCoding","page":"API","title":"Metida.RawCoding","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.RawCoding","category":"page"},{"location":"api/#Metida.RawCoding","page":"API","title":"Metida.RawCoding","text":"mutable struct RawCoding <: AbstractContrasts\n\nContrast for CategoricalTerm to get column \"as it is\" for model matrix.\n\n\n\n\n\n","category":"type"},{"location":"api/#Not-API-functions","page":"API","title":"Not API functions","text":"","category":"section"},{"location":"api/#Metida.contrast","page":"API","title":"Metida.contrast","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.contrast","category":"page"},{"location":"api/#Metida.contrast","page":"API","title":"Metida.contrast","text":"contrast(lmm, l::AbstractMatrix; name::String = \"Contrast\", ddf = :satter)\n\nUser contrast table. ddf = :satter or :residual or any number for direct ddf setting.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.fvalue","page":"API","title":"Metida.fvalue","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.fvalue","category":"page"},{"location":"api/#Metida.fvalue","page":"API","title":"Metida.fvalue","text":"fvalue(lmm::LMM, l::Matrix)\n\nF value for contrast matrix l.\n\nF = fracbetaL(LCL)^-1Lbetarank(LCL)\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.mulαβαtinc","page":"API","title":"Metida.mulαβαtinc","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.mulαβαtinc!","category":"page"},{"location":"api/#Metida.mulαβαtinc!","page":"API","title":"Metida.mulαβαtinc!","text":"mulαβαtinc!(θ::AbstractMatrix, A::AbstractMatrix, B::AbstractMatrix)\n\nθ + A * B * A'\n\nChange θ (only upper triangle). B is symmetric.\n\n\n\n\n\nmulαβαtinc!(θ::AbstractMatrix, A::AbstractMatrix, B::AbstractMatrix, alpha)\n\nθ + A * B * A' * alpha\n\nChange θ (only upper triangle). B is symmetric.\n\n\n\n\n\nmulαβαtinc!(θ::AbstractVector{T}, A::AbstractMatrix, B::AbstractMatrix, a::AbstractVector, b::AbstractVector, alpha) where T\n\nθ + A * B * (a - b) * alpha\n\nChange θ (only upper triangle). B is symmetric.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.mulθ","page":"API","title":"Metida.mulθ₃","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.mulθ₃","category":"page"},{"location":"api/#Metida.mulθ₃","page":"API","title":"Metida.mulθ₃","text":"mulθ₃(y, X, β, V::AbstractMatrix{T})::T where T\n\n(y - X * β)' * (-V) * (y - X * β)\n\nuse only upper triangle of V\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.mulαtβinc","page":"API","title":"Metida.mulαtβinc","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.mulαtβinc!","category":"page"},{"location":"api/#Metida.mulαtβinc!","page":"API","title":"Metida.mulαtβinc!","text":"mulαtβinc!(θ::AbstractVector{T}, A::AbstractMatrix, b::AbstractVector) where T\n\nθ + A' * b\n\nChange θ.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.tname","page":"API","title":"Metida.tname","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.tname ","category":"page"},{"location":"api/#Metida.tname","page":"API","title":"Metida.tname","text":"Term name.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.raneflenv","page":"API","title":"Metida.raneflenv","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.raneflenv ","category":"page"},{"location":"api/#Metida.raneflenv","page":"API","title":"Metida.raneflenv","text":"Return number of subject foe each random effet in current block.\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.edistance","page":"API","title":"Metida.edistance","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.edistance ","category":"page"},{"location":"api/#Metida.edistance","page":"API","title":"Metida.edistance","text":"edistance(mx::AbstractMatrix{T}, i::Int, j::Int) where T\n\nDistance between vector mx[i, :] and mx[j, :].\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.m2logml","page":"API","title":"Metida.m2logml","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.m2logml ","category":"page"},{"location":"api/#Metida.m2logml","page":"API","title":"Metida.m2logml","text":"m2logml(lmm::LMM, β = coef(lmm), θ = theta(lmm); maxthreads::Int = num_cores())\n\n-2 logML\n\n\n\n\n\n","category":"function"},{"location":"api/#Metida.logml","page":"API","title":"Metida.logml","text":"","category":"section"},{"location":"api/","page":"API","title":"API","text":"Metida.logml ","category":"page"},{"location":"api/#Metida.logml","page":"API","title":"Metida.logml","text":"logml(lmm::LMM, beta = coef(lmm), θ = theta(lmm); maxthreads::Int = num_cores())\n\nlogML\n\n\n\n\n\n","category":"function"},{"location":"custom/#Custom-structures","page":"Custom structures","title":"Custom structures","text":"","category":"section"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"To make your own covariance structure first you should make struct that <: AbstractCovarianceType:","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"Example:","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"struct YourCovarianceStruct <: AbstractCovarianceType end","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"You also can specify additional field if you need to use them inside gmat!/rmat! functions.","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"Then you can make function for construction random effect matrix (gmat!) and repeated effect (rmat!). Only upper triangular can be updated.","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"Function gmat! have 3 arguments: mx - zero matrix, θ - theta vector for this effect, and your custom structure object.","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"Next this function used to make \"random\" part of variance-covariance matrix: V' = Z * G * Z'","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"function Metida.gmat!(mx, θ, ::YourCovarianceStruct)\n @inbounds @simd for i = 1:size(mx, 1)\n mx[i, i] = θ[i] ^ 2\n end\n nothing\nend","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"Function rmat! have 5 arguments and add repeated effect to V': V = V' + R (so V = Z * G * Z' + R), mx - V' matrix, θ - theta vector for this effect, rz - subject effect matrix, ct - your covariance type object, sb = block number. For example, rmat! for Heterogeneous Toeplitz Parameterized structure is specified bellow (TOEPHP_ <: AbstractCovarianceType).","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"function Metida.rmat!(mx, θ, rz, ct::TOEPHP_, ::Int)\n l = size(rz, 2)\n vec = rz * (θ[1:l])\n s = size(mx, 1)\n if s > 1 && ct.p > 1\n for m = 1:s - 1\n for n = m + 1:(m + ct.p - 1 > s ? s : m + ct.p - 1)\n @inbounds mx[m, n] += vec[m] * vec[n] * θ[n - m + l]\n end\n end\n end\n @inbounds @simd for m = 1:s\n mx[m, m] += vec[m] * vec[m]\n end\n nothing\nend","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"One more function you shoud make is covstrparam, this function need to know how many parameters included in theta vector for optimization. Function returns number of variance parameters and rho parameters for this structure. Where t - number of columns in individual Z matrix for random effect or number of columns in repeated effect matrix (rZ).","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"Example for Heterogeneous Autoregressive and Heterogeneous Compound Symmetry structures:","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"function Metida.covstrparam(ct::Union{ARH_, CSH_}, t::Int)::Tuple{Int, Int}\n return (t, 1)\nend","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"For better printing you can add:","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"function Metida.rcoefnames(s, t, ct::YourCovarianceStruct)\n return [\"σ² \", \"γ \", \"ρ \"]\nend","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"Where, s - effect schema, t - number of parameters, this function returns names for your covariance structure for printing in LMM output.","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"Add this method for better printing:","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"function Base.show(io::IO, ct::YourCovarianceStruct)\n print(io, \"YourCovarianceStruct\")\nend","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"Then just make model and fit it:","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"lmm = Metida.LMM(@formula(response ~ 1 + factor*time), ftdf2;\n random = Metida.VarEffect(Metida.@covstr(factor|subject&factor), YourCovarianceStruct()),\n repeated = Metida.VarEffect(Metida.@covstr(1|subject&factor), YourCovarianceStruct()),\n )\n Metida.fit!(lmm)","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"Example:","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"using Metida, DataFrames, CSV, CategoricalArrays\n\nspatdf = CSV.File(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"csv\", \"spatialdata.csv\"); types = [Int, Int, String, Float64, Float64, Float64, Float64, Float64]) |> DataFrame\nftdf = CSV.File(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"csv\", \"1fptime.csv\"); types = [String, String, Float64, Float64]) |> DataFrame\ndf0 = CSV.File(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"csv\", \"df0.csv\"); types = [String, String, String, String,Float64, Float64, Float64]) |> DataFrame\n\nstruct CustomCovarianceStructure <: Metida.AbstractCovarianceType end\nfunction Metida.covstrparam(ct::CustomCovarianceStructure, t::Int)::Tuple{Int, Int}\n return (t, 1)\nend\nfunction Metida.gmat!(mx, θ, ct::CustomCovarianceStructure)\n s = size(mx, 1)\n @inbounds @simd for m = 1:s\n mx[m, m] = θ[m]\n end\n if s > 1\n for m = 1:s - 1\n @inbounds @simd for n = m + 1:s\n mx[m, n] = mx[m, m] * mx[n, n] * θ[end]\n end\n end\n end\n @inbounds @simd for m = 1:s\n mx[m, m] = mx[m, m] * mx[m, m]\n end\n nothing\nend\n\nlmm = Metida.LMM(@formula(response ~1 + factor*time), ftdf;\nrandom = Metida.VarEffect(Metida.@covstr(1 + time|subject&factor), CustomCovarianceStructure()),\n)\nMetida.fit!(lmm)\n\n# for R matrix\n\nfunction Metida.rmat!(mx, θ, rz, ::CustomCovarianceStructure, ::Int)\n vec = Metida.tmul_unsafe(rz, θ)\n rn = size(mx, 1)\n if rn > 1\n for m = 1:rn - 1\n @inbounds @simd for n = m + 1:rn\n mx[m, n] += vec[m] * vec[n] * θ[end]\n end\n end\n end\n @inbounds for m ∈ axes(mx, 1)\n mx[m, m] += vec[m] * vec[m]\n end\n nothing\nend\n\nlmm = Metida.LMM(@formula(var~sequence+period+formulation), df0;\nrepeated = Metida.VarEffect(Metida.@covstr(period|subject), CustomCovarianceStructure()),\n)\nMetida.fit!(lmm)","category":"page"},{"location":"custom/#Custom-distance-estimation-for-spatial-structures","page":"Custom structures","title":"Custom distance estimation for spatial structures","text":"","category":"section"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"If you want to use coordinates or some other structures for distance estimation you can define method Metida.edistance to calculate distance:","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"function Metida.edistance(mx::AbstractMatrix{<:CartesianIndex}, i::Int, j::Int)\n return sqrt((mx[i, 1][1] - mx[j, 1][1])^2 + (mx[i, 1][2] - mx[j, 1][2])^2)\nend","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"For example this method returns distance between two vectors represented as CartesianIndex.","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"Make vector of CartesianIndex:","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"spatdf.ci = map(x -> CartesianIndex(x[:x], x[:y]), eachrow(spatdf))","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"Then use new column as \"raw\" variable with Metida.RawCoding contrast and fit the model:","category":"page"},{"location":"custom/","page":"Custom structures","title":"Custom structures","text":"lmm = Metida.LMM(@formula(r2 ~ f), spatdf;\n repeated = Metida.VarEffect(Metida.@covstr(ci|1), Metida.SPEXP; coding = Dict(:ci => Metida.RawCoding())),\n )\nMetida.fit!(lmm)","category":"page"},{"location":"examples/#Example-1-Continuous-and-categorical-predictors","page":"Examples","title":"Example 1 - Continuous and categorical predictors","text":"","category":"section"},{"location":"examples/","page":"Examples","title":"Examples","text":"using Metida, CSV, DataFrames, CategoricalArrays, MixedModels;\n\nrds = CSV.File(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"csv\", \"1fptime.csv\"); types = [String, String, Float64, Float64]) |> DataFrame\n\nnothing; # hide","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"(Image: )","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"Metida result:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"lmm = LMM(@formula(response ~1 + factor*time), rds;\nrandom = VarEffect(@covstr(1 + time|subject&factor), CSH),\n)\nfit!(lmm)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"MixedModels result:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"fm = @formula(response ~ 1 + factor*time + (1 + time|subject&factor))\nmm = fit(MixedModel, fm, rds, REML=true)\nprintln(mm) #hide","category":"page"},{"location":"examples/#Example-2-Two-random-factors-(Penicillin-data)","page":"Examples","title":"Example 2 - Two random factors (Penicillin data)","text":"","category":"section"},{"location":"examples/","page":"Examples","title":"Examples","text":"Metida:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"\ndf = CSV.File(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"csv\", \"Penicillin.csv\"); types = [String, Float64, String, String]) |> DataFrame\ndf.diameter = float.(df.diameter)\n\nlmm = LMM(@formula(diameter ~ 1), df;\nrandom = [VarEffect(@covstr(1|plate), SI), VarEffect(@covstr(1|sample), SI)]\n)\nfit!(lmm)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"MixedModels:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"\nfm2 = @formula(diameter ~ 1 + (1|plate) + (1|sample))\nmm = fit(MixedModel, fm2, df, REML=true)\nprintln(mm) #hide","category":"page"},{"location":"examples/#Example-3-Repeated-ARMA/AR/ARH","page":"Examples","title":"Example 3 - Repeated ARMA/AR/ARH","text":"","category":"section"},{"location":"examples/","page":"Examples","title":"Examples","text":"rds = CSV.File(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"csv\", \"1freparma.csv\"); types = [String, String, Float64, Float64]) |> DataFrame\n\nnothing # hide","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"(Image: )","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"ARMA:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"lmm = LMM(@formula(response ~ 1 + factor*time), rds;\nrandom = VarEffect(@covstr(factor|subject&factor), DIAG),\nrepeated = VarEffect(@covstr(1|subject&factor), ARMA),\n)\nfit!(lmm)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"AR:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"lmm = Metida.LMM(@formula(response ~ 1 + factor*time), rds;\nrandom = VarEffect(@covstr(factor|subject&factor), DIAG),\nrepeated = VarEffect(@covstr(1|subject&factor), AR),\n)\nfit!(lmm)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"ARH:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"lmm = Metida.LMM(@formula(response ~ 1 + factor*time), rds;\nrandom = VarEffect(@covstr(factor|subject&factor), DIAG),\nrepeated = VarEffect(@covstr(1|subject&factor), ARH),\n)\nfit!(lmm)","category":"page"},{"location":"examples/#Example-4-SAS-relation","page":"Examples","title":"Example 4 - SAS relation","text":"","category":"section"},{"location":"examples/#Model-1","page":"Examples","title":"Model 1","text":"","category":"section"},{"location":"examples/","page":"Examples","title":"Examples","text":"df0 = CSV.File(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"csv\", \"df0.csv\")) |> DataFrame\n\nlmm = LMM(@formula(var ~ sequence + period + formulation), df0;\nrandom = VarEffect(@covstr(formulation|subject), CSH),\nrepeated = VarEffect(@covstr(formulation|subject), DIAG),\n)\nfit!(lmm)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"SAS code:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"PROC MIXED data=df0;\nCLASSES subject sequence period formulation;\nMODEL var = sequence period formulation/ DDFM=SATTERTH s;\nRANDOM formulation/TYPE=CSH SUB=subject G V;\nREPEATED/GRP=formulation SUB=subject R;\nRUN;","category":"page"},{"location":"examples/#Model-2","page":"Examples","title":"Model 2","text":"","category":"section"},{"location":"examples/","page":"Examples","title":"Examples","text":"lmm = LMM(\n @formula(var ~ sequence + period + formulation), df0;\n random = VarEffect(@covstr(formulation|subject), SI),\n repeated = VarEffect(@covstr(formulation|subject), DIAG),\n)\nfit!(lmm)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"SAS code:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"PROC MIXED data=df0;\nCLASSES subject sequence period formulation;\nMODEL var = sequence period formulation/ DDFM=SATTERTH s;\nRANDOM formulation/TYPE=VC SUB=subject G V;\nREPEATED/GRP=formulation SUB=subject R;\nRUN;","category":"page"},{"location":"examples/#Model-3","page":"Examples","title":"Model 3","text":"","category":"section"},{"location":"examples/","page":"Examples","title":"Examples","text":"lmm = LMM(@formula(var ~ sequence + period + formulation), df0;\n random = VarEffect(@covstr(subject|1), SI)\n )\nfit!(lmm)","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"SAS code:","category":"page"},{"location":"examples/","page":"Examples","title":"Examples","text":"PROC MIXED data=df0;\nCLASSES subject sequence period formulation;\nMODEL var = sequence period formulation/ DDFM=SATTERTH s;\nRANDOM subject/TYPE=VC G V;\nRUN;","category":"page"},{"location":"examples/#Example-5-Working-with-Effects.jl","page":"Examples","title":"Example 5 - Working with Effects.jl","text":"","category":"section"},{"location":"examples/","page":"Examples","title":"Examples","text":"using Effects, StatsModels\n\nlmm = LMM(@formula(var ~ sequence + period + formulation), df0;\n random = VarEffect(@covstr(subject|1), SI)\n )\nfit!(lmm)\n\ntable_model = StatsModels.TableRegressionModel(lmm, lmm.mf, lmm.mm)\n\nemmeans(tm)\n\neffects(Dict(:period => [\"1\", \"2\", \"3\", \"4\"]), tm)","category":"page"},{"location":"validation/#Validation","page":"Validation","title":"Validation","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"Validation provided with 3 sections:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"REML validation for public datasets with Metida & SPSS\nParameters validation for public datasets Metida & SPSS & MixedModels\nValidation with bioequivalence datasets with Metida & SPSS","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"To run validation:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"using Metida; include(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"validation.jl\"))","category":"page"},{"location":"validation/#Section-1:-REML-validation-for-public-datasets-Metida-and-SPSS","page":"Validation","title":"Section 1: REML validation for public datasets Metida & SPSS","text":"","category":"section"},{"location":"validation/#REML-result-table","page":"Validation","title":"REML result table","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"Model DataSet Used cov. types REML Metida REML SPSS\n1 sleepstudy.csv SI/SI 1729.4925602367025 1729.492560\n2 sleepstudy.csv CS/SI 1904.3265170722132 1904.327\n3 sleepstudy.csv CSH/SI 1772.0953251997046 1772.095\n4 sleepstudy.csv ARH/SI 1730.1895427398322 1730.189543\n5 Pastes.csv SI,SI/SI 246.99074585348623 246.990746\n6 Pastes.csv ARMA/SI 246.81895071012508 246.818951\n7 Penicillin.csv SI,SI/SI 330.86058899109184 330.860589\n8 RepeatedPulse.csv SI/AR 453.3395435627574 453.339544\n9 RepeatedPulse.csv 0/AR 471.85107712169827 471.851077\n10 RepeatedPulse.csv AR/SI 453.3395560121246 453.339555","category":"page"},{"location":"validation/#sleepstudy.csv","page":"Validation","title":"sleepstudy.csv","text":"","category":"section"},{"location":"validation/#Model-1","page":"Validation","title":"Model 1","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"lmm = LMM(@formula(Reaction~Days), df;\n random = VarEffect(@covstr(1|Subject), SI),\n )\n fit!(lmm)","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"SPSS:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"MIXED Reaction BY Days\n /CRITERIA=DFMETHOD(SATTERTHWAITE) CIN(95) MXITER(100) MXSTEP(10) SCORING(1)\n SINGULAR(0.000000000001) HCONVERGE(0, ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE)\n /FIXED=Days | SSTYPE(3)\n /METHOD=REML\n /RANDOM=INTERCEPT | SUBJECT(Subject) COVTYPE(ID).","category":"page"},{"location":"validation/#Model-2","page":"Validation","title":"Model 2","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"lmm = LMM(@formula(Reaction~1), df;\n random = VarEffect(Metida.@covstr(Days|Subject), CS),\n )\n fit!(lmm)","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"SPSS:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"MIXED Reaction BY Days\n /CRITERIA=DFMETHOD(SATTERTHWAITE) CIN(95) MXITER(100) MXSTEP(10) SCORING(1)\n SINGULAR(0.000000000001) HCONVERGE(0, ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE)\n /FIXED=INTERCEPT | SSTYPE(3)\n /METHOD=REML\n /RANDOM=Days | SUBJECT(Subject) COVTYPE(CS).","category":"page"},{"location":"validation/#Model-3","page":"Validation","title":"Model 3","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"lmm = LMM(@formula(Reaction~1), df;\n random = VarEffect(@covstr(Days|Subject), CSH)\n )\n fit!(lmm)","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"SPSS:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"MIXED Reaction BY Days\n /CRITERIA=DFMETHOD(SATTERTHWAITE) CIN(95) MXITER(100) MXSTEP(10) SCORING(1)\n SINGULAR(0.000000000001) HCONVERGE(0, ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE)\n /FIXED=INTERCEPT | SSTYPE(3)\n /METHOD=REML\n /RANDOM=Days | SUBJECT(Subject) COVTYPE(CSH).","category":"page"},{"location":"validation/#Model-4","page":"Validation","title":"Model 4","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"lmm = LMM(@formula(Reaction~1), df;\n random = VarEffect(@covstr(Days|Subject), ARH)\n )\n fit!(lmm)","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"SPSS:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"MIXED Reaction BY Days\n /CRITERIA=DFMETHOD(SATTERTHWAITE) CIN(95) MXITER(100) MXSTEP(10) SCORING(1)\n SINGULAR(0.000000000001) HCONVERGE(0, ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE)\n /FIXED=INTERCEPT | SSTYPE(3)\n /METHOD=REML\n /RANDOM=Days | SUBJECT(Subject) COVTYPE(ARH1).","category":"page"},{"location":"validation/#pastes.csv","page":"Validation","title":"pastes.csv","text":"","category":"section"},{"location":"validation/#Model-5","page":"Validation","title":"Model 5","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"lmm = LMM(@formula(strength~1), df;\nrandom = [VarEffect(@covstr(1|batch), SI), VarEffect(@covstr(1|batch & cask), SI)]\n)\nfit!(lmm)","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"SPSS:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"MIXED strength\n /CRITERIA=DFMETHOD(SATTERTHWAITE) CIN(95) MXITER(100) MXSTEP(10) SCORING(1)\n SINGULAR(0.000000000001) HCONVERGE(0, ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE)\n /FIXED=| SSTYPE(3)\n /METHOD=REML\n /RANDOM=INTERCEPT | SUBJECT(batch) COVTYPE(ID)\n /RANDOM=INTERCEPT | SUBJECT(cask * batch) COVTYPE(ID).","category":"page"},{"location":"validation/#Model-6","page":"Validation","title":"Model 6","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"lmm = LMM(@formula(strength~1), df;\nrandom = VarEffect(Metida.@covstr(cask|batch), ARMA),\n)\nfit!(lmm)","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"SPSS:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"MIXED strength by cask\n /CRITERIA=DFMETHOD(SATTERTHWAITE) CIN(95) MXITER(100) MXSTEP(10) SCORING(1)\n SINGULAR(0.000000000001) HCONVERGE(0, ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE)\n /FIXED=| SSTYPE(3)\n /METHOD=REML\n /RANDOM=cask | SUBJECT(batch) COVTYPE(ARMA11).","category":"page"},{"location":"validation/#penicillin.csv","page":"Validation","title":"penicillin.csv","text":"","category":"section"},{"location":"validation/#Model-7","page":"Validation","title":"Model 7","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"lmm = LMM(@formula(diameter ~ 1), df;\nrandom = [VarEffect(@covstr(1|plate), SI), VarEffect(@covstr(1|sample), SI)]\n)\nfit!(lmm)","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"SPSS:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"MIXED diameter\n /CRITERIA=DFMETHOD(SATTERTHWAITE) CIN(95) MXITER(100) MXSTEP(10) SCORING(1)\n SINGULAR(0.000000000001) HCONVERGE(0, ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE)\n /FIXED=| SSTYPE(3)\n /METHOD=REML\n /RANDOM=INTERCEPT | SUBJECT(plate) COVTYPE(ID)\n /RANDOM=INTERCEPT | SUBJECT(sample) COVTYPE(ID).","category":"page"},{"location":"validation/#RepeatedPulse.csv","page":"Validation","title":"RepeatedPulse.csv","text":"","category":"section"},{"location":"validation/#Model-8","page":"Validation","title":"Model 8","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"sort!(df, :Day)\nlmm = LMM(@formula(Pulse~1), df;\nrandom = VarEffect(Metida.@covstr(Time|Time), SI),\nrepeated = VarEffect(Metida.@covstr(Day|Time), AR),\n)\nfit!(lmm)","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"SPSS:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"MIXED Pulse BY Day Time\n /CRITERIA=DFMETHOD(SATTERTHWAITE) CIN(95) MXITER(100) MXSTEP(10) SCORING(1)\n SINGULAR(0.000000000001) HCONVERGE(0, ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE)\n /FIXED=| SSTYPE(3)\n /METHOD=REML\n /RANDOM=Time | SUBJECT(Time) COVTYPE(ID)\n /REPEATED = Day | SUBJCET(Time) COVTYPE(AR1).","category":"page"},{"location":"validation/#Model-9","page":"Validation","title":"Model 9","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"sort!(df, :Day)\nlmm = LMM(@formula(Pulse~1), df;\nrepeated = VarEffect(Metida.@covstr(Day|Time), AR),\n)\n fit!(lmm)","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"SPSS:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"MIXED Pulse BY Day Time\n /CRITERIA=DFMETHOD(SATTERTHWAITE) CIN(95) MXITER(100) MXSTEP(10) SCORING(1)\n SINGULAR(0.000000000001) HCONVERGE(0, ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE)\n /FIXED=| SSTYPE(3)\n /METHOD=REML\n /REPEATED = Day | SUBJCET(Time) COVTYPE(AR1).","category":"page"},{"location":"validation/#Model-10","page":"Validation","title":"Model 10","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"sort!(df, :Day)\nlmm = LMM(@formula(Pulse~1), df;\nrandom = VarEffect(Metida.@covstr(Day|Time), AR),\n)\n fit!(lmm)","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"SPSS:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"MIXED Pulse BY Day Time\n /CRITERIA=DFMETHOD(SATTERTHWAITE) CIN(95) MXITER(100) MXSTEP(10) SCORING(1)\n SINGULAR(0.000000000001) HCONVERGE(0, ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE)\n /FIXED=| SSTYPE(3)\n /METHOD=REML\n /RANDOM=Day | SUBJECT(Time) COVTYPE(AR1).","category":"page"},{"location":"validation/#Section-2:-Parameters-validation-for-public-datasets-Metida-and-SPSS-and-MixedModels","page":"Validation","title":"Section 2: Parameters validation for public datasets Metida & SPSS & MixedModels","text":"","category":"section"},{"location":"validation/#Model-7-2","page":"Validation","title":"Model 7","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"Metida:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"lmm = LMM(@formula(diameter ~ 1), df;\nrandom = [VarEffect(@covstr(1|plate), SI), VarEffect(@covstr(1|sample), SI)]\n)\nfit!(lmm)","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"MixedModels:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"fm = @formula(diameter ~ 1 + (1|plate) + (1|sample))\nmm = fit(MixedModel, fm, df, REML=true)","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"SPSS:","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"MIXED diameter\n /CRITERIA=DFMETHOD(SATTERTHWAITE) CIN(95) MXITER(100) MXSTEP(10) SCORING(1)\n SINGULAR(0.000000000001) HCONVERGE(0, ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE)\n /FIXED=| SSTYPE(3)\n /METHOD=REML\n /EMMEANS=TABLES(OVERALL)\n /RANDOM=INTERCEPT | SUBJECT(plate) COVTYPE(ID)\n /RANDOM=INTERCEPT | SUBJECT(sample) COVTYPE(ID).","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"Model Parameter Value Metida Value MM Value SPSS\n7 (Intercept) estimate 22.9722 22.9722 22.972\n7 (Intercept) SE 0.808573 0.808572 0.809\n7 plate σ² 0.716908 0.716908 0.716908\n7 sample σ² 3.73092 3.730901 3.730918\n7 Residual σ² 0.302415 0.302416 0.302415","category":"page"},{"location":"validation/#Section-3:-Validation-with-bioequivalence-datasets-with-Metida-and-SPSS","page":"Validation","title":"Section 3: Validation with bioequivalence datasets with Metida & SPSS","text":"","category":"section"},{"location":"validation/#Model-BE-B","page":"Validation","title":"Model BE-B","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"lmm = LMM(@formula(lnpk~sequence+period+treatment), dfrds;\nrandom = VarEffect(Metida.@covstr(1|subject), SI),\n)\nfit!(lmm)","category":"page"},{"location":"validation/#Model-BE-C","page":"Validation","title":"Model BE-C","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"lmm = LMM(@formula(lnpk~sequence+period+treatment), dfrds;\n random = VarEffect(Metida.@covstr(treatment|subject), CSH),\n repeated = VarEffect(Metida.@covstr(treatment|subject), DIAG),\n )\n fit!(lmm)","category":"page"},{"location":"validation/#Typical-SPSS-code","page":"Validation","title":"Typical SPSS code","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"MIXED lnpk BY period sequence treatment subject\n /CRITERIA=DFMETHOD(SATTERTHWAITE) CIN(95) MXITER(100) MXSTEP(10) SCORING(1)\n SINGULAR(0.000000000001) HCONVERGE(0, ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE)\n /FIXED=period sequence treatment | SSTYPE(3)\n /METHOD=REML\n /RANDOM= subject(sequence) | COVTYPE(ID)\n /EMMEANS=TABLES(treatment) COMPARE REFCAT(FIRST) ADJ(LSD).\n\nMIXED lnpk BY period treatment sequence subject\n /CRITERIA=CIN(90) MXITER(200) MXSTEP(20) SCORING(2) SINGULAR(0.000000000001) HCONVERGE(0,\n RELATIVE) LCONVERGE(0.0000000000001, RELATIVE) PCONVERGE(0, RELATIVE)\n /FIXED=period treatment sequence | SSTYPE(3)\n /METHOD=REML\n /RANDOM=treatment | SUBJECT(subject) COVTYPE(CSH)\n /REPEATED=treatment | SUBJECT(subject*period) COVTYPE(DIAG)\n /EMMEANS=TABLES(treatment) COMPARE REFCAT(FIRST) ADJ(LSD).","category":"page"},{"location":"validation/#Results","page":"Validation","title":"Results","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"using Metida; # hide\ninclude(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"validation_init.jl\")); # hide\ninclude(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"validation_s3.jl\"))","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"Full SPSS code provided in validation folder (here).","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"SPSS output in DOCX format.","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"Validation dataset available here, 122482020427MOESM2ESM.xls.","category":"page"},{"location":"validation/#Validation-report","page":"Validation","title":"Validation report","text":"","category":"section"},{"location":"validation/","page":"Validation","title":"Validation","text":"Validation and report can be done on local machine with Weave.jl and Pandoc.","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"using Weave, Metida\nweave(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"validation_report.jmd\");\ndoctype = \"pandoc2pdf\",\nout_path = :pwd,\npandoc_options=[\"--toc\", \"-V colorlinks=true\" , \"-V linkcolor=blue\", \"-V urlcolor=red\", \"-V toccolor=gray\"])","category":"page"},{"location":"validation/","page":"Validation","title":"Validation","text":"Report will be saved in Julia working directory. For your own purpose you can edit validation_report.jmd template.","category":"page"},{"location":"ref/#Citation-and-Reference","page":"Citation & Reference","title":"Citation & Reference","text":"","category":"section"},{"location":"ref/#Sweep-algorithm","page":"Citation & Reference","title":"Sweep algorithm","text":"","category":"section"},{"location":"ref/","page":"Citation & Reference","title":"Citation & Reference","text":"Sweep based on SweepOperator.jl. Thanks to @joshday and @Hua-Zhou.\nhttp://hua-zhou.github.io/teaching/biostatm280-2019spring/slides/12-sweep/sweep.html","category":"page"},{"location":"ref/","page":"Citation & Reference","title":"Citation & Reference","text":"More:","category":"page"},{"location":"ref/","page":"Citation & Reference","title":"Citation & Reference","text":"Section 7.4-7.6 of Numerical Analysis for Statisticians by Kenneth Lange (2010).\nThe paper A tutorial on the SWEEP operator by James H. Goodnight (1979).","category":"page"},{"location":"ref/#REML-and-Parameter-estimation","page":"Citation & Reference","title":"REML & Parameter estimation","text":"","category":"section"},{"location":"ref/","page":"Citation & Reference","title":"Citation & Reference","text":"Henderson, C. R., et al. “The Estimation of Environmental and Genetic Trends from Records Subject to Culling.” Biometrics, vol. 15, no. 2, 1959, pp. 192–218. JSTOR, www.jstor.org/stable/2527669.\nLaird, Nan M., and James H. Ware. “Random-Effects Models for Longitudinal Data.” Biometrics, vol. 38, no. 4, 1982, pp. 963–974. JSTOR, www.jstor.org/stable/2529876.\nLindstrom & J.; Bates, M. (1988). Newton—Raphson and EM Algorithms for Linear Mixed-Effects Models for Repeated-Measures Data. Journal of the American Statistical Association. 83. 1014. 10.1080/01621459.1988.10478693.\nGurka, Matthew. (2006). Selecting the Best Linear Mixed Model under REML. The American Statistician. 60. 19-26. 10.1198/000313006X90396.\nSang Hong Lee, Julius H.J. van der Werf. An efficient variance component approach implementing an average information REML suitable for combined LD and linkage mapping with a general complex pedigree. Genetics Selection Evolution, BioMed Central, 2006, 38 (1), pp.25-43. ⟨hal-00894558⟩\nF.N. Gumedze, T.T. Dunne, Parameter estimation and inference in the linear mixed model, Linear Algebra and its Applications, Volume 435, Issue 8, 2011, Pages 1920-1944, ISSN 0024-3795, https://doi.org/10.1016/j.laa.2011.04.015. (http://www.sciencedirect.com/science/article/pii/S002437951100320X)","category":"page"},{"location":"ref/#AI-algorithm","page":"Citation & Reference","title":"AI algorithm","text":"","category":"section"},{"location":"ref/","page":"Citation & Reference","title":"Citation & Reference","text":"D.L. Johnson, R. Thompson, Restricted Maximum Likelihood Estimation of Variance Components for Univariate Animal Models Using Sparse Matrix Techniques and Average Information, Journal of Dairy Science, Volume 78, Issue 2, 1995, Pages 449-456, ISSN 0022-0302, https://doi.org/10.3168/jds.S0022-0302(95)76654-1. (http://www.sciencedirect.com/science/article/pii/S0022030295766541)\nMishchenko, Kateryna & Holmgren, Sverker & Rönnegård, Lars. (2007). Newton-type Methods for REML Estimation in Genetic Analysis of Quantitative Traits. Journal of Computational Methods in Science and Engineering. 8. 10.3233/JCM-2008-81-203.\nMatilainen K, Mäntysaari EA, Lidauer MH, Strandén I, Thompson R. Employing a Monte Carlo algorithm in Newton-type methods for restricted maximum likelihood estimation of genetic parameters. PLoS One. 2013;8(12):e80821. Published 2013 Dec 10. doi:10.1371/journal.pone.0080821","category":"page"},{"location":"ref/#Covariance-structures","page":"Citation & Reference","title":"Covariance structures","text":"","category":"section"},{"location":"ref/","page":"Citation & Reference","title":"Citation & Reference","text":"Wolfinger, Russ. (1993). Covariance structure selection in general mixed models. Communications in Statistics-simulation and Computation - COMMUN STATIST-SIMULAT COMPUT. 22. 1079-1106. 10.1080/03610919308813143.\nWolfinger, Russ. (1996). Heterogeneous Variance: Covariance Structures for Repeated Measures. Journal of Agricultural, Biological, and Environmental Statistics. 1. 205. 10.2307/1400366. \nLittell, Ramon & Pendergast, Jane & Natarajan, Ranjini. (2000). Modelling covariance structure in the analysis of repeated measures data. Statistics in Medicine. 19. 1793-1819. 10.1002/1097-0258(20000715)19:13%3C1793::AID-SIM482%3E3.0.CO;2-Q.\nQUINTAL, SILVANA SILVA RED, VIANA, ALEXANDRE PIO, CAMPOS, BIANCA MACHADO, VIVAS, MARCELO, & AMARAL JÚNIOR, ANTONIO TEIXEIRA DO. (2017). ANALYSIS OF STRUCTURES OF COVARIANCE AND REPEATABILITY IN GUAVA SEGREGANTING POPULATION. Revista Caatinga, 30(4), 885-891. https://doi.org/10.1590/1983-21252017v30n408rc\nMcNeish, D., Harring, J. Covariance pattern mixture models: Eliminating random effects to improve convergence and performance. Behav Res 52, 947–979 (2020). https://doi.org/10.3758/s13428-019-01292-4","category":"page"},{"location":"ref/#And-more","page":"Citation & Reference","title":"And more","text":"","category":"section"},{"location":"ref/","page":"Citation & Reference","title":"Citation & Reference","text":"Giesbrecht, F. G., and Burns, J. C. (1985), \"Two-Stage Analysis Based on a Mixed Model: Large-sample Asymptotic Theory and Small-Sample Simulation Results,\" Biometrics, 41, 853-862.\nJennrich, R., & Schluchter, M. (1986). Unbalanced Repeated-Measures Models with Structured Covariance Matrices. Biometrics, 42(4), 805-820. doi:10.2307/2530695\nFletcher, Roger (1987), Practical methods of optimization (2nd ed.), New York: John Wiley & Sons, ISBN 978-0-471-91547-8\nWolfinger et al., (1994) Computing gaussian likelihoods and their derivatives for general linear mixed models doi: 10.1137/0915079\nHrong-Tai Fai & Cornelius (1996) Approximate F-tests of multiple degree of freedom hypotheses in generalized least squares analyses of unbalanced split-plot experiments, Journal of Statistical Computation and Simulation, 54:4, 363-378, DOI: 10.1080/00949659608811740\nSchaalje GB, McBride JB, Fellingham GW. Adequacy of approximations to distributions of test statistics in complex mixed linear models. J Agric Biol Environ Stat. 2002;7:512–24.\nWright, Stephen, and Jorge Nocedal (2006) \"Numerical optimization.\" Springer\nVan Peer, A. (2010), Variability and Impact on Design of Bioequivalence Studies. Basic & Clinical Pharmacology & Toxicology, 106: 146-153. doi:10.1111/j.1742-7843.2009.00485.x","category":"page"},{"location":"ref/#Julia-packages","page":"Citation & Reference","title":"Julia packages","text":"","category":"section"},{"location":"ref/","page":"Citation & Reference","title":"Citation & Reference","text":"Revels, Jarrett & Lubin, Miles & Papamarkou, Theodore. (2016). Forward-Mode Automatic Differentiation in Julia.\nMogensen et al., (2018). Optim: A mathematical optimization package for Julia. Journal of Open Source Software, 3(24), 615,doi: 10.21105/joss.00615","category":"page"},{"location":"ref/#CuSolver-and-CuBLAS","page":"Citation & Reference","title":"CuSolver & CuBLAS","text":"","category":"section"},{"location":"ref/","page":"Citation & Reference","title":"Citation & Reference","text":"https://docs.nvidia.com/cuda/cusolver/index.html\nhttps://docs.nvidia.com/cuda/cublas/index.htm","category":"page"},{"location":"ref/#Reference-dataset","page":"Citation & Reference","title":"Reference dataset","text":"","category":"section"},{"location":"ref/","page":"Citation & Reference","title":"Citation & Reference","text":"Bioequivalence reference datasets: Schütz, H., Labes, D., Tomashevskiy, M. et al. Reference Datasets for Studies in a Replicate Design Intended for Average Bioequivalence with Expanding Limits. AAPS J 22, 44 (2020). https://doi.org/10.1208/s12248-020-0427-6\nsleepstudy.csv: Gregory Belenky, Nancy J. Wesensten, David R. Thorne, Maria L. Thomas, Helen C. Sing, Daniel P. Redmond, Michael B. Russo and Thomas J. Balkin (2003) Patterns of performance degradation and restoration during sleep restriction and subsequent recovery: a sleep dose-response study. Journal of Sleep Research 12, 1–12.\nPenicillin.csv: O.L. Davies and P.L. Goldsmith (eds), Statistical Methods in Research and Production, 4th ed., Oliver and Boyd, (1972), section 6.6\nPastes.csv: O.L. Davies and P.L. Goldsmith (eds), Statistical Methods in Research and Production, 4th ed., Oliver and Boyd, (1972), section 6.5\nChickWeight.csv:\nCrowder, M. and Hand, D. (1990), Analysis of Repeated Measures, Chapman and Hall (example 5.3)\nHand, D. and Crowder, M. (1996), Practical Longitudinal Data Analysis, Chapman and Hall (table A.2)\nPinheiro, J. C. and Bates, D. M. (2000) Mixed-effects Models in S and S-PLUS, Springer.\nRepeatedPulse.csv: Data supplied by a student at Oberlin College.","category":"page"},{"location":"ref/","page":"Citation & Reference","title":"Citation & Reference","text":"See also: https://vincentarelbundock.github.io/Rdatasets/datasets.html","category":"page"},{"location":"bench/#Benchmark","page":"Benchmark","title":"Benchmark","text":"","category":"section"},{"location":"bench/#System","page":"Benchmark","title":"System","text":"","category":"section"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"CPU: Ryzen 5950x\nRAM: 64Gb 3200\nGTX 1070Ti","category":"page"},{"location":"bench/#Data","page":"Benchmark","title":"Data","text":"","category":"section"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"using Metida, CSV, DataFrames, MixedModels, BenchmarkTools;\n\nrds = CSV.File(joinpath(dirname(pathof(Metida)), \"..\", \"test\", \"csv\", \"1fptime.csv\"); types = [String, String, Float64, Float64]) |> DataFrame","category":"page"},{"location":"bench/#MixedModels","page":"Benchmark","title":"MixedModels","text":"","category":"section"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"fm = @formula(response ~ 1 + factor*time + (1 + time|subject&factor))\n@benchmark mm = fit($MixedModel, $fm, $rds, REML=true) seconds = 15","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"BenchmarkTools.Trial: 10000 samples with 1 evaluation.\n Range (min … max): 1.140 ms … 10.909 ms ┊ GC (min … max): 0.00% … 86.12%\n Time (median): 1.175 ms ┊ GC (median): 0.00%\n Time (mean ± σ): 1.215 ms ± 563.839 μs ┊ GC (mean ± σ): 2.78% ± 5.31%\n\n ▄██▆▃▁ \n ▁▁▁▂▂▃▅▇██████▇▅▄▃▃▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▂\n 1.14 ms Histogram: frequency by time 1.33 ms <\n\n Memory estimate: 409.52 KiB, allocs estimate: 6130.","category":"page"},{"location":"bench/#Metida","page":"Benchmark","title":"Metida","text":"","category":"section"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"lmm = LMM(@formula(response ~1 + factor*time), rds;\nrandom = VarEffect(@covstr(1 + time|subject&factor), CSH),\n)\n@benchmark fit!($lmm, hes = false) seconds = 15","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"Metida v0.12.0","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"BenchmarkTools.Trial: 1316 samples with 1 evaluation.\n Range (min … max): 5.394 ms … 186.301 ms ┊ GC (min … max): 0.00% … 95.48%\n Time (median): 7.648 ms ┊ GC (median): 0.00%\n Time (mean ± σ): 11.391 ms ± 19.135 ms ┊ GC (mean ± σ): 32.70% ± 17.73%\n\n ██▆\n ███▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▄▁▆▅▄▄▅▄▅▄▄▆▄▆▄▄▄ █\n 5.39 ms Histogram: log(frequency) by time 112 ms <\n\n Memory estimate: 22.63 MiB, allocs estimate: 37224.","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"MetidaNLopt v0.4.0 (Metida 0.12.0)","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"@benchmark fit!($lmm, solver = :nlopt, hes = false, f_tol=1e-8, x_tol=1e-8) seconds = 15","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"BenchmarkTools.Trial: 274 samples with 1 evaluation.\n Range (min … max): 47.312 ms … 153.284 ms ┊ GC (min … max): 0.00% … 67.58%\n Time (median): 49.064 ms ┊ GC (median): 0.00%\n Time (mean ± σ): 54.854 ms ± 19.559 ms ┊ GC (mean ± σ): 10.55% ± 15.98%\n\n ▅█ \n ███▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▆▅▁▁▄▁▁▄▁▄▁▁▄▄▅▁▁▁▁▁▁▁▁▁▁▁▄▁▄▄▁▅▄▁▅▄▄ ▅\n 47.3 ms Histogram: log(frequency) by time 135 ms <\n\n Memory estimate: 35.45 MiB, allocs estimate: 301141.","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"MetidaCu v0.4.0 (Metida 0.4)","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"@benchmark fit!($lmm, solver = :cuda, hes = false, f_tol=1e-8, x_tol=1e-8) seconds = 15","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"BenchmarkTools.Trial: 42 samples with 1 evaluation.\n Range (min … max): 347.642 ms … 461.104 ms ┊ GC (min … max): 0.00% … 4.12%\n Time (median): 350.603 ms ┊ GC (median): 0.00%\n Time (mean ± σ): 358.874 ms ± 23.939 ms ┊ GC (mean ± σ): 0.27% ± 0.98%\n\n ▁█ \n ███▁▃▁▁▁▁▁▁▁▁▅▄▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▃▁▁▃ ▁\n 348 ms Histogram: frequency by time 461 ms <\n\n Memory estimate: 6.86 MiB, allocs estimate: 115020.","category":"page"},{"location":"bench/#Cancer-data:","page":"Benchmark","title":"Cancer data:","text":"","category":"section"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"File: hdp.csv , 8525 observations.","category":"page"},{"location":"bench/#Model-1:-maximum-377-observation-per-subject-(35-subjects)","page":"Benchmark","title":"Model 1: maximum 377 observation-per-subject (35 subjects)","text":"","category":"section"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"lmm = Metida.LMM(@formula(tumorsize ~ 1 + CancerStage), hdp;\nrandom = Metida.VarEffect(Metida.@covstr(1|HID), Metida.DIAG),\n)","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"Metida v0.12.0","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"@benchmark Metida.fit!(lmm, hes = false)","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"BenchmarkTools.Trial: 1 sample with 1 evaluation.\n Single result which took 6.519 s (1.38% GC) to evaluate,\n with a memory estimate of 2.33 GiB, over 41654 allocations.","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"MetidaNLopt v0.4.0 (Metida v0.12.0)","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"@benchmark fit!($lmm, solver = :nlopt, hes = false, f_tol=1e-8, x_tol=1e-8) seconds = 15","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"BenchmarkTools.Trial: 25 samples with 1 evaluation.\n Range (min … max): 555.136 ms … 700.605 ms ┊ GC (min … max): 0.00% … 16.09%\n Time (median): 605.713 ms ┊ GC (median): 7.98%\n Time (mean ± σ): 608.768 ms ± 27.220 ms ┊ GC (mean ± σ): 7.62% ± 3.82%\n\n █ ▂\n ▅▁▁▅▁▁▁▁▁▅▁▁▁▁▁▅▁▅█▅▅▅▅█▅▁▁▅▅▁▅█▁▁▅▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▅ ▁\n 555 ms Histogram: frequency by time 701 ms <\n\n Memory estimate: 921.54 MiB, allocs estimate: 62203.","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"MetidaCu v0.4.0 (Metida 0.12.0)","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"@benchmark fit!($lmm, solver = :cuda, hes = false, f_tol=1e-8, x_tol=1e-8) seconds = 15","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"BenchmarkTools.Trial: 5 samples with 1 evaluation.\n Range (min … max): 3.482 s … 3.650 s ┊ GC (min … max): 0.00% … 2.73%\n Time (median): 3.496 s ┊ GC (median): 0.00%\n Time (mean ± σ): 3.547 s ± 77.924 ms ┊ GC (mean ± σ): 1.07% ± 1.43%\n\n ▁ █ ▁ ▁\n █▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁█ ▁\n 3.48 s Histogram: frequency by time 3.65 s <\n\n Memory estimate: 913.96 MiB, allocs estimate: 410438.","category":"page"},{"location":"bench/#Model-2:-maximum-875-observation-per-subject-(20-subjects)","page":"Benchmark","title":"Model 2: maximum 875 observation-per-subject (20 subjects)","text":"","category":"section"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"lmm = Metida.LMM(@formula(tumorsize ~ 1 + CancerStage), hdp;\nrandom = Metida.VarEffect(Metida.@covstr(1|Experience), Metida.SI),\n)","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"MetidaNLopt v0.2.0 (Metida 0.5.1)","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"@benchmark fit!($lmm, solver = :nlopt, hes = false, f_tol=1e-8, x_tol=1e-8) seconds = 1","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"BenchmarkTools.Trial: 9 samples with 1 evaluation.\n Range (min … max): 1.651 s … 1.952 s ┊ GC (min … max): 3.10% … 4.27%\n Time (median): 1.797 s ┊ GC (median): 4.15%\n Time (mean ± σ): 1.815 s ± 101.277 ms ┊ GC (mean ± σ): 3.83% ± 0.82%\n\n ▁ ▁ ▁ ▁ ▁ ▁ ▁ █\n █▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█▁▁█▁█▁▁▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁█▁█▁▁▁▁▁▁▁▁▁▁▁▁▁█ ▁\n 1.65 s Histogram: frequency by time 1.95 s <\n\n Memory estimate: 2.47 GiB, allocs estimate: 57729.","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"MetidaCu v0.2.0 (Metida 0.5.1)","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"@benchmark fit!($lmm, solver = :cuda, hes = false, f_tol=1e-8, x_tol=1e-8) seconds = 15","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"BenchmarkTools.Trial: 3 samples with 1 evaluation.\n Range (min … max): 5.137 s … 5.216 s ┊ GC (min … max): 1.03% … 2.19%\n Time (median): 5.166 s ┊ GC (median): 1.43%\n Time (mean ± σ): 5.173 s ± 39.699 ms ┊ GC (mean ± σ): 1.55% ± 0.59%\n\n █ █ █\n █▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█ ▁\n 5.14 s Histogram: frequency by time 5.22 s <\n\n Memory estimate: 2.46 GiB, allocs estimate: 372716.","category":"page"},{"location":"bench/#Model-3:-maximum-1437-observation-per-subject-(10-subjects)","page":"Benchmark","title":"Model 3: maximum 1437 observation-per-subject (10 subjects)","text":"","category":"section"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"lmm = Metida.LMM(@formula(tumorsize ~ 1 + CancerStage), hdp;\nrandom = Metida.VarEffect(Metida.@covstr(1|ntumors), Metida.SI),\n)","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"MetidaNLopt v0.4.0 (Metida 0.12.0)","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"@benchmark fit!($lmm, solver = :nlopt, hes = false, f_tol=1e-8, x_tol=1e-8) seconds = 15","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"BenchmarkTools.Trial: 4 samples with 1 evaluation.\n Range (min … max): 4.305 s … 4.476 s ┊ GC (min … max): 2.49% … 3.52%\n Time (median): 4.372 s ┊ GC (median): 3.23%\n Time (mean ± σ): 4.381 s ± 80.689 ms ┊ GC (mean ± σ): 3.12% ± 0.47%\n\n █ █ █ █\n █▁▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█ ▁\n 4.3 s Histogram: frequency by time 4.48 s <\n\n Memory estimate: 3.83 GiB, allocs estimate: 28068.","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"MetidaCu v0.4.0 (Metida 0.12.0)","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"@benchmark fit!($lmm, solver = :cuda, hes = false, f_tol=1e-8, x_tol=1e-8) seconds = 15","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"BenchmarkTools.Trial: 4 samples with 1 evaluation.\n Range (min … max): 4.928 s … 4.970 s ┊ GC (min … max): 1.83% … 1.78%\n Time (median): 4.957 s ┊ GC (median): 1.85%\n Time (mean ± σ): 4.953 s ± 18.996 ms ┊ GC (mean ± σ): 1.90% ± 0.15%\n\n █ █ █ █\n █▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█▁▁▁▁█ ▁\n 4.93 s Histogram: frequency by time 4.97 s <\n\n Memory estimate: 3.39 GiB, allocs estimate: 149182.","category":"page"},{"location":"bench/#Model-4:-maximum-3409-observation-per-subject-(4-subjects)","page":"Benchmark","title":"Model 4: maximum 3409 observation-per-subject (4 subjects)","text":"","category":"section"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"MetidaCu v0.4.0 (Metida 0.12.0)","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"lmm = Metida.LMM(@formula(tumorsize ~ 1 + CancerStage), hdp;\nrandom = Metida.VarEffect(Metida.@covstr(1|CancerStage), Metida.SI),\n)","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"@benchmark fit!($lmm, solver = :cuda, hes = false, f_tol=1e-8, x_tol=1e-8) seconds = 15","category":"page"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"julia> @benchmark fit!($lmm, solver = :cuda, hes = false, f_tol=1e-8, x_tol=1e-8) seconds = 15\nBenchmarkTools.Trial: 3 samples with 1 evaluation.\n Range (min … max): 7.343 s … 7.372 s ┊ GC (min … max): 1.62% … 1.48%\n Time (median): 7.346 s ┊ GC (median): 1.49%\n Time (mean ± σ): 7.354 s ± 15.657 ms ┊ GC (mean ± σ): 1.50% ± 0.11%\n\n █ █ █\n █▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█ ▁\n 7.34 s Histogram: frequency by time 7.37 s <\n\n Memory estimate: 5.04 GiB, allocs estimate: 46549.","category":"page"},{"location":"bench/#Conclusion","page":"Benchmark","title":"Conclusion","text":"","category":"section"},{"location":"bench/","page":"Benchmark","title":"Benchmark","text":"MixedModels.jl faster than Metida.jl in similar cases, but Metida.jl can be used with different covariance structures for random and repeated effects. MetidaNLopt have better performance but not estimate Hessian matrix of REML. MetidaCu have advantage only for big observation-pes-subject number.","category":"page"},{"location":"#Metida","page":"Home","title":"Metida","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"CurrentModule = Metida","category":"page"},{"location":"#Mixed-Models","page":"Home","title":"Mixed Models","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Multilevel models (also known as hierarchical linear models, linear mixed-effect model, mixed models, nested data models, random coefficient, random-effects models, random parameter models, or split-plot designs) are statistical models of parameters that vary at more than one level. An example could be a model of student performance that contains measures for individual students as well as measures for classrooms within which the students are grouped. These models can be seen as generalizations of linear models (in particular, linear regression), although they can also extend to non-linear models. These models became much more popular after sufficient computing power and software became available. (Wiki)","category":"page"},{"location":"","page":"Home","title":"Home","text":"Metida.jl is a Julia package for fitting mixed-effects models with flexible covariance structure.","category":"page"},{"location":"","page":"Home","title":"Home","text":"Implemented covariance structures:","category":"page"},{"location":"","page":"Home","title":"Home","text":"Scaled Identity (SI)\nDiagonal (DIAG)\nAutoregressive (AR)\nHeterogeneous Autoregressive (ARH)\nCompound Symmetry (CS)\nHeterogeneous Compound Symmetry (CSH)\nAutoregressive Moving Average (ARMA)\nToeplitz (TOEP)\nToeplitz Parameterized (TOEPP)\nHeterogeneous Toeplitz (TOEPH)\nHeterogeneous Toeplitz Parameterized (TOEPHP)\nSpatial Exponential (SPEXP)\nSpatial Power (SPPOW)\nSpatial Gaussian (SPGAU)\nUnstructured (UN) \nCustom Covariance Type","category":"page"},{"location":"#Limitations","page":"Home","title":"Limitations","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Maximum length of block more than ~400 (observation-per-subject).\nObservation number more than 160 000.\nFor MetidaCu number of blocks more than 40 (maximum length of block more than 4000).","category":"page"},{"location":"","page":"Home","title":"Home","text":"Actually Metida can fit datasets with wore than 160k observation and 40k subjects levels on PC with 64 GB RAM. This is not \"hard-coded\" limitation, but depends on your model and data structure. Fitting of big datasets can take a lot of time. Optimal dataset size is less than 100k observations with maximum length of block less than 400.","category":"page"},{"location":"","page":"Home","title":"Home","text":"warning: Warning\nJulia v1.8 or higher required.","category":"page"},{"location":"#Contents","page":"Home","title":"Contents","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Pages = [\n \"details.md\",\n \"examples.md\",\n \"validation.md\",\n \"api.md\"]\nDepth = 3","category":"page"},{"location":"","page":"Home","title":"Home","text":"See also:","category":"page"},{"location":"","page":"Home","title":"Home","text":"MixedModels.jl\nGLM.jl\nSweepOperator.jl","category":"page"},{"location":"#Reference","page":"Home","title":"Reference","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Gelman, A.; Hill, J. (2007). Data Analysis Using Regression and Multilevel/Hierarchical Models. New York: Cambridge University Press. pp. 235–299. ISBN 978-0-521-68689-1.","category":"page"}] } diff --git a/dev/validation/index.html b/dev/validation/index.html index ced1f85..6ee7870 100644 --- a/dev/validation/index.html +++ b/dev/validation/index.html @@ -120,7 +120,7 @@ /RANDOM=treatment | SUBJECT(subject) COVTYPE(CSH) /REPEATED=treatment | SUBJECT(subject*period) COVTYPE(DIAG) /EMMEANS=TABLES(treatment) COMPARE REFCAT(FIRST) ADJ(LSD).

Results

include(joinpath(dirname(pathof(Metida)), "..", "test", "validation_s3.jl"))
Test Summary:                                               | Pass  Total  Time
-  RDS Test                                                  |  120    120  7.9s
+  RDS Test                                                  |  120    120  7.7s
 
 Bioequivalence Reference Datasets - REML - type B
 .-----.----------.----------.-------------.
@@ -273,4 +273,4 @@
 weave(joinpath(dirname(pathof(Metida)), "..", "test", "validation_report.jmd");
 doctype = "pandoc2pdf",
 out_path = :pwd,
-pandoc_options=["--toc", "-V colorlinks=true" , "-V linkcolor=blue", "-V urlcolor=red", "-V toccolor=gray"])

Report will be saved in Julia working directory. For your own purpose you can edit validation_report.jmd template.

+pandoc_options=["--toc", "-V colorlinks=true" , "-V linkcolor=blue", "-V urlcolor=red", "-V toccolor=gray"])

Report will be saved in Julia working directory. For your own purpose you can edit validation_report.jmd template.