Simulation of Markov chain












0












$begingroup$


I wrote this algorithm on matlab to simulate a markov chain :



function X=markov_chain(n,cl1,cl2,A,p10,p20)
X=;
first_term=[p10 p20];
for x=1:n
X(x)=simulate(first_term(1),first_term(2),cl1,cl2);
first_term=first_term*A;
end
end


n is the desired length of the Markov chain cl1 and cl2 two values, A the transition matrix and p10 (resp. p20) the probability of being in the state 1 at t=0 (resp. state 2)
the simulate function returns either cl1 with probability first_term(1) or cl2 with probability first_term(2).
It seems like there is something wrong with what I've done. Indeed, my final goal is to estimate the transition matrix given a certain Markov chain. I found contradictory results and it seems like my code here doesn't really simulate a Markov chain, but I can't see why.










share|cite|improve this question











$endgroup$












  • $begingroup$
    Welcome to MSE. Please read this text about how to ask a good question.
    $endgroup$
    – José Carlos Santos
    Dec 6 '18 at 0:03










  • $begingroup$
    You’re using the $n$-step transition probabilities $A^n$ instead of the single-step probabilities $A$.
    $endgroup$
    – amd
    Dec 6 '18 at 0:05










  • $begingroup$
    why so? isn't the relation between the states at different times $t$: $x_t=x_{t-1}A$?
    $endgroup$
    – yjnt
    Dec 6 '18 at 0:11


















0












$begingroup$


I wrote this algorithm on matlab to simulate a markov chain :



function X=markov_chain(n,cl1,cl2,A,p10,p20)
X=;
first_term=[p10 p20];
for x=1:n
X(x)=simulate(first_term(1),first_term(2),cl1,cl2);
first_term=first_term*A;
end
end


n is the desired length of the Markov chain cl1 and cl2 two values, A the transition matrix and p10 (resp. p20) the probability of being in the state 1 at t=0 (resp. state 2)
the simulate function returns either cl1 with probability first_term(1) or cl2 with probability first_term(2).
It seems like there is something wrong with what I've done. Indeed, my final goal is to estimate the transition matrix given a certain Markov chain. I found contradictory results and it seems like my code here doesn't really simulate a Markov chain, but I can't see why.










share|cite|improve this question











$endgroup$












  • $begingroup$
    Welcome to MSE. Please read this text about how to ask a good question.
    $endgroup$
    – José Carlos Santos
    Dec 6 '18 at 0:03










  • $begingroup$
    You’re using the $n$-step transition probabilities $A^n$ instead of the single-step probabilities $A$.
    $endgroup$
    – amd
    Dec 6 '18 at 0:05










  • $begingroup$
    why so? isn't the relation between the states at different times $t$: $x_t=x_{t-1}A$?
    $endgroup$
    – yjnt
    Dec 6 '18 at 0:11
















0












0








0





$begingroup$


I wrote this algorithm on matlab to simulate a markov chain :



function X=markov_chain(n,cl1,cl2,A,p10,p20)
X=;
first_term=[p10 p20];
for x=1:n
X(x)=simulate(first_term(1),first_term(2),cl1,cl2);
first_term=first_term*A;
end
end


n is the desired length of the Markov chain cl1 and cl2 two values, A the transition matrix and p10 (resp. p20) the probability of being in the state 1 at t=0 (resp. state 2)
the simulate function returns either cl1 with probability first_term(1) or cl2 with probability first_term(2).
It seems like there is something wrong with what I've done. Indeed, my final goal is to estimate the transition matrix given a certain Markov chain. I found contradictory results and it seems like my code here doesn't really simulate a Markov chain, but I can't see why.










share|cite|improve this question











$endgroup$




I wrote this algorithm on matlab to simulate a markov chain :



function X=markov_chain(n,cl1,cl2,A,p10,p20)
X=;
first_term=[p10 p20];
for x=1:n
X(x)=simulate(first_term(1),first_term(2),cl1,cl2);
first_term=first_term*A;
end
end


n is the desired length of the Markov chain cl1 and cl2 two values, A the transition matrix and p10 (resp. p20) the probability of being in the state 1 at t=0 (resp. state 2)
the simulate function returns either cl1 with probability first_term(1) or cl2 with probability first_term(2).
It seems like there is something wrong with what I've done. Indeed, my final goal is to estimate the transition matrix given a certain Markov chain. I found contradictory results and it seems like my code here doesn't really simulate a Markov chain, but I can't see why.







statistics markov-chains






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Dec 5 '18 at 23:38









Bernard

120k740114




120k740114










asked Dec 5 '18 at 23:30









yjntyjnt

63




63












  • $begingroup$
    Welcome to MSE. Please read this text about how to ask a good question.
    $endgroup$
    – José Carlos Santos
    Dec 6 '18 at 0:03










  • $begingroup$
    You’re using the $n$-step transition probabilities $A^n$ instead of the single-step probabilities $A$.
    $endgroup$
    – amd
    Dec 6 '18 at 0:05










  • $begingroup$
    why so? isn't the relation between the states at different times $t$: $x_t=x_{t-1}A$?
    $endgroup$
    – yjnt
    Dec 6 '18 at 0:11




















  • $begingroup$
    Welcome to MSE. Please read this text about how to ask a good question.
    $endgroup$
    – José Carlos Santos
    Dec 6 '18 at 0:03










  • $begingroup$
    You’re using the $n$-step transition probabilities $A^n$ instead of the single-step probabilities $A$.
    $endgroup$
    – amd
    Dec 6 '18 at 0:05










  • $begingroup$
    why so? isn't the relation between the states at different times $t$: $x_t=x_{t-1}A$?
    $endgroup$
    – yjnt
    Dec 6 '18 at 0:11


















$begingroup$
Welcome to MSE. Please read this text about how to ask a good question.
$endgroup$
– José Carlos Santos
Dec 6 '18 at 0:03




$begingroup$
Welcome to MSE. Please read this text about how to ask a good question.
$endgroup$
– José Carlos Santos
Dec 6 '18 at 0:03












$begingroup$
You’re using the $n$-step transition probabilities $A^n$ instead of the single-step probabilities $A$.
$endgroup$
– amd
Dec 6 '18 at 0:05




$begingroup$
You’re using the $n$-step transition probabilities $A^n$ instead of the single-step probabilities $A$.
$endgroup$
– amd
Dec 6 '18 at 0:05












$begingroup$
why so? isn't the relation between the states at different times $t$: $x_t=x_{t-1}A$?
$endgroup$
– yjnt
Dec 6 '18 at 0:11






$begingroup$
why so? isn't the relation between the states at different times $t$: $x_t=x_{t-1}A$?
$endgroup$
– yjnt
Dec 6 '18 at 0:11












0






active

oldest

votes











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "69"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3027825%2fsimulation-of-markov-chain%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Mathematics Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3027825%2fsimulation-of-markov-chain%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Plaza Victoria

Puebla de Zaragoza

Musa