giddy.markov.FullRank_Markov

class giddy.markov.FullRank_Markov(y, fill_empty_classes=False, summary=True)[source]

Full Rank Markov in which ranks are considered as Markov states rather than quantiles or other discretized classes. This is one way to avoid issues associated with discretization.

Parameters:
yarray

(n, t) with t>>n, one row per observation (n total), one column recording the value of each observation, with as many columns as time periods.

fill_empty_classes: bool

If True, assign 1 to diagonal elements which fall in rows full of 0s to ensure p is a stochastic transition probability matrix (each row sums up to 1).

summarybool

If True, print out the summary of the Markov Chain during initialization. Default is True.

Notes

Refer to [Rey14b] Equation (11) for details. Ties are resolved by assigning distinct ranks, corresponding to the order that the values occur in each cross section.

Examples

US nominal per capita income 48 states 81 years 1929-2009

>>> from giddy.markov import FullRank_Markov
>>> import libpysal as ps
>>> import numpy as np
>>> f = ps.io.open(ps.examples.get_path("usjoin.csv"))
>>> pci = np.array([f.by_col[str(y)] for y in range(1929,2010)]).transpose()
>>> m = FullRank_Markov(pci)
The Markov Chain is irreducible and is composed by:
1 Recurrent class (indices):
[ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47]
0 Transient classes.
The Markov Chain has 0 absorbing states.
>>> m.transitions
array([[66.,  5.,  5., ...,  0.,  0.,  0.],
       [ 8., 51.,  9., ...,  0.,  0.,  0.],
       [ 2., 13., 44., ...,  0.,  0.,  0.],
       ...,
       [ 0.,  0.,  0., ..., 40., 17.,  0.],
       [ 0.,  0.,  0., ..., 15., 54.,  2.],
       [ 0.,  0.,  0., ...,  2.,  1., 77.]])
>>> m.p[0, :5]
array([0.825 , 0.0625, 0.0625, 0.025 , 0.025 ])
>>> m.mfpt[0, :5]
array([48.        , 87.96280048, 68.1089084 , 58.83306575, 41.77250827])
>>> m.sojourn_time[:5]
array([5.71428571, 2.75862069, 2.22222222, 1.77777778, 1.66666667])
Attributes:
ranksarray

ranks of the original y array (by columns): higher values rank higher, e.g. the largest value in a column ranks 1.

parray

(n, n), transition probability matrix for Full Rank Markov.

steady_statearray

(n, ), ergodic distribution.

transitionsarray

(n, n), count of transitions between each rank i and j

mfptarray

(n, n), mean first passage times.

sojourn_timearray

(n, ), sojourn times.

__init__(y, fill_empty_classes=False, summary=True)[source]

Methods

__init__(y[, fill_empty_classes, summary])

Attributes

mfpt

sojourn_time

steady_state