Interfacing AnovaBase.jl
Given model types SomeModel and OtherModel, the following functions have to be defined or used.
anova
anova can be overloaded in the following arguments signature.
anova(::SomeModel; test, type, kwargs...)anova(::GoodnessOfFit, ::SomeModel; type, kwargs...)anova(::Vararg{SomeModel}; test, kwargs...)anova(::GoodnessOfFit, ::Vararg{SomeModel}; kwargs...)
Other arguments signatures are acceptable, but there will be Type piracy warnings.
Models should be wrapped in the following types before storing in the returned AnovaResult.
| Model | Wrapper |
|---|---|
| Single model | FullModel |
| Nested models | NestedModels |
| Nested models with different types | MixedAovModels |
It is recommended that anova additionally dispatched on wrapper types and the main algorithm is implemented in it.
predictors
This function returns a tuple of terms which can be used in ANOVA (some terms may not be used because of ANOVA type or model itself).
There is a default method for RegressionModel, i.e., formula(model).rhs.terms. If the formula for SomeModel has special structure like MixedModel, this function should be overloaded.
AnovaModels
NestedModels
Wrap nested models in the following way
NestedModels{SomeModel}((model1, model2, ...))NestedModels{SomeModel}(model1, model2, ...)
MixedAovModels
This is for comparing models with different types.
MixedAovModels{Union{SomeModel, OtherModel}}((model1, model2, ...))MixedAovModels{Union{SomeModel, OtherModel}}(model1, model2, ...)
Both NestedModels and MixedAovModels do not check if the order is correct, so user should be careful to put simpler models former and more complex models later. ANOVA can be computed along with some basic statistics. See ftest_nested and lrt_nested.
FullModel
FullModel wraps the model along with the index of predictors(pred_id) that is actually used in ANOVA and ANOVA type.
AnovaBase provides a method which automatically determines pred_id based on ANOVA type, whether empty model is allowed, and whether intercept is tested. See FullModel.
To customize FullModel, there are many helper functions for manipulating terms. See Developer utility
anovatable
This function returns a AnovaTable for showing AnovaResult. For NestedModels and MixedAovModels, AnovaBase provides a default interface. When dealing with FullModel or customizing methods on SomeModel, the following methods should be defined.
anovatable(::AnovaResult{<: FullModel{SomeModel}}; rownames)anovatable(::AnovaResult{<: NestedModels{SomeModel}}; rownames)anovatable(::AnovaResult{<: MixedAovModels{SomeModel}}; rownames)
See AnovaTable for the argument signature.
nestedmodels
This function is not essential for ANOVA; it is just for convenience to create nested models(NestedModels). It should be defined as follow
nestedmodels(SomeModel, ::FormulaTerm, data; kwargs)nestedmodels(::SomeModel; kwargs)
AnovaBase provides a lot of functions to work on formula, terms and contrasts. See Developer utility
Other function
dof_residualappliesdof_residualto all models by default. Ifdof_residual(::SomeModel)is not valid for ANOVA, customizedof_residual(::AnovaResult{<: AnovaModel{SomeModel}})alternatively.