Open azev77 opened 4 years ago
Maybe something for https://discourse.julialang.org/ ?
@mschauer I posted this as sample code in case someone is working on a PR. Are there plans to include Wald/LR/LM in HypothesisTests.jl?
See https://github.com/JuliaStats/StatsModels.jl/pull/162 for the likelihood ratio test. I think other tests for models should go to StatsModels or GLM rather than HypothesisTests, as the latter shouldn't depend on other packages.
I agree. HypothesisTests.jl shouldn't depend on other packages.
My code for LR test is for any estimated models which work w/ loglikelihood(m)
.
The only thing it depends on is cdf(Chisq(df), LR)
.
# Likelihood Ratio Test
function HT_LR(mH0, mHA)
LR = 2.0*(loglikelihood(mHA) - loglikelihood(mH0)) |> abs
df = dof_residual(mH0) - dof_residual(mHA) |> abs
pv = 1 - cdf(Chisq(df), LR)
return LR, pv, df
end
I think a trinity tests package would be nice. I would be happy to contribute to this in the future.
PS i whink it would also be nice to have a @formula
syntax to make this, such as @formula(x =0, y = 0)
and make a matrix of restrictions base on that.
Aye. I have code for Wald testing and there is the hypothesis contrasts at StatsModels that could be expanded. We should work on specifying linear combinations and hypothesis tests based on those.
Reopen, it makes sense to discuss this here
@pdeffebach I'd prefer the classic trinity tests be in this repo.
Can we return to the conversation about where hypothesis tests should live in Julia? To me the most obvious & natural place is in a repo called "HypothesisTests.jl". Just like most distributions are in "Distributions.jl". If not, then what's the purpose of "HypothesisTests.jl"?
I feel like keeping as many hypothesis tests as possible in this repo will encourage others to contribute. It would certainly make me more likely to wanna contribute.
I don't see why dependencies are an necessarily an issue. I wrote code for an LRT that doesn't depend on anything (except Chiqsuared distribution).
Our plan was to move all model-related functions to anew StatsModelsBase package, which would contain the essential parts of the currents StatsModels. In that case, HypothesisTests would have to depend on StatsModelsBase to be able to call deviance
and co. (In the long term StatsBase is supposed to go away in favor of Statistics + StatsModelsBase and possibly others.) Anyway I don't see the problem with having these functions in one package or another. Anyway you'll have to read the documentation for StatsModels to learn how to fit models.
Cc: @kleinschmidt
@nalimilan this is interesting, I wanna learn more.
One advantage of having Hyp Tests together (when possible) is it makes it easier for the user to discover & compare. There are often many different tests one can use for a given hypothesis. Each has it's own advantages. For example, Wald has better power than Score, but Score has better size than Wald. Keeping tests together makes it easier to discover, compute each tests power/size etc.
Mathematica has several goodness of fit tests. You can automatically compare results:
Furthermore, they can automate selecting the optimal
test for a given dataset
DistributionFitTest[data,dist,Automatic] will choose the most powerful test that applies to data and dist for a general alternative hypothesis.
I feel like these things are easier to cooperate on if we work together in the same repo, whichever repo is decided on...
Yes but they could live in StatsModels.
I don't have much of an opinion one way or another. I suspect that even a trimmed down StatsModelsBase would still contain more than just the function definitions, so I could see being less willing to take it on as a dependency here. But on the other hand I'm sympathetic to the desire to keep hypothesis tests in one place, and this package is the natural place for them.
@nalimilan @kleinschmidt
The score (LM) test requires the score function & informationmatrix of a model.
I've been looking around JuliaStats & found:
StatsBase.informationmatrix(mHA)
StatsBase.score(mHA)
They currently don't work w/ GLM. Will these eventually be able to return score/info for any appropriate fitted model?
I added those to the API as those are necessary components for robust variance-covariance estimators vcov(model; ...)
.
GLM just needs to implement those. I believe Econometrics.jl does implement those.
StatsModels 0.6.12 has just been released which contains the LR test (from JuliaStats/StatsModels.jl#162)
My field uses a lot of likelihood ratio and related test statistics, Wald etc. I wonder if it's worth splitting a package out for that, for reference, see Chapter 3 of: https://arxiv.org/pdf/1007.1727.pdf
Essentially, given a Likelihood function L(θs::Vector{Float64})::Float64
, our likelihood ratio would be a 1D function of parameter of interest (POI), call it μ
, and assume it's the first among original θs
:
const global_MLL = L(MLE_θs)
function LR(μ::Float64)
other_θs = # conditional estimator while fixing POI μ
L(vcat(μ, other_θs)) / global_MLL
end
then we develop test statistics t_0
and t_μ
and obtain p-value
and interval by integrating the value of test statistics etc.
@nosferican mentioned this in #121 also on discourse... I coded up some classical hypothesis tests (HT). I need help w/ the score test. Does anyone know how to obtain the loglik functions after
glm
?