QuantEcon.jl icon indicating copy to clipboard operation
QuantEcon.jl copied to clipboard

Add MLE estimation of Markov chains

Open jstac opened this issue 2 years ago • 1 comments

This is already accomplished on the Python side in https://github.com/QuantEcon/QuantEcon.py/pull/658

An ongoing discussion for the Julia side is here:

  • https://discourse.quantecon.org/t/estimate-markovchain-from-data-using-ml/239
  • https://discourse.quantecon.org/t/estimating-markov-chain-probabilities-in-julia-using-proportions/981

@msilva913 proposes

function estimate_markov(X::Vector, nstates::Int64)
    P = zeros(nstates, nstates)
    n = length(X) - 1
    for t = 1:n
        # add one each count is observed
        P[X[t], X[t+1]] = P[X[t], X[t+1]] + 1
    end
    for i = 1:nstates
        # divide by total number of counts
        P[i, :] .= P[i, :]/sum(P[i, :])
    end
    return P
end

Note that this will lead to division by zero errors for states that are never visited. The Python code handles this by dropping such states.

jstac avatar Dec 18 '22 18:12 jstac

Is it estimate_mc_discrete (#161)?

oyamad avatar Dec 19 '22 00:12 oyamad