6
6
* `time_varying_params` map.
7
7
* Default link
8
8
9
- Right now when estimating a BetaFourParameters model is recomended to provide fixed parameters a and c, dont
9
+ Right now when estimating a BetaFourParameters model is recomended to provide fixed parameters a and c, dont
10
10
with the code:
11
11
12
12
```julia
@@ -15,49 +15,49 @@ gas_beta_4.ω[1] = minimum(y) - 0.1*std(y) # parameter a
15
15
gas_beta_4.ω[2] = maximum(y) + 0.1*std(y) # parameter c
16
16
```
17
17
18
- This code is a simple and not very accurate heuristic on how to estimate the a and c parameters. If you have estimated
18
+ This code is a simple and not very accurate heuristic on how to estimate the a and c parameters. If you have estimated
19
19
using maximum likelihood it will be probably better
20
20
21
- The fact occurs because if in the optimization the gradient makes `c < maximum(y)` or `a > minimum(y)` then it
21
+ The fact occurs because if in the optimization the gradient makes `c < maximum(y)` or `a > minimum(y)` then it
22
22
is impossible that y comes from the BetaFourParameters distribution leading to DomainErrors
23
23
"""
24
24
BetaFourParameters
25
25
26
26
function score! (score_til:: Matrix{T} , y:: T , :: Type{BetaFourParameters} , param:: Matrix{T} , t:: Int ) where T
27
27
score_til[t, 1 ] = - (param[t, 3 ] - 1 )/ (y - param[t, 1 ]) + (param[t, 4 ] + param[t, 3 ] - 1 )/ (param[t, 2 ] - param[t, 1 ])
28
28
score_til[t, 2 ] = (param[t, 4 ] - 1 )/ (param[t, 2 ] - y) - (param[t, 4 ] + param[t, 3 ] - 1 )/ (param[t, 2 ] - param[t, 1 ])
29
- score_til[t, 3 ] = log (y - param[t, 1 ]) - log (param[t, 2 ] - param[t, 1 ]) +
29
+ score_til[t, 3 ] = log (y - param[t, 1 ]) - log (param[t, 2 ] - param[t, 1 ]) +
30
30
digamma (param[t, 3 ] + param[t, 4 ]) - digamma (param[t, 3 ])
31
- score_til[t, 4 ] = log (param[t, 2 ] - y) - log (param[t, 2 ] - param[t, 1 ]) +
31
+ score_til[t, 4 ] = log (param[t, 2 ] - y) - log (param[t, 2 ] - param[t, 1 ]) +
32
32
digamma (param[t, 3 ] + param[t, 4 ]) - digamma (param[t, 4 ])
33
33
return
34
34
end
35
35
36
36
function log_likelihood (:: Type{BetaFourParameters} , y:: Vector{T} , param:: Matrix{T} , n:: Int ) where T
37
37
loglik = 0.0
38
38
for t in 1 : n
39
- loglik += (param[t, 3 ] - 1 )* log (y[t] - param[t, 1 ]) + (param[t, 4 ] - 1 ) * log (param[t, 2 ] - y[t]) -
39
+ loglik += (param[t, 3 ] - 1 )* log (y[t] - param[t, 1 ]) + (param[t, 4 ] - 1 ) * log (param[t, 2 ] - y[t]) -
40
40
(param[t, 3 ] + param[t, 4 ] - 1 ) * log (param[t, 2 ] - param[t, 1 ]) - logbeta (param[t, 3 ], param[t, 4 ])
41
41
end
42
42
return - loglik
43
43
end
44
44
45
45
# Links
46
- function link! (param_tilde:: Matrix{T} , :: Type{BetaFourParameters} , param:: Matrix{T} , t:: Int ) where T
46
+ function link! (param_tilde:: Matrix{T} , :: Type{BetaFourParameters} , param:: Matrix{T} , t:: Int ) where T
47
47
param_tilde[t, 1 ] = link (IdentityLink, param[t, 1 ])
48
48
param_tilde[t, 2 ] = link (IdentityLink, param[t, 2 ])
49
49
param_tilde[t, 3 ] = link (LogLink, param[t, 3 ], zero (T))
50
50
param_tilde[t, 4 ] = link (LogLink, param[t, 4 ], zero (T))
51
51
return
52
52
end
53
- function unlink! (param:: Matrix{T} , :: Type{BetaFourParameters} , param_tilde:: Matrix{T} , t:: Int ) where T
53
+ function unlink! (param:: Matrix{T} , :: Type{BetaFourParameters} , param_tilde:: Matrix{T} , t:: Int ) where T
54
54
param[t, 1 ] = unlink (IdentityLink, param_tilde[t, 1 ])
55
55
param[t, 2 ] = unlink (IdentityLink, param_tilde[t, 2 ])
56
56
param[t, 3 ] = unlink (LogLink, param_tilde[t, 3 ], zero (T))
57
57
param[t, 4 ] = unlink (LogLink, param_tilde[t, 4 ], zero (T))
58
58
return
59
59
end
60
- function jacobian_link! (aux:: AuxiliaryLinAlg{T} , :: Type{BetaFourParameters} , param:: Matrix{T} , t:: Int ) where T
60
+ function jacobian_link! (aux:: AuxiliaryLinAlg{T} , :: Type{BetaFourParameters} , param:: Matrix{T} , t:: Int ) where T
61
61
aux. jac[1 ] = jacobian_link (IdentityLink, param[t, 1 ])
62
62
aux. jac[2 ] = jacobian_link (IdentityLink, param[t, 2 ])
63
63
aux. jac[3 ] = jacobian_link (LogLink, param[t, 3 ], zero (T))
69
69
function update_dist (:: Type{BetaFourParameters} , param:: Matrix{T} , t:: Int ) where T
70
70
small_threshold! (param[:, 3 : 4 ], SMALL_NUM, t)
71
71
beta = Beta (param[t, 3 ], param[t, 4 ])
72
- return LocationScale (param[t, 1 ], param[t, 2 ] - param[t, 1 ], beta)
73
- end
72
+ return AffineDistribution (param[t, 1 ], param[t, 2 ] - param[t, 1 ], beta)
73
+ end
74
74
75
75
function params_sdm (d:: BetaFourParameters )
76
76
return (d. μ, d. σ + d. μ, Distributions. params (d. ρ)... )
79
79
function num_params (:: Type{BetaFourParameters} )
80
80
return 4
81
81
end
82
-
83
- # d = Beta(1, 1)
84
- # d2 = LocationScale(-1, 3, d)
85
- # maximum(d2)
86
- # minimum(d2)
0 commit comments