@@ -122,7 +122,7 @@ const TableModels = Union{TableStatisticalModel, TableRegressionModel}
122122 StatsBase. stderror, StatsBase. vcov]
123123@delegate TableRegressionModel. model [StatsBase. modelmatrix,
124124 StatsBase. residuals, StatsBase. response,
125- StatsBase. predict, StatsBase. predict!,
125+ StatsBase. predict, StatsBase. predict!,
126126 StatsBase. cooksdistance]
127127StatsBase. predict (m:: TableRegressionModel , new_x:: AbstractMatrix ; kwargs... ) =
128128 predict (m. model, new_x; kwargs... )
@@ -189,7 +189,12 @@ function Base.show(io::IO, model::TableModels)
189189 println (io, model. mf. f)
190190 println (io)
191191 println (io," Coefficients:" )
192- show (io, ct)
192+ println (io, ct)
193+ if model isa TableRegressionModel
194+ println (io)
195+ println (" R²: " , round (r2 (model. model), sigdigits= 4 ))
196+ println (io, fstatistic (model))
197+ end
193198 catch e
194199 if isa (e, ErrorException) && occursin (" coeftable is not defined" , e. msg)
195200 show (io, model. model)
@@ -198,3 +203,28 @@ function Base.show(io::IO, model::TableModels)
198203 end
199204 end
200205end
206+
207+ struct FStatistic
208+ nobs:: Int64
209+ ndims:: Int64
210+ f:: Float64
211+ fprob:: Float64
212+ end
213+
214+ function fstatistic (obj:: TableRegressionModel )
215+ rss = deviance (obj)
216+ tss = nulldeviance (obj)
217+
218+ n = nobs (obj)
219+ p = length (coef (obj)) - 1 # minus intercept
220+ fstat = ((tss - rss) / p) / (rss / (n - p - 1 ))
221+ fdist = FDist (n, p)
222+
223+ FStatistic (n, p, fstat, ccdf .(fdist, abs (fstat)))
224+ end
225+
226+ function show (io:: IO , fstat:: FStatistic )
227+ print (io, " F-statistic: " , round (fstat. f, sigdigits= 4 ), " " )
228+ print (io, " on " , fstat. ndims, " and " , fstat. nobs, " degrees of freedom, " )
229+ print (io, " p-value: " , round (fstat. fprob, sigdigits= 4 ))
230+ end
0 commit comments