JuliaStats / GLM.jl

Generalized linear models in Julia
Other
584 stars 114 forks source link

Feature Request: Deviance Goodness of fit tests #527

Open itsdebartha opened 1 year ago

itsdebartha commented 1 year ago

I was thinking of implementing the deviance goodness of fit tests while calling the glm function. It'll be nice to know if the fitted model is meaningful or not right from the summary.

The null hypothesis could be the fact that the fitted model is as good as the null model, while the alternative is the fitted model is better than the null model. The distribution of the test statistic for this test follows asymptotically a chi-squared distribution

nalimilan commented 1 year ago

You mean something like the output of lrtest(null_model, model)?

One concern is that currently when an offset is provided, we have to fit the null model just to compute its log-likelihood. So this has a cost. Maybe that's not a problem if we assume that the summary is only printed for interactive use and not e.g. when bootstrapping or fitting hundreds of models.

itsdebartha commented 1 year ago

@nalimilan Yes, like the lrtest. But I was proposing to print a short result directly below the output of glm. Something like:

StatsModels.TableRegressionModel{GeneralizedLinearModel{GLM.GlmResp{Vector{Float64}, Binomial{Float64}, LogitLink}, GLM.DensePredChol{Float64, LinearAlgebra.CholeskyPivoted{Float64, Matrix{Float64}, Vector{Int64}}}}, Matrix{Float64}}

y ~ 1 + x1 + x2

Coefficients:
────────────────────────────────────────────────────────────────────────────
                  Coef.  Std. Error      z  Pr(>|z|)    Lower 95%  Upper 95%
────────────────────────────────────────────────────────────────────────────
(Intercept)  -6.94463     4.63484    -1.50    0.1340  -16.0287       2.13949
x1            0.0723796   0.0632414   1.14    0.2524   -0.0515712    0.19633
x2            0.978977    0.523473    1.87    0.0615   -0.0470123    2.00497
────────────────────────────────────────────────────────────────────────────

Deviance goodness of fit measure
null deviance: 27.725887222397812
residual deviance: 21.124205303875755
value under h_0: fitted model is as good as null model
outcome with 95% confidence: reject h_0
one-sided p-value: 0.03685216319850078