Skip to content

Commit

Permalink
Allow only models with intercept in single-argument ftest
Browse files Browse the repository at this point in the history
  • Loading branch information
OndrejSlamecka committed Oct 17, 2021
1 parent 1d5fdb8 commit bc21522
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
7 changes: 6 additions & 1 deletion src/ftest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ F-statistic: 241.62 on 12 observations and 1 degrees of freedom, p-value: <1e-07
```
"""
function ftest(mod::LinearModel)
if !hasintercept(mod)
Base.warn("ftest only works for models with an intercept")
return nothing
end

rss = deviance(mod)
tss = hasintercept(mod) ? nulldeviance(mod) : sum(mod.rr.y .^ 2)
tss = nulldeviance(mod)

n = Int(nobs(mod))
p = dof(mod) - Int(hasintercept(mod)) - 1 # -1 for dispersion parameter
Expand Down
10 changes: 1 addition & 9 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,6 @@ end
othermod = lm(@formula(Result~Other), d).model
nullmod = lm(@formula(Result~1), d).model
bothmod = lm(@formula(Result~Other+Treatment), d).model
emptymod = lm(zeros((length(d.Result), 1)), d.Result)
nointerceptmod = lm(reshape(d.Treatment, :, 1), d.Result)

ft1 = ftest(mod)
Expand Down Expand Up @@ -699,14 +698,7 @@ end
end

ft4 = ftest(nointerceptmod)
ft4base = ftest(emptymod, nointerceptmod)
@test ft4.nobs == ft4base.nobs
@test ft4.dof dof(nointerceptmod) - dof(emptymod)
@test ft4.fstat ft4base.fstat[2]
@test ft4.pval ft4base.pval[2]
@test sprint(show, ft4) == """
F-test against the null model:
F-statistic: 2703.38 on 12 observations and 1 degrees of freedom, p-value: <1e-13"""
@test ft4 == nothing
end

@testset "F test for model comparison" begin
Expand Down

0 comments on commit bc21522

Please sign in to comment.