diff --git a/src/ftest.jl b/src/ftest.jl index d1adebfb..50ac9c4f 100644 --- a/src/ftest.jl +++ b/src/ftest.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 2d23715f..41120ffa 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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) @@ -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