From e04ad3f19e5bbe4d0a86ffb236c0c7b1203c9b2e Mon Sep 17 00:00:00 2001 From: Giuseppe Ragusa Date: Fri, 10 Jun 2022 20:53:47 +0200 Subject: [PATCH 01/15] WIP --- src/regressionmodel.jl | 2 +- src/statisticalmodel.jl | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/regressionmodel.jl b/src/regressionmodel.jl index d7a2afc..419263f 100644 --- a/src/regressionmodel.jl +++ b/src/regressionmodel.jl @@ -46,7 +46,7 @@ function modelmatrix end Return `X'X` where `X` is the model matrix of `model`. This function will return a pre-computed matrix stored in `model` if possible. """ -crossmodelmatrix(model::RegressionModel) = (x = modelmatrix(model); Symmetric(x' * x)) +crossmodelmatrix(model::RegressionModel; kwarg...) = (x = modelmatrix(model; kwarg...); Symmetric(x' * x)) """ leverage(model::RegressionModel) diff --git a/src/statisticalmodel.jl b/src/statisticalmodel.jl index e8f4f68..8e3d654 100644 --- a/src/statisticalmodel.jl +++ b/src/statisticalmodel.jl @@ -313,4 +313,15 @@ function adjr2(model::StatisticalModel, variant::Symbol) end end + +""" + momentmatrix(model::StatisticalModel) + +Return the moment matrix. + +For linear regression models `lm`, the moment matrix is residual(lm)*momentmatrix(lm). + +""" +function momentmatrix end + const adjr² = adjr2 From 6f6a160a70ffd442a407ab5c77b473dc456af519 Mon Sep 17 00:00:00 2001 From: Giuseppe Ragusa Date: Wed, 15 Jun 2022 19:10:01 +0200 Subject: [PATCH 02/15] Fix doc --- src/statisticalmodel.jl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/statisticalmodel.jl b/src/statisticalmodel.jl index 8e3d654..533a6ed 100644 --- a/src/statisticalmodel.jl +++ b/src/statisticalmodel.jl @@ -313,15 +313,14 @@ function adjr2(model::StatisticalModel, variant::Symbol) end end +const adjr² = adjr2 """ momentmatrix(model::StatisticalModel) -Return the moment matrix. +Return the matrix containing the estimating equation. -For linear regression models `lm`, the moment matrix is residual(lm)*momentmatrix(lm). +For linear regression models, the moment matrix is given by u*X, where u is the vector of residuals and X is the model matrix. """ function momentmatrix end - -const adjr² = adjr2 From 0625c3c12adfca65ef12db5f260d9dbf67d6ef81 Mon Sep 17 00:00:00 2001 From: Giuseppe Ragusa Date: Thu, 16 Jun 2022 22:23:14 +0200 Subject: [PATCH 03/15] WIP --- src/regressionmodel.jl | 19 +++++++++++++------ src/statisticalmodel.jl | 2 +- test/regressionmodel.jl | 19 +++++++++++++++++++ test/statisticalmodel.jl | 1 + 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/regressionmodel.jl b/src/regressionmodel.jl index 419263f..c4aef4e 100644 --- a/src/regressionmodel.jl +++ b/src/regressionmodel.jl @@ -34,19 +34,26 @@ Return the mean of the response. function meanresponse end """ - modelmatrix(model::RegressionModel) + modelmatrix(model::RegressionModel; weighted::Bool=false) -Return the model matrix (a.k.a. the design matrix). +Return the model matrix (a.k.a. the design matrix) or, if `weighted=true` the weighted +model matrix, i.e, X'sqrt.(W), where `W` is the diagonal matrix whose elements are +the model weights. """ -function modelmatrix end +function modelmatrix(model::RegressionModel; weighted::Bool=false) +end """ - crossmodelmatrix(model::RegressionModel) + crossmodelmatrix(model::RegressionModel; weighted::Bool=false) -Return `X'X` where `X` is the model matrix of `model`. +Return `X'X` where `X` is the model matrix of `model` or, if `weighted=true`, `X'WX`, +where `W` is the diagonal matrix whose elements are the model weights. This function will return a pre-computed matrix stored in `model` if possible. """ -crossmodelmatrix(model::RegressionModel; kwarg...) = (x = modelmatrix(model; kwarg...); Symmetric(x' * x)) +function crossmodelmatrix(model::RegressionModel; weighted::Bool=false) + x = weighted ? modelmatrix(model; weighted=weighted) : modelmatrix(model) + return Symmetric(x' * x) +end """ leverage(model::RegressionModel) diff --git a/src/statisticalmodel.jl b/src/statisticalmodel.jl index 533a6ed..7b2e201 100644 --- a/src/statisticalmodel.jl +++ b/src/statisticalmodel.jl @@ -320,7 +320,7 @@ const adjr² = adjr2 Return the matrix containing the estimating equation. -For linear regression models, the moment matrix is given by u*X, where u is the vector of residuals and X is the model matrix. +For linear regression models, the moment matrix is given by `u*X`, where `u` is the vector of residuals and `X` is the model matrix. """ function momentmatrix end diff --git a/test/regressionmodel.jl b/test/regressionmodel.jl index a8892fa..4b48a27 100644 --- a/test/regressionmodel.jl +++ b/test/regressionmodel.jl @@ -6,13 +6,32 @@ using StatsAPI: RegressionModel, crossmodelmatrix struct MyRegressionModel <: RegressionModel end +struct ItsRegressionModel <: RegressionModel + wts +end + StatsAPI.modelmatrix(::MyRegressionModel) = [1 2; 3 4] +function StatsAPI.modelmatrix(r::ItsRegressionModel; weighted::Bool=false) + X = [1 2; 3 4] + weighted ? sqrt.(r.wts).*X : X +end + +w = [0.3, 0.2] + @testset "TestRegressionModel" begin m = MyRegressionModel() + r = ItsRegressionModel(w) @test crossmodelmatrix(m) == [10 14; 14 20] + @test crossmodelmatrix(m; weighted=false) == [10 14; 14 20] @test crossmodelmatrix(m) isa Symmetric + + @test crossmodelmatrix(r) == [10 14; 14 20] + @test crossmodelmatrix(r; weighted=false) == [10 14; 14 20] + @test crossmodelmatrix(r; weighted=true) ≈ [2.1 3.0; 3.0 4.4] + @test crossmodelmatrix(r; weighted=true) isa Symmetric + end end # module TestRegressionModel \ No newline at end of file diff --git a/test/statisticalmodel.jl b/test/statisticalmodel.jl index 114a68e..666f61a 100644 --- a/test/statisticalmodel.jl +++ b/test/statisticalmodel.jl @@ -13,6 +13,7 @@ StatsAPI.deviance(::MyStatisticalModel) = 25 StatsAPI.nulldeviance(::MyStatisticalModel) = 40 StatsAPI.dof(::MyStatisticalModel) = 5 StatsAPI.nobs(::MyStatisticalModel) = 100 +StatsAPI.momentmatrix(::MyStatisticalModel) = [1 2; 3 4; 5 6; 7 8] @testset "StatisticalModel" begin m = MyStatisticalModel() From e514db0186ede4a334483a41992ae86e71a84e3b Mon Sep 17 00:00:00 2001 From: Giuseppe Ragusa Date: Fri, 17 Jun 2022 00:34:09 +0200 Subject: [PATCH 04/15] Update src/regressionmodel.jl Co-authored-by: Milan Bouchet-Valat --- src/regressionmodel.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/regressionmodel.jl b/src/regressionmodel.jl index c4aef4e..e5b6278 100644 --- a/src/regressionmodel.jl +++ b/src/regressionmodel.jl @@ -40,8 +40,7 @@ Return the model matrix (a.k.a. the design matrix) or, if `weighted=true` the we model matrix, i.e, X'sqrt.(W), where `W` is the diagonal matrix whose elements are the model weights. """ -function modelmatrix(model::RegressionModel; weighted::Bool=false) -end +function modelmatrix(model::RegressionModel; weighted::Bool=false) end """ crossmodelmatrix(model::RegressionModel; weighted::Bool=false) From bfe8ac67381ec62c35c9ba0a808e295425e84986 Mon Sep 17 00:00:00 2001 From: Giuseppe Ragusa Date: Fri, 17 Jun 2022 00:34:19 +0200 Subject: [PATCH 05/15] Update src/regressionmodel.jl Co-authored-by: Milan Bouchet-Valat --- src/regressionmodel.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/regressionmodel.jl b/src/regressionmodel.jl index e5b6278..3eaa497 100644 --- a/src/regressionmodel.jl +++ b/src/regressionmodel.jl @@ -46,7 +46,7 @@ function modelmatrix(model::RegressionModel; weighted::Bool=false) end crossmodelmatrix(model::RegressionModel; weighted::Bool=false) Return `X'X` where `X` is the model matrix of `model` or, if `weighted=true`, `X'WX`, -where `W` is the diagonal matrix whose elements are the model weights. +where `W` is the diagonal matrix whose elements are the model weights. This function will return a pre-computed matrix stored in `model` if possible. """ function crossmodelmatrix(model::RegressionModel; weighted::Bool=false) From af658881a3b4ccbb809e392a66532b1716125cf2 Mon Sep 17 00:00:00 2001 From: Giuseppe Ragusa Date: Fri, 17 Jun 2022 00:34:47 +0200 Subject: [PATCH 06/15] Update src/statisticalmodel.jl Co-authored-by: Milan Bouchet-Valat --- src/statisticalmodel.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/statisticalmodel.jl b/src/statisticalmodel.jl index 7b2e201..1babd65 100644 --- a/src/statisticalmodel.jl +++ b/src/statisticalmodel.jl @@ -320,7 +320,7 @@ const adjr² = adjr2 Return the matrix containing the estimating equation. -For linear regression models, the moment matrix is given by `u*X`, where `u` is the vector of residuals and `X` is the model matrix. - +For linear regression models, the moment matrix is given by `u*X`, +where `u` is the vector of residuals and `X` is the model matrix. """ function momentmatrix end From 11505ff462311b123b7266d6dcdf598b7978cb5a Mon Sep 17 00:00:00 2001 From: Giuseppe Ragusa Date: Fri, 17 Jun 2022 00:38:46 +0200 Subject: [PATCH 07/15] Change type name for clarity --- test/regressionmodel.jl | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test/regressionmodel.jl b/test/regressionmodel.jl index 4b48a27..9268bfa 100644 --- a/test/regressionmodel.jl +++ b/test/regressionmodel.jl @@ -6,22 +6,22 @@ using StatsAPI: RegressionModel, crossmodelmatrix struct MyRegressionModel <: RegressionModel end -struct ItsRegressionModel <: RegressionModel - wts +struct MyWeightedRegressionModel <: RegressionModel + wts::AbstractVector end StatsAPI.modelmatrix(::MyRegressionModel) = [1 2; 3 4] -function StatsAPI.modelmatrix(r::ItsRegressionModel; weighted::Bool=false) +function StatsAPI.modelmatrix(r::MyWeightedRegressionModel; weighted::Bool=false) X = [1 2; 3 4] - weighted ? sqrt.(r.wts).*X : X + weighted ? sqrt.(r.wts).*X : X end w = [0.3, 0.2] @testset "TestRegressionModel" begin m = MyRegressionModel() - r = ItsRegressionModel(w) + r = MyWeightedRegressionModel(w) @test crossmodelmatrix(m) == [10 14; 14 20] @test crossmodelmatrix(m; weighted=false) == [10 14; 14 20] @@ -31,7 +31,6 @@ w = [0.3, 0.2] @test crossmodelmatrix(r; weighted=false) == [10 14; 14 20] @test crossmodelmatrix(r; weighted=true) ≈ [2.1 3.0; 3.0 4.4] @test crossmodelmatrix(r; weighted=true) isa Symmetric - end end # module TestRegressionModel \ No newline at end of file From de0c6aee338d24d4a6cfefeb94fb367d62e6ca3e Mon Sep 17 00:00:00 2001 From: Giuseppe Ragusa Date: Fri, 17 Jun 2022 00:41:07 +0200 Subject: [PATCH 08/15] Update src/regressionmodel.jl Co-authored-by: Milan Bouchet-Valat --- src/regressionmodel.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/regressionmodel.jl b/src/regressionmodel.jl index 3eaa497..f8f12aa 100644 --- a/src/regressionmodel.jl +++ b/src/regressionmodel.jl @@ -37,8 +37,8 @@ function meanresponse end modelmatrix(model::RegressionModel; weighted::Bool=false) Return the model matrix (a.k.a. the design matrix) or, if `weighted=true` the weighted -model matrix, i.e, X'sqrt.(W), where `W` is the diagonal matrix whose elements are -the model weights. +model matrix, i.e. `X' * sqrt.(W)`, where `X` is the model matrix and +`W` is the diagonal matrix whose elements are the model weights. """ function modelmatrix(model::RegressionModel; weighted::Bool=false) end From c36352bd65a630a333c724be8aafb1bf6d54e730 Mon Sep 17 00:00:00 2001 From: Giuseppe Ragusa Date: Fri, 17 Jun 2022 00:41:43 +0200 Subject: [PATCH 09/15] Don't test momentmatrix --- test/statisticalmodel.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/test/statisticalmodel.jl b/test/statisticalmodel.jl index 666f61a..114a68e 100644 --- a/test/statisticalmodel.jl +++ b/test/statisticalmodel.jl @@ -13,7 +13,6 @@ StatsAPI.deviance(::MyStatisticalModel) = 25 StatsAPI.nulldeviance(::MyStatisticalModel) = 40 StatsAPI.dof(::MyStatisticalModel) = 5 StatsAPI.nobs(::MyStatisticalModel) = 100 -StatsAPI.momentmatrix(::MyStatisticalModel) = [1 2; 3 4; 5 6; 7 8] @testset "StatisticalModel" begin m = MyStatisticalModel() From 9a7b2ab2d44eca9d3efc8aa3c9d5f70f617b183d Mon Sep 17 00:00:00 2001 From: Giuseppe Ragusa Date: Fri, 17 Jun 2022 00:44:09 +0200 Subject: [PATCH 10/15] Don't test momentmatrix --- test/statisticalmodel.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/statisticalmodel.jl b/test/statisticalmodel.jl index 666f61a..4b35998 100644 --- a/test/statisticalmodel.jl +++ b/test/statisticalmodel.jl @@ -13,7 +13,6 @@ StatsAPI.deviance(::MyStatisticalModel) = 25 StatsAPI.nulldeviance(::MyStatisticalModel) = 40 StatsAPI.dof(::MyStatisticalModel) = 5 StatsAPI.nobs(::MyStatisticalModel) = 100 -StatsAPI.momentmatrix(::MyStatisticalModel) = [1 2; 3 4; 5 6; 7 8] @testset "StatisticalModel" begin m = MyStatisticalModel() @@ -37,4 +36,4 @@ StatsAPI.momentmatrix(::MyStatisticalModel) = [1 2; 3 4; 5 6; 7 8] @test adjr2 === adjr² end -end # module TestStatisticalModel \ No newline at end of file +end # module TestStatisticalModel From 48333e50977fdd7f22db75ac50c6196aae11eacf Mon Sep 17 00:00:00 2001 From: Giuseppe Ragusa Date: Fri, 17 Jun 2022 14:47:15 +0200 Subject: [PATCH 11/15] Update src/regressionmodel.jl Co-authored-by: Moritz Schauer --- src/regressionmodel.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/regressionmodel.jl b/src/regressionmodel.jl index f8f12aa..ff8c6dd 100644 --- a/src/regressionmodel.jl +++ b/src/regressionmodel.jl @@ -45,7 +45,7 @@ function modelmatrix(model::RegressionModel; weighted::Bool=false) end """ crossmodelmatrix(model::RegressionModel; weighted::Bool=false) -Return `X'X` where `X` is the model matrix of `model` or, if `weighted=true`, `X'WX`, +Return `X'X` where `X` is the model/design matrix of `model` or, if `weighted=true`, `X'WX`, where `W` is the diagonal matrix whose elements are the model weights. This function will return a pre-computed matrix stored in `model` if possible. """ From e927f72e89d43d4fe8fecf9bdd10d6b6b66cfdfd Mon Sep 17 00:00:00 2001 From: Giuseppe Ragusa Date: Sat, 18 Jun 2022 13:07:35 +0200 Subject: [PATCH 12/15] Docs fixes --- src/regressionmodel.jl | 16 +++++++++------- src/statisticalmodel.jl | 19 +++++++++++++++---- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/regressionmodel.jl b/src/regressionmodel.jl index ff8c6dd..1e7fa45 100644 --- a/src/regressionmodel.jl +++ b/src/regressionmodel.jl @@ -36,9 +36,9 @@ function meanresponse end """ modelmatrix(model::RegressionModel; weighted::Bool=false) -Return the model matrix (a.k.a. the design matrix) or, if `weighted=true` the weighted -model matrix, i.e. `X' * sqrt.(W)`, where `X` is the model matrix and -`W` is the diagonal matrix whose elements are the model weights. +Return the model matrix (design matrix) or, if `weighted=true` the weighted +model matrix, i.e. `X * sqrt.(W)`, where `X` is the model matrix and +`W` is the diagonal matrix whose elements are the [model weights](@ref weights(::StatisticalModel)). """ function modelmatrix(model::RegressionModel; weighted::Bool=false) end @@ -46,7 +46,7 @@ function modelmatrix(model::RegressionModel; weighted::Bool=false) end crossmodelmatrix(model::RegressionModel; weighted::Bool=false) Return `X'X` where `X` is the model/design matrix of `model` or, if `weighted=true`, `X'WX`, -where `W` is the diagonal matrix whose elements are the model weights. +where `W` is the diagonal matrix whose elements are the [model weights](@ref weights(::StatisticalModel)). This function will return a pre-computed matrix stored in `model` if possible. """ function crossmodelmatrix(model::RegressionModel; weighted::Bool=false) @@ -71,11 +71,13 @@ of each data point. function cooksdistance end """ - residuals(model::RegressionModel) + residuals(model::RegressionModel; weighted::Bool=false) + +Return the residuals of the model or, if `weighted=true`, the residuals multiplied by +the square root of the [model weights](@ref weights(::StatisticalModel)). -Return the residuals of the model. """ -function residuals end +function residuals(model::RegressionModel; weighted::Bool=false) end """ predict(model::RegressionModel, [newX]) diff --git a/src/statisticalmodel.jl b/src/statisticalmodel.jl index 1babd65..fafb8fa 100644 --- a/src/statisticalmodel.jl +++ b/src/statisticalmodel.jl @@ -317,10 +317,21 @@ const adjr² = adjr2 """ momentmatrix(model::StatisticalModel) - -Return the matrix containing the estimating equation. -For linear regression models, the moment matrix is given by `u*X`, -where `u` is the vector of residuals and `X` is the model matrix. +Return the matrix containing the empirical moments defining the estimated parameters. + +For likelihood-based models, `momentmatrix` returns the log-score, i.e. the gradient +of the log-likelihood evaluated at each observation. For semiparametric models, each row +of the `(n×k)` matrix returned by `momentmatrix` is `m(Zᵢ, β̂)`, where `m(⋅, ⋅)` +is a vector-valued function evaluated at the estimated parameter `β̂` and `Zᵢ` is the +vector of data for entity `i`. The vector-valued function satisfies `∑ᵢm(Zᵢ, β̂) = 0`. + +For linear and generalized linear models, the parameters of interest are the coefficients +of the linear predictor. The moment matrix of a linear model is given by `u.*X`, +where `u` is the vector of residuals and `X` is the model matrix. The moment matrix of +a generalized linear model with link function `g`, the moment matrix is `X'e`, where `e` +is given by `Y-g⁻¹(X'β̂)` where `X` is the model matrix, `Y` is the model response, and +`β̂` is the vector of estimated coefficients. """ function momentmatrix end + From ab928fa206e0956dce2135e72b12c25221edac6c Mon Sep 17 00:00:00 2001 From: Giuseppe Ragusa Date: Tue, 21 Jun 2022 16:51:13 +0200 Subject: [PATCH 13/15] Improve docs --- src/statisticalmodel.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/statisticalmodel.jl b/src/statisticalmodel.jl index fafb8fa..2539420 100644 --- a/src/statisticalmodel.jl +++ b/src/statisticalmodel.jl @@ -322,16 +322,16 @@ Return the matrix containing the empirical moments defining the estimated parame For likelihood-based models, `momentmatrix` returns the log-score, i.e. the gradient of the log-likelihood evaluated at each observation. For semiparametric models, each row -of the `(n×k)` matrix returned by `momentmatrix` is `m(Zᵢ, β̂)`, where `m(⋅, ⋅)` -is a vector-valued function evaluated at the estimated parameter `β̂` and `Zᵢ` is the -vector of data for entity `i`. The vector-valued function satisfies `∑ᵢm(Zᵢ, β̂) = 0`. +of the ``(n \\times k)`` matrix returned by `momentmatrix` is ``m(Z_i, b)``, where `m` +is a vector-valued function evaluated at the estimated parameter `b` and ``Z_i`` is the +vector of data for entity `i`. The vector-valued function satisfies ``\\sum_{i=1}^n m(Z_i, b) = 0``. For linear and generalized linear models, the parameters of interest are the coefficients of the linear predictor. The moment matrix of a linear model is given by `u.*X`, where `u` is the vector of residuals and `X` is the model matrix. The moment matrix of a generalized linear model with link function `g`, the moment matrix is `X'e`, where `e` -is given by `Y-g⁻¹(X'β̂)` where `X` is the model matrix, `Y` is the model response, and -`β̂` is the vector of estimated coefficients. +is given by ``Y-g^{-1}(X'b)`` where `X` is the model matrix, `Y` is the model response, and +`b` is the vector of estimated coefficients. """ function momentmatrix end From 2858ba0736a9eba01382531e970f20c3da7feba2 Mon Sep 17 00:00:00 2001 From: Giuseppe Ragusa Date: Wed, 19 Oct 2022 11:16:54 +0200 Subject: [PATCH 14/15] Update src/regressionmodel.jl to reflect reviewer suggestions Co-authored-by: Milan Bouchet-Valat --- src/regressionmodel.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/regressionmodel.jl b/src/regressionmodel.jl index 1e7fa45..25e9a66 100644 --- a/src/regressionmodel.jl +++ b/src/regressionmodel.jl @@ -40,7 +40,7 @@ Return the model matrix (design matrix) or, if `weighted=true` the weighted model matrix, i.e. `X * sqrt.(W)`, where `X` is the model matrix and `W` is the diagonal matrix whose elements are the [model weights](@ref weights(::StatisticalModel)). """ -function modelmatrix(model::RegressionModel; weighted::Bool=false) end +function modelmatrix end """ crossmodelmatrix(model::RegressionModel; weighted::Bool=false) From 06206add77e2d6fce3e07e738cbb61d174814c50 Mon Sep 17 00:00:00 2001 From: Giuseppe Ragusa Date: Wed, 19 Oct 2022 11:28:56 +0200 Subject: [PATCH 15/15] 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 2539420..9680ecc 100644 --- a/src/statisticalmodel.jl +++ b/src/statisticalmodel.jl @@ -329,7 +329,7 @@ vector of data for entity `i`. The vector-valued function satisfies ``\\sum_{i=1 For linear and generalized linear models, the parameters of interest are the coefficients of the linear predictor. The moment matrix of a linear model is given by `u.*X`, where `u` is the vector of residuals and `X` is the model matrix. The moment matrix of -a generalized linear model with link function `g`, the moment matrix is `X'e`, where `e` +a a generalized linear model with link function `g` is `X'e`, where `e` is given by ``Y-g^{-1}(X'b)`` where `X` is the model matrix, `Y` is the model response, and `b` is the vector of estimated coefficients. """