Skip to content

Commit

Permalink
Fix bug with collapsing when loadings matrix is all zeros
Browse files Browse the repository at this point in the history
  • Loading branch information
qntwrsm committed May 13, 2024
1 parent cbe8b90 commit db2382b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/fit/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,17 @@ function loglikelihood(model::DynamicFactorModel)
(n, T) = size(model)[1:end-1]
(_, _, v, F, _) = filter(model)

# active factors
active = [!all(iszero, λ) for λ eachcol(loadings(model))]

# annihilator matrix
(A_low, Z_basis) = collapse(model)
M = I - Z_basis * ((A_low * Z_basis) \ A_low)
if any(active)
(A_low, Z_basis) = collapse(model)
M = I - Z_basis * ((A_low * Z_basis) \ A_low)
else
A_low = I
M = Zeros(eltype(data(model)), n, n)
end

# covariance and precision matrices
H = cov(model)
Expand Down
9 changes: 8 additions & 1 deletion src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,15 @@ function state_space(model::DynamicFactorModel)
R = size(process(model))
Ty = eltype(data(model))

# active factors
active = [!all(iszero, λ) for λ eachcol(loadings(model))]

# collapsing matrix
(A_low, _) = collapse(model)
if any(active)
(A_low, _) = collapse(model)
else
A_low = I
end

# collapsing
y_low = [A_low * yt for yt eachcol(data(model))]
Expand Down

0 comments on commit db2382b

Please sign in to comment.