# Fit Markov Chain

Assume a simple Markov Chain with the transition matrix

n = 9;
matrix = Table[Piecewise[{{-c[i], And[i == j, i < n]}, {c[i], i + 1 == j}, {0,True}}], {i, n}, {j, n}];
matrix // MatrixForm and the starting point

ini[start_] := Table[If[i == start, 1, 0], {i, n}];


It looks like this

P[ini_] := ContinuousMarkovProcess[ini, matrix];
Graph[P[ini]] Now we run this Markov chain repeatedly for random times, beginning at random stages.

values = Table[c[i] -> 10 + Mod[i, 3], {i, n - 1}];
simulation[start_, t_] := Normal[RandomFunction[P[ini[start]] /. values, {0, t}]][[1, -1, 2]];
runs = 100;
dat = Table[ Module[{start = RandomInteger[{1, 3}], t = RandomReal[{.1, .4}]}, {t, {start, simulation[start, t]}}], runs];


For each data point, the first element is the time of the simulation and the second elements are the initial and final stages.

dat[[1 ;; 5]]

{{0.22866, {2, 5}}, {0.252981, {2, 4}}, {0.291232, {2, 6}}, {0.370085, {1, 6}}, {0.103945, {1, 2}}}


Is there an efficient way to fit the parameters $$c[i]$$ to this data?

Edit: If this is difficult, is there an easy way to estimate the mean transition time from stage $$i$$ to $$n$$, $$\sum_{i=1}^{n-1}\frac{1}{c[i]}$$?