From 6507416e3524f6697947b83e7bee4c92717c9939 Mon Sep 17 00:00:00 2001 From: Matthieu Gomez Date: Mon, 27 Jun 2022 12:26:18 -0400 Subject: [PATCH 01/11] add hasintercept This is useful to compute the correct degrees of freedoms to be used in t-test --- src/statisticalmodel.jl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/statisticalmodel.jl b/src/statisticalmodel.jl index e8f4f68..f73e880 100644 --- a/src/statisticalmodel.jl +++ b/src/statisticalmodel.jl @@ -162,6 +162,15 @@ Return the weights used in the model. """ function weights end + +""" + hasintercept(model::StatisticalModel) + +Return a Boolean indicating whether the model has an intercept +""" +function hasintercept end + + """ isfitted(model::StatisticalModel) @@ -314,3 +323,6 @@ function adjr2(model::StatisticalModel, variant::Symbol) end const adjr² = adjr2 + + + From b733a0e60ff4e6e5efebd08a6c745cac572cde6a Mon Sep 17 00:00:00 2001 From: Matthieu Gomez Date: Wed, 6 Sep 2023 08:27:29 -0400 Subject: [PATCH 02/11] Update src/statisticalmodel.jl Co-authored-by: Milan Bouchet-Valat --- src/statisticalmodel.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/statisticalmodel.jl b/src/statisticalmodel.jl index f73e880..de21d46 100644 --- a/src/statisticalmodel.jl +++ b/src/statisticalmodel.jl @@ -162,7 +162,6 @@ Return the weights used in the model. """ function weights end - """ hasintercept(model::StatisticalModel) From 80d017ea19e805c744e341229d4b88db2d197630 Mon Sep 17 00:00:00 2001 From: Matthieu Gomez Date: Wed, 6 Sep 2023 08:27:34 -0400 Subject: [PATCH 03/11] Update src/statisticalmodel.jl Co-authored-by: Milan Bouchet-Valat --- src/statisticalmodel.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/statisticalmodel.jl b/src/statisticalmodel.jl index de21d46..48b2e61 100644 --- a/src/statisticalmodel.jl +++ b/src/statisticalmodel.jl @@ -165,7 +165,7 @@ function weights end """ hasintercept(model::StatisticalModel) -Return a Boolean indicating whether the model has an intercept +Indicate whether the model has an intercept. """ function hasintercept end From bf74b97bbcac7de65c1bf050c07740c83f5dcef3 Mon Sep 17 00:00:00 2001 From: Matthieu Gomez Date: Wed, 6 Sep 2023 08:27:40 -0400 Subject: [PATCH 04/11] Update src/statisticalmodel.jl Co-authored-by: Milan Bouchet-Valat --- src/statisticalmodel.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/statisticalmodel.jl b/src/statisticalmodel.jl index 48b2e61..b282718 100644 --- a/src/statisticalmodel.jl +++ b/src/statisticalmodel.jl @@ -169,7 +169,6 @@ Indicate whether the model has an intercept. """ function hasintercept end - """ isfitted(model::StatisticalModel) From a1f821e2869fd3af855c74f81d22d0a5fcf0fc10 Mon Sep 17 00:00:00 2001 From: Matthieu Gomez Date: Wed, 6 Sep 2023 08:27:46 -0400 Subject: [PATCH 05/11] Update src/statisticalmodel.jl Co-authored-by: Milan Bouchet-Valat --- src/statisticalmodel.jl | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/statisticalmodel.jl b/src/statisticalmodel.jl index b282718..669e82a 100644 --- a/src/statisticalmodel.jl +++ b/src/statisticalmodel.jl @@ -321,6 +321,3 @@ function adjr2(model::StatisticalModel, variant::Symbol) end const adjr² = adjr2 - - - From 634e632b736e1b59f42b62c4a4619cdbf1583416 Mon Sep 17 00:00:00 2001 From: Matthieu Gomez Date: Wed, 6 Sep 2023 08:29:15 -0400 Subject: [PATCH 06/11] Update statisticalmodel.jl --- src/statisticalmodel.jl | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/statisticalmodel.jl b/src/statisticalmodel.jl index 669e82a..e8f4f68 100644 --- a/src/statisticalmodel.jl +++ b/src/statisticalmodel.jl @@ -162,13 +162,6 @@ Return the weights used in the model. """ function weights end -""" - hasintercept(model::StatisticalModel) - -Indicate whether the model has an intercept. -""" -function hasintercept end - """ isfitted(model::StatisticalModel) From 31564052b3f056742e910caa9a0939c0540ef5b3 Mon Sep 17 00:00:00 2001 From: Matthieu Gomez Date: Wed, 6 Sep 2023 08:29:54 -0400 Subject: [PATCH 07/11] Update regressionmodel.jl --- src/regressionmodel.jl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/regressionmodel.jl b/src/regressionmodel.jl index d7a2afc..e8916b7 100644 --- a/src/regressionmodel.jl +++ b/src/regressionmodel.jl @@ -40,6 +40,13 @@ Return the model matrix (a.k.a. the design matrix). """ function modelmatrix end +""" + hasintercept(model::RegressionModel) + +Indicate whether the model has an intercept. +""" +function hasintercept end + """ crossmodelmatrix(model::RegressionModel) From c603a4eb3a607a11d7e345c8fc3368359867d366 Mon Sep 17 00:00:00 2001 From: Matthieu Gomez Date: Wed, 6 Sep 2023 08:45:13 -0400 Subject: [PATCH 08/11] Update regressionmodel.jl --- src/regressionmodel.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/regressionmodel.jl b/src/regressionmodel.jl index e8916b7..2cc1510 100644 --- a/src/regressionmodel.jl +++ b/src/regressionmodel.jl @@ -45,7 +45,11 @@ function modelmatrix end Indicate whether the model has an intercept. """ -function hasintercept end +function hasintercept(model::RegressionModel) + X = modelmatrix(model) + any(i -> all(==(1), view(X , :, i)), 1:size(X, 2)) +end + """ crossmodelmatrix(model::RegressionModel) From 9845ac3b266a5c76d009f65882d85c8770fde58b Mon Sep 17 00:00:00 2001 From: Matthieu Gomez Date: Wed, 6 Sep 2023 08:45:51 -0400 Subject: [PATCH 09/11] Update regressionmodel.jl --- test/regressionmodel.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/regressionmodel.jl b/test/regressionmodel.jl index a8892fa..2dd767c 100644 --- a/test/regressionmodel.jl +++ b/test/regressionmodel.jl @@ -10,9 +10,10 @@ StatsAPI.modelmatrix(::MyRegressionModel) = [1 2; 3 4] @testset "TestRegressionModel" begin m = MyRegressionModel() - + @test !hasintercept(m) @test crossmodelmatrix(m) == [10 14; 14 20] @test crossmodelmatrix(m) isa Symmetric + end -end # module TestRegressionModel \ No newline at end of file +end # module TestRegressionModel From 8e389855c0ea4b99bc40e07735efbe8eefcad98c Mon Sep 17 00:00:00 2001 From: Matthieu Gomez Date: Wed, 6 Sep 2023 08:47:29 -0400 Subject: [PATCH 10/11] Update regressionmodel.jl --- test/regressionmodel.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/regressionmodel.jl b/test/regressionmodel.jl index 2dd767c..c5c7edc 100644 --- a/test/regressionmodel.jl +++ b/test/regressionmodel.jl @@ -10,10 +10,10 @@ StatsAPI.modelmatrix(::MyRegressionModel) = [1 2; 3 4] @testset "TestRegressionModel" begin m = MyRegressionModel() + @test !hasintercept(m) @test crossmodelmatrix(m) == [10 14; 14 20] @test crossmodelmatrix(m) isa Symmetric - end end # module TestRegressionModel From 8aa44b4a13fae04cee0465377d6ea3cb05a11dbc Mon Sep 17 00:00:00 2001 From: Matthieu Gomez Date: Wed, 6 Sep 2023 08:49:13 -0400 Subject: [PATCH 11/11] Update regressionmodel.jl --- test/regressionmodel.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/regressionmodel.jl b/test/regressionmodel.jl index c5c7edc..a18c556 100644 --- a/test/regressionmodel.jl +++ b/test/regressionmodel.jl @@ -1,7 +1,7 @@ module TestRegressionModel using Test, LinearAlgebra, StatsAPI -using StatsAPI: RegressionModel, crossmodelmatrix +using StatsAPI: RegressionModel, hasintercept, crossmodelmatrix struct MyRegressionModel <: RegressionModel end