@@ -122,7 +122,7 @@ const TableModels = Union{TableStatisticalModel, TableRegressionModel}
122
122
StatsBase. stderror, StatsBase. vcov]
123
123
@delegate TableRegressionModel. model [StatsBase. modelmatrix,
124
124
StatsBase. residuals, StatsBase. response,
125
- StatsBase. predict, StatsBase. predict!,
125
+ StatsBase. predict, StatsBase. predict!,
126
126
StatsBase. cooksdistance]
127
127
StatsBase. predict (m:: TableRegressionModel , new_x:: AbstractMatrix ; kwargs... ) =
128
128
predict (m. model, new_x; kwargs... )
@@ -189,7 +189,12 @@ function Base.show(io::IO, model::TableModels)
189
189
println (io, model. mf. f)
190
190
println (io)
191
191
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
193
198
catch e
194
199
if isa (e, ErrorException) && occursin (" coeftable is not defined" , e. msg)
195
200
show (io, model. model)
@@ -198,3 +203,28 @@ function Base.show(io::IO, model::TableModels)
198
203
end
199
204
end
200
205
end
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