@@ -63,10 +63,10 @@ function ftest(mod::LinearModel)
6363
6464 n = Int (nobs (mod))
6565 p = dof (mod) - 2 # -2 for intercept and dispersion parameter
66- fstat = (( tss - rss) / rss) * ((n - p - 1 ) / p)
66+ fstat = abs ((( tss - rss) / rss) * ((n - p - 1 ) / p) )
6767 fdist = FDist (p, dof_residual (mod))
6868
69- return SingleFTestResult (n, p, promote (fstat, ccdf (fdist, abs ( fstat) ))... )
69+ return SingleFTestResult (n, p, promote (fstat, ccdf (fdist, fstat))... )
7070end
7171
7272"""
@@ -77,9 +77,10 @@ the one model fits significantly better than the other. Models must have been fi
7777on the same data, and be nested either in forward or backward direction.
7878
7979A table is returned containing consumed degrees of freedom (DOF),
80- difference in DOF from the preceding model, sum of squared residuals (SSR), difference in
81- SSR from the preceding model, R², difference in R² from the preceding model, and F-statistic
82- and p-value for the comparison between the two models.
80+ absolute difference in DOF from the preceding model, sum of squared residuals (SSR),
81+ absolute difference in SSR from the preceding model, R², absolute difference in R²
82+ from the preceding model, and F-statistic and p-value for the comparison
83+ between the two models.
8384
8485!!! note
8586 This function can be used to perform an ANOVA by testing the relative fit of two models
@@ -110,22 +111,22 @@ julia> bigmodel = lm(@formula(Result ~ 1 + Treatment + Other), dat);
110111
111112julia> ftest(nullmodel, model)
112113F-test: 2 models fitted on 12 observations
113- ─────────────────────────────────────────────────────────────────
114- DOF ΔDOF SSR ΔSSR R² ΔR² F* p(>F)
115- ─────────────────────────────────────────────────────────────────
116- [1] 2 3.2292 0.0000
117- [2] 3 1 0.1283 - 3.1008 0.9603 0.9603 241.6234 <1e-07
118- ─────────────────────────────────────────────────────────────────
114+ ────────────────────────────────────────────────────────────────
115+ DOF ΔDOF SSR ΔSSR R² ΔR² F* p(>F)
116+ ────────────────────────────────────────────────────────────────
117+ [1] 2 3.2292 0.0000
118+ [2] 3 1 0.1283 3.1008 0.9603 0.9603 241.6234 <1e-07
119+ ────────────────────────────────────────────────────────────────
119120
120121julia> ftest(nullmodel, model, bigmodel)
121122F-test: 3 models fitted on 12 observations
122- ─────────────────────────────────────────────────────────────────
123- DOF ΔDOF SSR ΔSSR R² ΔR² F* p(>F)
124- ─────────────────────────────────────────────────────────────────
125- [1] 2 3.2292 0.0000
126- [2] 3 1 0.1283 - 3.1008 0.9603 0.9603 241.6234 <1e-07
127- [3] 5 2 0.1017 - 0.0266 0.9685 0.0082 1.0456 0.3950
128- ─────────────────────────────────────────────────────────────────
123+ ────────────────────────────────────────────────────────────────
124+ DOF ΔDOF SSR ΔSSR R² ΔR² F* p(>F)
125+ ────────────────────────────────────────────────────────────────
126+ [1] 2 3.2292 0.0000
127+ [2] 3 1 0.1283 3.1008 0.9603 0.9603 241.6234 <1e-07
128+ [3] 5 2 0.1017 0.0266 0.9685 0.0082 1.0456 0.3950
129+ ────────────────────────────────────────────────────────────────
129130```
130131"""
131132function ftest (mods:: LinearModel... ; atol:: Real = 0.0 )
@@ -153,7 +154,7 @@ function ftest(mods::LinearModel...; atol::Real=0.0)
153154 SSR = deviance .(mods)
154155
155156 df = dof .(mods)
156- Δdf = _diff (df)
157+ Δdf = abs .( _diff (df) )
157158 dfr = Int .(dof_residual .(mods))
158159 MSR1 = _diffn (SSR) ./ Δdf
159160 MSR2 = (SSR ./ dfr)
@@ -165,8 +166,8 @@ function ftest(mods::LinearModel...; atol::Real=0.0)
165166 dfr_big = dfr[1 : (end - 1 )]
166167 end
167168
168- fstat = ( NaN , (MSR1 ./ MSR2). .. )
169- pval = (NaN , ccdf .(FDist .(abs .( Δdf) , dfr_big), abs .( fstat[2 : end ]) )... )
169+ fstat = abs .(( NaN , (MSR1 ./ MSR2). .. ) )
170+ pval = (NaN , ccdf .(FDist .(Δdf, dfr_big), fstat[2 : end ])... )
170171
171172 return FTestResult (Int (nobs (mods[1 ])), SSR, df, r2 .(mods), fstat, pval)
172173end
@@ -179,9 +180,9 @@ function show(io::IO, ftr::SingleFTestResult)
179180end
180181
181182function show (io:: IO , ftr:: FTestResult{N} ) where {N}
182- Δdof = _diff (ftr. dof)
183- Δssr = _diff (ftr. ssr)
184- ΔR² = _diff (ftr. r2)
183+ Δdof = abs .( _diff (ftr. dof) )
184+ Δssr = abs .( _diff (ftr. ssr) )
185+ ΔR² = abs .( _diff (ftr. r2) )
185186
186187 nc = 9
187188 nr = N
0 commit comments