AnovaMixedModels.jl

AnovaBase.anovaMethod
anova(mixedmodels...; test::Type{<: GoodnessOfFit}, keyword_arguments...)
anova(anovamodel; test::Type{<: GoodnessOfFit}, keyword_arguments...)
anova(test::Type{<: GoodnessOfFit}, mixedmodels...; keyword_arguments...)
anova(test::Type{<: GoodnessOfFit}, anovamodel; keyword_arguments...)

Analysis of variance.

Return AnovaResult{M, test, N}. See AnovaResult for details.

Arguments

  • mixedmodels: model objects
    1. LinearMixedModel fitted by MixedModels.lmm or fit(LinearMixedModel, ...)
    2. GeneralizedLinearMixedModel fitted by MixedModels.glmm or fit(GeneralizedLinearMixedModel, ...)
    If mutiple models are provided, they should be nested and the last one is the most complex. The first model can also be the corresponding GLM object without random effects.
  • anovamodel: wrapped model objects; FullModel, NestedModels, and MixedAovModels.
  • test: test statistics for goodness of fit. Available tests are LikelihoodRatioTest (LRT) and FTest. The default is based on the model type.
    1. LinearMixedModel: FTest for one model; LRT for nested models.
    2. GeneralizedLinearMixedModel: LRT for nested models.
    Models should not be fitted by REML for LRT.

Other keyword arguments

  • When one model is provided:
    1. type: type of anova (1, 2 or 3). Default value is 1.
    2. adjust_sigma: whether adjust σ to match that of linear mixed-effect model fitted by REML. The result will be slightly deviated from that of model fitted by REML.
  • When multiple models are provided:
    1. check: allows to check if models are nested. Defalut value is true. Some checkers are not implemented now.
Note

For fitting new models and conducting anova at the same time, see anova_lmm for LinearMixedModel.

Note

The result with adjust_sigma will be slightly deviated from that of model fitted directly by REML.

Note

For the computation of degrees of freedom, please see dof_residual_pred.

source
AnovaMixedModels.anova_lmmFunction
anova_lmm(f::FormulaTerm, tbl; test::Type{<: GoodnessOfFit} = FTest, keyword_arguments...)

anova_lmm(test::Type{<: GoodnessOfFit}, f::FormulaTerm, tbl; keyword_arguments...)

anova(test::Type{<: GoodnessOfFit}, ::Type{<: LinearMixedModel}, f::FormulaTerm, tbl; keyword_arguments...)

ANOVA for linear mixed-effect models.

Arguments

  • f: a Formula.
  • tbl: a Tables.jl compatible data.
  • test: GoodnessOfFit. The default is FTest.

Anova keyword arguments

  • test: GoodnessOfFit. The default is FTest.
  • type: type of anova (1, 2 or 3). Default value is 1.
  • adjust_sigma: whether adjust σ to match that of linear mixed-effect model fitted by REML. The result will be slightly deviated from that of model fitted by REML.

Model keyword arguments

  • wts = []
  • contrasts = Dict{Symbol,Any}()
  • progress::Bool = true
  • REML::Bool = true

Other keyword arguments

For LRT, NestedModels is generated with the leftover keyword arguments using nestedmodels. For FTest, no other keyword arguments can be accepted.

anova_lmm generate a LinearMixedModel fitted with REML if applying FTest; otherwise, a model fitted with ML.

Note

The result with adjust_sigma will be slightly deviated from that of model fitted directly by REML.

source
AnovaBase.nestedmodelsMethod
nestedmodels(model::LinearMixedModel; null::Bool = true, keyword_arguments...)

nestedmodels(::Type{LinearMixedModel}, f::FormulaTerm, tbl; null::Bool = true, wts = [], contrasts = Dict{Symbol, Any}(), verbose::Bool = false, REML::Bool = false)

Generate nested models from a model or modeltype, formula and data. The null model will be an empty model if the keyword argument null is true (default).

source
AnovaMixedModels.dof_residual_predFunction
dof_residual_pred(model::LinearMixedModel)
dof_residual_pred(aovm::FullModel{LinearMixedModel})

Compute degrees of freedom (DOF) of residuals for each predictors in a linear mixed effect models.

DOF of residuals are estimated by between-within method. For details, please refer to the documentation or GLMM FAQ for details.

To be noticed, my implementation is a little different from the reference one. When intercept is not in fix effects, the reference algorithm regards the first term as intercept; however, there is no such replacement here.

source