Skip to content

Commit 8f08ab0

Browse files
Merge pull request #305 from LAMPSPUC/fix_std_err_calculation
Fix std err calculations
2 parents 6a825f7 + 27d88c6 commit 8f08ab0

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "StateSpaceModels"
22
uuid = "99342f36-827c-5390-97c9-d7f9ee765c78"
33
authors = ["raphaelsaavedra <[email protected]>, guilhermebodin <[email protected]>, mariohsouto"]
4-
version = "0.6.0"
4+
version = "0.6.1"
55

66
[deps]
77
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"

src/fit.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function fit!(
5151
if save_hyperparameter_distribution
5252
numerical_hessian = Optim.hessian!(func, opt_hyperparameters)
5353
try
54-
std_err = numerical_hessian |> pinv |> diag .|> sqrt
54+
std_err = sqrt.(diag(inv(numerical_hessian)) ./ (num_observations(model) - filter.skip_llk_instants))
5555
fill_results!(model, opt_loglikelihood, std_err)
5656
catch
5757
@warn(

src/models/common.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ num_series(model::StateSpaceModel) = num_series(system(model))
44
system(model::StateSpaceModel) = model.system
55
isunivariate(model::StateSpaceModel) = isa(model.system.y, Vector)
66
model_name(model::StateSpaceModel) = "$(typeof(model))"
7-
length_observations(model::StateSpaceModel) = length(model.system.y)
7+
num_observations(model::StateSpaceModel) = length(model.system.y)
88
observations(model::StateSpaceModel) = model.system.y
99

1010
function lagmat(y::Vector{Fl}, k::Int) where Fl

src/models/naive_models.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function isfitted(model::NaiveModel)
55
end
66

77
isunivariate(model::NaiveModel) = true
8-
length_observations(model::NaiveModel) = length(model.y)
8+
num_observations(model::NaiveModel) = length(model.y)
99
observations(model::NaiveModel) = model.y
1010
get_standard_residuals(model::NaiveModel) = model.residuals ./ sqrt(model.sigma2)
1111
typeof_model_elements(model::NaiveModel) = eltype(model.y)

src/visualization/forecast.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
for d in eachindex(dists)
88
dists[d] = Normal(forec.expected_value[d][1], sqrt(forec.covariance[d][1]))
99
end
10-
n = length_observations(model)
10+
n = num_observations(model)
1111
forec_idx = collect(n + 1: n + length(forec.expected_value))
1212
fillrange_color = :steelblue
1313
# Plot the series
@@ -47,7 +47,7 @@ RecipesBase.@recipe function f(model::Union{StateSpaceModel, NaiveModel},
4747
if !isunivariate(model)
4848
error("This plot recipe currently works for univariate models only.")
4949
end
50-
n = length_observations(model)
50+
n = num_observations(model)
5151
n_scen = size(scenarios, 3)
5252
scenarios_idx = collect(n + 1: n + size(scenarios, 1))
5353
# Plot the series

0 commit comments

Comments
 (0)