diff --git a/src/fit/utilities.jl b/src/fit/utilities.jl index 9d315a1..ea9e194 100644 --- a/src/fit/utilities.jl +++ b/src/fit/utilities.jl @@ -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) diff --git a/src/utilities.jl b/src/utilities.jl index 1024c8b..533e055 100644 --- a/src/utilities.jl +++ b/src/utilities.jl @@ -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))]