Skip to content

Commit

Permalink
Merge pull request #60 from yufongpeng/revert-59-release-0.7.2
Browse files Browse the repository at this point in the history
Revert "Release 0.7.2"
  • Loading branch information
yufongpeng authored Jan 19, 2023
2 parents 251d370 + 1e1bb90 commit c1cf9b0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
18 changes: 3 additions & 15 deletions src/fit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,16 @@ end

# Calculate dof from assign
"""
dof_asgn(assign::Vector{Int})
dof_asgn(v::Vector{Int})
Calculate degrees of freedom of each predictors. 'assign' can be obtained by `StatsModels.asgn(f::FormulaTerm)`. For a given `trm::RegressionModel`, it is as same as `trm.mm.assign`.
The index of the output matches values in the orinal `assign`. If any index value is not in `assign`, the default is 0.
# Examples
```julia
julia> dof_asgn([1, 2, 2, 3, 3, 3])
(1, 2, 3)
julia> dof_asgn([2, 2, 3, 3, 3])
(0, 2, 3)
```
Calculate degrees of freedom of each predictors. 'v' can be obtained by `StatsModels.asgn(f::FormulaTerm)`. For a given `trm::RegressionModel`, it is as same as `trm.mm.assign`.
"""
function dof_asgn(v::Vector{Int})
dofv = zeros(Int, maximum(v))
for i in v
@inbounds dofv[i] += 1
end
tuple(dofv...)
dofv
end

@deprecate dof(v::Vector{Int}) dof_asgn(v::Vector{Int})
Expand Down
6 changes: 3 additions & 3 deletions src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ predictors(anovamodel::FullModel) = getindex.(Ref(predictors(anovamodel.model)),
anovatable(aov::AnovaResult{<: NestedModels, LRT, N}; rownames = string.(1:N)) where N
Return a table with coefficients and related statistics of ANOVA.
When displaying `aov` in repl, `rownames` will be `prednames(aov)` for `FullModel` and `string.(1:N)` for `NestedModels`.
When displaying `aov` in repl, `rownames` will be `prednames(aov)` for `FullModel` and `"x" .* string.(1:N)` for `NestedModels`.
For nested models, there are two default methods for `FTest` and `LRT`; one can also define new methods dispatching on `::NestedModels{M}` where `M` is a model type.
Expand All @@ -87,7 +87,7 @@ function anovatable(::AnovaResult{T, S, N}; rownames = "x" .* string.(1:N)) wher
end

# default anovatable api for comparing multiple models
function anovatable(aov::AnovaResult{<: NestedModels, FTest, N}; rownames = string.(1:N)) where N
function anovatable(aov::AnovaResult{<: NestedModels, FTest, N}; rownames = "x" .* string.(1:N)) where N
AnovaTable([
dof(aov),
[NaN, _diff(dof(aov))...],
Expand All @@ -101,7 +101,7 @@ function anovatable(aov::AnovaResult{<: NestedModels, FTest, N}; rownames = stri
rownames, 7, 6)
end

function anovatable(aov::AnovaResult{<: NestedModels, LRT, N}; rownames = string.(1:N)) where N
function anovatable(aov::AnovaResult{<: NestedModels, LRT, N}; rownames = "x" .* string.(1:N)) where N
AnovaTable([
dof(aov),
[NaN, _diff(dof(aov))...],
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ anovatable(::AnovaResult{<: FullModel{StatsModels.TableRegressionModel{Int64, Ma
@test canonicalgoodnessoffit(Binomial()) == LRT
@test AnovaBase.lrt_nested(NestedModels{StatsModels.TableRegressionModel}(model1, model1), (1,2), (1.5, 1.5), 0.1).teststat[2] == 0.0
@test AnovaBase.ftest_nested(NestedModels{StatsModels.TableRegressionModel}((model1, model1)), (1,2), (10, 10), (1.5, 1.5), 0.1).teststat[2] == 0.0
@test dof_asgn([1, 2, 2, 2, 3]) == (1, 3, 1)
@test dof_asgn([1, 2, 2, 2, 3]) == [1, 3, 1]
end
global f = FormulaTerm(conterm, MatrixTerm((InterceptTerm{true}(), caterm(), fterm, InteractionTerm((caterm(), fterm)))))
@testset "term.jl" begin
Expand Down

0 comments on commit c1cf9b0

Please sign in to comment.