Skip to content

Commit 6907d3d

Browse files
committed
remove error methods, leaving stubs
1 parent 39945cf commit 6907d3d

File tree

3 files changed

+39
-48
lines changed

3 files changed

+39
-48
lines changed

src/StatsAPI.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ include("statisticalmodel.jl")
88
99
Return all parameters of a model.
1010
"""
11-
params(model) = error("params is not defined for $(typeof(model))")
11+
function params end
1212

1313
function params! end
1414

src/regressionmodel.jl

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,50 +10,51 @@ abstract type RegressionModel <: StatisticalModel end
1010
1111
Return the fitted values of the model.
1212
"""
13-
fitted(model::RegressionModel) = error("fitted is not defined for $(typeof(model)).")
13+
function fitted end
1414

1515
"""
1616
response(model::RegressionModel)
1717
1818
Return the model response (a.k.a. the dependent variable).
1919
"""
20-
response(model::RegressionModel) = error("response is not defined for $(typeof(model)).")
20+
function response end
2121

2222
"""
2323
responsename(model::RegressionModel)
2424
2525
Return the name of the model response (a.k.a. the dependent variable).
2626
"""
27-
responsename(model::RegressionModel) = error("responsename is not defined for $(typeof(model)).")
27+
function responsename end
2828

2929
"""
3030
meanresponse(model::RegressionModel)
3131
3232
Return the mean of the response.
3333
"""
34-
meanresponse(model::RegressionModel) = error("meanresponse is not defined for $(typeof(model)).")
34+
function meanresponse end
3535

3636
"""
3737
modelmatrix(model::RegressionModel)
3838
3939
Return the model matrix (a.k.a. the design matrix).
4040
"""
41-
modelmatrix(model::RegressionModel) = error("modelmatrix is not defined for $(typeof(model)).")
41+
function modelmatrix end
4242

4343
"""
4444
crossmodelmatrix(model::RegressionModel)
4545
4646
Return `X'X` where `X` is the model matrix of `model`.
4747
This function will return a pre-computed matrix stored in `model` if possible.
4848
"""
49+
function crossmodelmatrix end
4950
crossmodelmatrix(model::RegressionModel) = (x = modelmatrix(model); Symmetric(x' * x))
5051

5152
"""
5253
leverage(model::RegressionModel)
5354
5455
Return the diagonal of the projection matrix of the model.
5556
"""
56-
leverage(model::RegressionModel) = error("leverage is not defined for $(typeof(model)).")
57+
function leverage end
5758

5859
"""
5960
cooksdistance(model::RegressionModel)
@@ -62,14 +63,14 @@ Compute [Cook's distance](https://en.wikipedia.org/wiki/Cook%27s_distance)
6263
for each observation in linear model `model`, giving an estimate of the influence
6364
of each data point.
6465
"""
65-
cooksdistance(model::RegressionModel) = error("cooksdistance is not defined for $(typeof(model)).")
66+
function cooksdistance end
6667

6768
"""
6869
residuals(model::RegressionModel)
6970
7071
Return the residuals of the model.
7172
"""
72-
residuals(model::RegressionModel) = error("residuals is not defined for $(typeof(model)).")
73+
function residuals end
7374

7475
"""
7576
predict(model::RegressionModel, [newX])
@@ -80,20 +81,16 @@ it would generally be a `DataFrame` with the same variable names as the original
8081
"""
8182
function predict end
8283

83-
predict(model::RegressionModel) = error("predict is not defined for $(typeof(model)).")
84-
8584
"""
8685
predict!
8786
8887
In-place version of [`predict`](@ref).
8988
"""
9089
function predict! end
9190

92-
predict!(model::RegressionModel) = error("predict! is not defined for $(typeof(model)).")
93-
9491
"""
9592
dof_residual(model::RegressionModel)
9693
9794
Return the residual degrees of freedom of the model.
9895
"""
99-
dof_residual(model::RegressionModel) = error("dof_residual is not defined for $(typeof(model)).")
96+
function dof_residual end

src/statisticalmodel.jl

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ abstract type StatisticalModel end
1010
1111
Return the coefficients of the model.
1212
"""
13-
coef(model::StatisticalModel) = error("coef is not defined for $(typeof(model)).")
13+
function coef end
1414

1515
"""
1616
coefnames(model::StatisticalModel)
1717
1818
Return the names of the coefficients.
1919
"""
20-
coefnames(model::StatisticalModel) = error("coefnames is not defined for $(typeof(model)).")
20+
function coefnames end
2121

2222
"""
2323
coeftable(model::StatisticalModel; level::Real=0.95)
@@ -29,14 +29,14 @@ The returned `CoefTable` object implements the
2929
[Tables.jl](https://github.com/JuliaData/Tables.jl/) interface, and can be
3030
converted e.g. to a `DataFrame` via `using DataFrames; DataFrame(coeftable(model))`.
3131
"""
32-
coeftable(model::StatisticalModel) = error("coeftable is not defined for $(typeof(model)).")
32+
function coeftable end
3333

3434
"""
3535
confint(model::StatisticalModel; level::Real=0.95)
3636
3737
Compute confidence intervals for coefficients, with confidence level `level` (by default 95%).
3838
"""
39-
confint(model::StatisticalModel) = error("confint is not defined for $(typeof(model)).")
39+
function confint end
4040

4141
"""
4242
deviance(model::StatisticalModel)
@@ -45,39 +45,36 @@ Return the deviance of the model relative to a reference, which is usually when
4545
the saturated model. It is equal, *up to a constant*, to ``-2 \\log L``, with ``L``
4646
the likelihood of the model.
4747
"""
48-
deviance(model::StatisticalModel) = error("deviance is not defined for $(typeof(model)).")
48+
function deviance end
4949

5050
"""
5151
islinear(model::StatisticalModel)
5252
5353
Indicate whether the model is linear.
5454
"""
55-
islinear(model::StatisticalModel) = error("islinear is not defined for $(typeof(model)).")
55+
function islinear end
5656

5757
"""
5858
nulldeviance(model::StatisticalModel)
5959
6060
Return the deviance of the null model, that is the one including only the intercept.
6161
"""
62-
nulldeviance(model::StatisticalModel) =
63-
error("nulldeviance is not defined for $(typeof(model)).")
62+
function nulldeviance end
6463

6564
"""
6665
loglikelihood(model::StatisticalModel)
6766
6867
Return the log-likelihood of the model.
6968
"""
70-
loglikelihood(model::StatisticalModel) =
71-
error("loglikelihood is not defined for $(typeof(model)).")
69+
function loglikelihood end
7270

7371
"""
7472
loglikelihood(model::StatisticalModel)
7573
7674
Return the log-likelihood of the null model corresponding to `model`.
7775
This is usually the model containing only the intercept.
7876
"""
79-
nullloglikelihood(model::StatisticalModel) =
80-
error("nullloglikelihood is not defined for $(typeof(model)).")
77+
function nullloglikelihood end
8178

8279
"""
8380
loglikelihood(model::StatisticalModel, ::Colon)
@@ -87,24 +84,22 @@ In other words, this is the vector of the pointwise log-likelihood contributions
8784
8885
In general, `sum(loglikehood(model, :)) == loglikelihood(model)`.
8986
"""
90-
loglikelihood(model::StatisticalModel, ::Colon) =
91-
error("loglikelihood(model::StatisticalModel, ::Colon) is not defined for $(typeof(model)).")
87+
function loglikelihood end
9288

9389
"""
9490
loglikelihood(model::StatisticalModel, observation)
9591
9692
Return the contribution of `observation` to the log-likelihood of `model`.
9793
"""
98-
loglikelihood(model::StatisticalModel, observation) =
99-
error("loglikelihood(model::StatisticalModel, observation) is not defined for $(typeof(model)).")
94+
function loglikelihood end
10095

10196
"""
10297
score(model::StatisticalModel)
10398
10499
Return the score of the model, that is the gradient of the
105100
log-likelihood with respect to the coefficients.
106101
"""
107-
score(model::StatisticalModel) = error("score is not defined for $(typeof(model)).")
102+
function score end
108103

109104
"""
110105
nobs(model::StatisticalModel)
@@ -114,76 +109,75 @@ when using this information, as the definition of an independent observation may
114109
depending on the model, on the format used to pass the data, on the sampling plan
115110
(if specified), etc.
116111
"""
117-
nobs(model::StatisticalModel) = error("nobs is not defined for $(typeof(model)).")
112+
function nobs end
118113

119114
"""
120115
dof(model::StatisticalModel)
121116
122117
Return the number of degrees of freedom consumed in the model, including
123118
when applicable the intercept and the distribution's dispersion parameter.
124119
"""
125-
dof(model::StatisticalModel) = error("dof is not defined for $(typeof(model)).")
120+
function dof end
126121

127122
"""
128123
mss(model::StatisticalModel)
129124
130125
Return the model sum of squares.
131126
"""
132-
mss(model::StatisticalModel) = error("mss is not defined for $(typeof(model)).")
127+
function mss end
133128

134129
"""
135130
rss(model::StatisticalModel)
136131
137132
Return the residual sum of squares of the model.
138133
"""
139-
rss(model::StatisticalModel) = error("rss is not defined for $(typeof(model)).")
134+
function rss end
140135

141136
"""
142137
informationmatrix(model::StatisticalModel; expected::Bool = true)
143138
144139
Return the information matrix of the model. By default the Fisher information matrix
145140
is returned, while the observed information matrix can be requested with `expected = false`.
146141
"""
147-
informationmatrix(model::StatisticalModel; expected::Bool=true) =
148-
error("informationmatrix is not defined for $(typeof(model)).")
142+
function informationmatrix end
149143

150144
"""
151145
stderror(model::StatisticalModel)
152146
153147
Return the standard errors for the coefficients of the model.
154148
"""
155-
stderror(model::StatisticalModel) = sqrt.(diag(vcov(model)))
149+
function stderror end
156150

157151
"""
158152
vcov(model::StatisticalModel)
159153
160154
Return the variance-covariance matrix for the coefficients of the model.
161155
"""
162-
vcov(model::StatisticalModel) = error("vcov is not defined for $(typeof(model)).")
156+
function vcov end
163157

164158
"""
165159
weights(model::StatisticalModel)
166160
167161
Return the weights used in the model.
168162
"""
169-
weights(model::StatisticalModel) = error("weights is not defined for $(typeof(model)).")
163+
function weights end
170164

171165
"""
172166
isfitted(model::StatisticalModel)
173167
174168
Indicate whether the model has been fitted.
175169
"""
176-
isfitted(model::StatisticalModel) = error("isfitted is not defined for $(typeof(model)).")
170+
function isfitted end
177171

178172
"""
179173
Fit a statistical model.
180174
"""
181-
fit(model::StatisticalModel, args...) = error("fit is not defined for $(typeof(model)).")
175+
function fit end
182176

183177
"""
184178
Fit a statistical model in-place.
185179
"""
186-
fit!(model::StatisticalModel, args...) = error("fit! is not defined for $(typeof(model)).")
180+
function fit! end
187181

188182
"""
189183
aic(model::StatisticalModel)
@@ -192,7 +186,7 @@ Akaike's Information Criterion, defined as ``-2 \\log L + 2k``, with ``L`` the l
192186
of the model, and `k` its number of consumed degrees of freedom
193187
(as returned by [`dof`](@ref)).
194188
"""
195-
aic(model::StatisticalModel) = -2loglikelihood(model) + 2dof(model)
189+
function aic end
196190

197191
"""
198192
aicc(model::StatisticalModel)
@@ -202,7 +196,7 @@ defined as ``-2 \\log L + 2k + 2k(k-1)/(n-k-1)``, with ``L`` the likelihood of t
202196
``k`` its number of consumed degrees of freedom (as returned by [`dof`](@ref)),
203197
and ``n`` the number of observations (as returned by [`nobs`](@ref)).
204198
"""
205-
function aicc(model::StatisticalModel)
199+
function aicc end
206200
k = dof(model)
207201
n = nobs(model)
208202
-2loglikelihood(model) + 2k + 2k*(k+1)/(n-k-1)
@@ -216,7 +210,7 @@ the likelihood of the model, ``k`` its number of consumed degrees of freedom
216210
(as returned by [`dof`](@ref)), and ``n`` the number of observations
217211
(as returned by [`nobs`](@ref)).
218212
"""
219-
bic(model::StatisticalModel) = -2loglikelihood(model) + dof(model)*log(nobs(model))
213+
function bic end
220214

221215
"""
222216
r2(model::StatisticalModel)
@@ -227,7 +221,7 @@ Coefficient of determination (R-squared).
227221
For a linear model, the R² is defined as ``ESS/TSS``, with ``ESS`` the explained sum of squares
228222
and ``TSS`` the total sum of squares.
229223
"""
230-
r2(model::StatisticalModel) = error("r2/r² is not defined for $(typeof(model)).")
224+
function r2 end
231225

232226
const= r2
233227

@@ -241,6 +235,6 @@ For linear models, the adjusted R² is defined as ``1 - (1 - (1-R^2)(n-1)/(n-p))
241235
the coefficient of determination, ``n`` the number of observations, and ``p`` the number of
242236
coefficients (including the intercept). This definition is generally known as the Wherry Formula I.
243237
"""
244-
adjr2(model::StatisticalModel) = error("adjr2 is not defined for $(typeof(model)).")
238+
function adjr2 end
245239

246240
const adjr² = adjr2

0 commit comments

Comments
 (0)