@@ -13,6 +13,7 @@ struct Fitted{D <: Distribution, T <: AbstractFloat}
13
13
llk:: T
14
14
coefs:: Vector{T}
15
15
numerical_hessian:: Matrix{T}
16
+ pearson_residuals:: Vector{T}
16
17
end
17
18
18
19
struct CoefsStats{T <: AbstractFloat }
@@ -29,13 +30,16 @@ struct EstimationStats{D <: Distribution, T <: AbstractFloat}
29
30
aic:: T
30
31
bic:: T
31
32
np:: T
33
+ jarquebera_p_value:: T
32
34
coefs_stats:: CoefsStats{T}
33
35
end
34
36
35
37
function results (f:: Fitted{D, T} ) where {D, T}
36
38
estim_results = eval_coefs_stats (f)
37
39
np = length (f. unknowns)
38
- return EstimationStats {D, T} (f. num_obs, f. llk, f. aic, f. bic, np, estim_results)
40
+ jarquebera_p_value = pvalue (JarqueBeraTest (f. pearson_residuals))
41
+ return EstimationStats {D, T} (f. num_obs, f. llk, f. aic, f. bic, np,
42
+ jarquebera_p_value, estim_results)
39
43
end
40
44
41
45
function eval_coefs_stats (f:: Fitted{D, T} ) where {D, T}
@@ -91,13 +95,18 @@ function update_aux_estimation!(aux_est::AuxEstimation{T}, func::Optim.TwiceDiff
91
95
return
92
96
end
93
97
94
- function fit (gas:: Model{D, T} , y:: Vector{T} ;
98
+ function fit! (gas:: Model{D, T} , y:: Vector{T} ;
95
99
initial_params:: Matrix{T} = DEFAULT_INITIAL_PARAM,
96
100
opt_method:: AbstractOptimizationMethod = NelderMead (gas, DEFAULT_NUM_SEEDS),
97
101
verbose:: Int = DEFAULT_VERBOSE,
98
102
throw_errors:: Bool = false ,
99
103
time_limit_sec:: Int = 10 ^ 8 ) where {D, T}
100
104
105
+ unknowns = find_unknowns (gas)
106
+ # Check if the model has no unknowns
107
+ n_unknowns = length (unknowns)
108
+ check_model_estimated (n_unknowns) && return gas
109
+
101
110
verbose in [0 , 1 , 2 , 3 ] || throw (ErrorException, " verbose argument must be in [0, 1, 2, 3]" )
102
111
# Number of initial_points and number of params to estimate
103
112
n_initial_points = length (opt_method. initial_points)
@@ -150,21 +159,12 @@ function fit(gas::Model{D, T}, y::Vector{T};
150
159
println (aux_est. opt_result[best_seed])
151
160
end
152
161
153
- return Fitted {D, T} (n, unknowns, aic, bic, best_llk, coefs, num_hessian)
154
- end
162
+ fill_psitilde! (gas, coefs, unknowns)
155
163
156
- function fit! (gas:: Model{D, T} , y:: Vector{T} ;
157
- initial_params:: Matrix{T} = DEFAULT_INITIAL_PARAM,
158
- opt_method:: AbstractOptimizationMethod = NelderMead (gas, DEFAULT_NUM_SEEDS),
159
- verbose:: Int = DEFAULT_VERBOSE,
160
- throw_errors:: Bool = false ) where {D, T}
164
+ # Calculate pearson residuals
165
+ pearson_res = isnan (initial_params[1 ]) ?
166
+ pearson_residuals (y, gas) :
167
+ pearson_residuals (y, gas; initial_params = initial_params)
161
168
162
- unknowns = find_unknowns (gas)
163
- # Check if the model has no unknowns
164
- n_unknowns = length (unknowns)
165
- check_model_estimated (n_unknowns) && return gas
166
-
167
- f = fit (gas, y; initial_params = initial_params, opt_method = opt_method, verbose = verbose, throw_errors = throw_errors)
168
- fill_psitilde! (gas, f. coefs, unknowns)
169
- return f
169
+ return Fitted {D, T} (n, unknowns, aic, bic, best_llk, coefs, num_hessian, pearson_res)
170
170
end
0 commit comments