Skip to content

Commit

Permalink
Merge pull request #67 from yufongpeng/dev
Browse files Browse the repository at this point in the history
Release 0.7.5
  • Loading branch information
yufongpeng authored Dec 8, 2023
2 parents 9d256ae + e14b26f commit 18810ec
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 27 deletions.
8 changes: 4 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "AnovaBase"
uuid = "946dddda-6a23-4b48-8e70-8e60d9b8d680"
authors = ["Yu-Fong Peng <sciphypar@gmail.com>"]
version = "0.7.4"
version = "0.7.5"

[deps]
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Expand All @@ -14,6 +14,6 @@ StatsModels = "3eaba693-59b7-5ba5-a881-562e759f1c8d"
[compat]
Distributions = "0.23, 0.24, 0.25"
Reexport = "0.2, 1"
StatsBase = "0.33"
StatsModels = "0.6"
julia = "1.6, 1.7, 1.8"
StatsBase = "0.33, 0.34"
StatsModels = "0.7"
julia = "1.6, 1.7, 1.8, 1.9"
4 changes: 1 addition & 3 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ makedocs(
"Examples_MixedModels.md",
"Examples_FixedEffectModels.md"
],
"Interfacing AnovaBase.jl" => [
"Interface.md"
],
"Interface.md",
"Algorithm" => [
"Algorithm_AnovaGLM.md",
"Algorithm_AnovaMixedModels.md",
Expand Down
4 changes: 2 additions & 2 deletions docs/src/Interface.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Interface
# Interfacing AnovaBase.jl
Given model types `SomeModel` and `OtherModel`, the following functions have to be defined or used.

## [anova](./AnovaBase.md#AnovaBase.anova-Tuple{Type{<:GoodnessOfFit},%20AnovaModel})
Expand Down Expand Up @@ -62,4 +62,4 @@ This function is not essential for ANOVA; it is just for convenience to create n
`AnovaBase` provides a lot of functions to work on formula, terms and contrasts. See [Developer utility](./AnovaBase.md#Developer-utility)

## Other function
* [`dof_residual`](./AnovaBase.md#AnovaBase.dof_residual-Tuple{AnovaResult}) applies `dof_residual` to all models by default. If `dof_residual(::SomeModel)` is not valid for ANOVA, customize `dof_residual(::AnovaResult{<: AnovaModel{SomeModel}})` alternatively.
* [`dof_residual`](./AnovaBase.md#StatsAPI.dof_residual-Tuple{AnovaResult}) applies `dof_residual` to all models by default. If `dof_residual(::SomeModel)` is not valid for ANOVA, customize `dof_residual(::AnovaResult{<: AnovaModel{SomeModel}})` alternatively.
4 changes: 2 additions & 2 deletions src/AnovaBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module AnovaBase
using Statistics, Distributions, Reexport, Printf
@reexport using StatsModels
import StatsBase: fit!, fit, dof, dof_residual, deviance, nobs, vcov, coeftable
import StatsModels: TableRegressionModel, vectorize, collect_matrix_terms, coefnames, formula, asgn, TupleTerm
import StatsModels: TableRegressionModel, vectorize, collect_matrix_terms, coefnames, formula, asgn, TupleTerm, hasintercept
import Base: show

export
Expand Down Expand Up @@ -132,7 +132,7 @@ function FullModel(model::RegressionModel, type::Int, null::Bool, test_intercept
#err2 = ArgumentError("Invalid set of model specification for ANOVA; all coefficents are aliased with 1.")
preds = predictors(model)
pred_id = collect(eachindex(preds))
has_intercept(preds) || popfirst!(pred_id)
hasintercept(preds) || popfirst!(pred_id)
isempty(pred_id) && throw(err1) # ~ 0
if type 1
# ~ 0 + A + B..., ~ 1 + B..., ~ B as null
Expand Down
19 changes: 5 additions & 14 deletions src/term.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
# Function related to terms
"""
has_intercept(<terms>)
Return `true` if `InterceptTerm{true}` is in the terms.
"""
has_intercept(f::FormulaTerm) = has_intercept(f.rhs)
has_intercept(f::MatrixTerm) = has_intercept(f.terms)
has_intercept(f::TupleTerm) = has_intercept(first(f))
has_intercept(::InterceptTerm{H}) where H = H
has_intercept(::AbstractTerm) = false
@deprecate has_intercept hasintercept

"""
any_not_aliased_with_1(<terms>)
Expand Down Expand Up @@ -201,31 +192,31 @@ Set{Int64} with 3 elements:
select_super_interaction(f::MatrixTerm, id::Int) = select_super_interaction(f.terms, id)
function select_super_interaction(f::TupleTerm, id::Int)
s = id 1 ? Set(eachindex(f)) : Set([idn for idn in eachindex(f) if isinteract(f, id, idn)])
has_intercept(f) || filter!(!=(1), s)
hasintercept(f) || filter!(!=(1), s)
s
end

@doc doc_select_interaction
select_sub_interaction(f::MatrixTerm, id::Int) = select_sub_interaction(f.terms, id)
function select_sub_interaction(f::TupleTerm, id::Int)
s = id 1 ? Set(Int[]) : Set([idn for idn in eachindex(f) if isinteract(f, idn, id)])
has_intercept(f) || filter!(!=(1), s)
hasintercept(f) || filter!(!=(1), s)
s
end

@doc doc_select_interaction
select_not_super_interaction(f::MatrixTerm, id::Int) = select_not_super_interaction(f.terms, id)
function select_not_super_interaction(f::TupleTerm, id::Int)
s = id 1 ? Set(Int[]) : Set([idn for idn in eachindex(f) if !isinteract(f, id, idn)])
has_intercept(f) || filter!(!=(1), s)
hasintercept(f) || filter!(!=(1), s)
s
end

@doc doc_select_interaction
select_not_sub_interaction(f::MatrixTerm, id::Int) = select_not_sub_interaction(f.terms, id)
function select_not_sub_interaction(f::TupleTerm, id::Int)
s = id 1 ? Set(eachindex(f)) : Set([idn for idn in eachindex(f) if !isinteract(f, idn, id)])
has_intercept(f) || filter!(!=(1), s)
hasintercept(f) || filter!(!=(1), s)
s
end

Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ anovatable(::AnovaResult{<: FullModel{StatsModels.TableRegressionModel{Int64, Ma
1, 1, Int),
mm)
conterm = ContinuousTerm(:y, 0.0, 0.0, 0.0, 0.0)
fterm = FunctionTerm(log, x->log(x), (:t, ), :(log(t)), [])
fterm = FunctionTerm(log, [Term(:t)], :(log(t)))
caterm() = CategoricalTerm(:x, StatsModels.ContrastsMatrix(StatsModels.FullDummyCoding(), [1, 2, 3]))
caterm(i) = CategoricalTerm(Symbol("x$i"), StatsModels.ContrastsMatrix(StatsModels.DummyCoding(), [1, 2, 3]))
global model5 = StatsModels.TableRegressionModel(
Expand Down Expand Up @@ -188,7 +188,7 @@ anovatable(::AnovaResult{<: FullModel{StatsModels.TableRegressionModel{Int64, Ma
end
global f = FormulaTerm(conterm, MatrixTerm((InterceptTerm{true}(), caterm(), fterm, InteractionTerm((caterm(), fterm)))))
@testset "term.jl" begin
@test AnovaBase.has_intercept(f.rhs)
@test AnovaBase.hasintercept(f.rhs)
@test AnovaBase.any_not_aliased_with_1(f.rhs)
@test !AnovaBase.any_not_aliased_with_1(MatrixTerm((InterceptTerm{true}(), caterm(), caterm(1), caterm(2), InteractionTerm((caterm(), caterm(1), caterm(2))))))
@test AnovaBase.any_not_aliased_with_1(MatrixTerm((InterceptTerm{true}(), caterm(), conterm, fterm, InteractionTerm((caterm(), conterm, fterm)))))
Expand Down

2 comments on commit 18810ec

@yufongpeng
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/96760

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.5 -m "<description of version>" 18810ec838d99aab61f47e50e5d9e86ea169eab5
git push origin v0.7.5

Please sign in to comment.