-
Notifications
You must be signed in to change notification settings - Fork 10
/
regressionmodel.jl
181 lines (134 loc) · 4.76 KB
/
regressionmodel.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
"""
RegressionModel <: StatisticalModel
Abstract supertype for all regression models.
"""
abstract type RegressionModel <: StatisticalModel end
"""
fitted(model::RegressionModel)
Return the fitted values of the model.
"""
function fitted end
"""
response(model::RegressionModel)
Return the model response (a.k.a. the dependent variable).
"""
function response end
"""
responsename(model::RegressionModel)
Return the name of the model response (a.k.a. the dependent variable).
"""
function responsename end
"""
meanresponse(model::RegressionModel)
Return the mean of the response.
"""
function meanresponse end
"""
modelmatrix(model::RegressionModel)
Return the model matrix (a.k.a. the design matrix).
"""
function modelmatrix end
"""
crossmodelmatrix(model::RegressionModel)
Return `X'X` where `X` is the model matrix of `model`.
This function will return a pre-computed matrix stored in `model` if possible.
"""
crossmodelmatrix(model::RegressionModel) = (x = modelmatrix(model); Symmetric(x' * x))
"""
leverage(model::RegressionModel)
Return the diagonal of the projection matrix of the model.
"""
function leverage end
"""
cooksdistance(model::RegressionModel)
Compute [Cook's distance](https://en.wikipedia.org/wiki/Cook%27s_distance)
for each observation in linear model `model`, giving an estimate of the influence
of each data point.
"""
function cooksdistance end
"""
residuals(model::RegressionModel)
Return the residuals of the model.
"""
function residuals end
"""
predict(model::RegressionModel, [newX])
Form the predicted response of `model`. An object with new covariate values `newX` can be supplied,
which should have the same type and structure as that used to fit `model`; e.g. for a GLM
it would generally be a `DataFrame` with the same variable names as the original predictors.
"""
function predict end
"""
predict!
In-place version of [`predict`](@ref).
"""
function predict! end
"""
dof_residual(model::RegressionModel)
Return the residual degrees of freedom of the model.
"""
function dof_residual end
"""
reconstruct(model::RegressionModel[, newY])
Reconstruct explanatory variables from `model`.
An object with new response values `newX` can be supplied, which should have
the same type and structure as the output of [`predict(model)`](@ref).
"""
function reconstruct end
"""
reconstruct!
In-place version of [`reconstruct`](@ref).
"""
function reconstruct! end
"""
offset(model::RegressionModel)
Return the offset used in the model, i.e. the term added to the linear predictor with
known coefficient 1, or `nothing` if the model was not fit with an offset.
"""
function offset end
"""
linearpredictor(model::RegressionModel)
Return the model's linear predictor, `Xβ` where `X` is the model matrix and `β` is the
vector of coefficients, or `Xβ + offset` if the model was fit with an offset.
"""
function linearpredictor end
"""
linearpredictor!(storage, model::RegressionModel)
In-place version of [`linearpredictor`](@ref), storing the result in `storage`.
"""
function linearpredictor! end
"""
vif(m::RegressionModel)
Compute the variance inflation factor (VIF).
The [VIF](https://en.wikipedia.org/wiki/Variance_inflation_factor) measures
the increase in the variance of a parameter's estimate in a model with multiple parameters relative to
the variance of a parameter's estimate in a model containing only that parameter.
See also [`gvif`](@ref).
!!! warning
This method will fail if there is (numerically) perfect multicollinearity,
i.e. rank deficiency. In that case though, the VIF
is not particularly informative anyway.
"""
function vif end
# This generic function is owned by StatsModels.jl, which is the sole provider
# of the default definition.
"""
gvif(m::RegressionModel; scale=false)
Compute the generalized variance inflation factor (GVIF).
If `scale=true`, then each GVIF is scaled by the degrees of freedom
for (number of coefficients associated with) the predictor: ``GVIF^(1 / (2*df))``.
The [GVIF](https://doi.org/10.2307/2290467)
measures the increase in the variance of a (group of) parameter's estimate in a model
with multiple parameters relative to the variance of a parameter's estimate in a
model containing only that parameter. For continuous, numerical predictors, the GVIF
is the same as the VIF, but for categorical predictors, the GVIF provides a single
number for the entire group of contrast-coded coefficients associated with a categorical
predictor.
See also [`vif`](@ref).
## References
Fox, J., & Monette, G. (1992). Generalized Collinearity Diagnostics.
Journal of the American Statistical Association, 87(417), 178. doi:10.2307/2290467
"""
function gvif end
# This generic function is owned by StatsModels.jl, which is the sole provider
# of the default definition.