On Sun, Mar 25, 2012 at 3:50 PM, stivi <muhamed19 at wp.pl>
wrote:> Hello,
>
> my question is if anyone has any good ideas how to create a Markov Chain
> from ordered data. So, I have some sort of time series, and if value1
> happens as time1 and value2 happens at time2 I record this as an update to
> the probability transition matrix. The problem is that I cannot predefine
> the size of the matrix (as I don't know how many states(values) I will
have
> in the end)
You could create a iter x n matrix of NA's and fill it up with a loop.
Or an empty list
ll <- list()
for(i in 1:3) ll[[i]] <- sample(10,i)
ll
Or, not very efficient, but you can also avoid predefining with something like
trans.prob <- .5
set.seed(1)
for(i in 2:12){
# if(some conditions) or calcs
trans.prob <- c( trans.prob , rbeta(1,12,1,trans.prob[i-1]) )
}
plot(trans.prob,type='l')
and don't really know how to update the prob distribution in
the> rows.
in a loop:
trans.prob.matrix[i, ] <- some.update.fun
> If anyone has any thoughts, i would be grateful for sharing.
If you'd read the posting guide and contemplated some existential
questions like "is it OK if the question (even if it's not) sounds
like homework ?" and "what's this obsession with providing
minimal,
reproducible code ? " than maybe the smaRter than me on this list will
be more inclined to share their thoughts ...
Cheers
Elai
> Stivi
>
> --
> View this message in context:
http://r.789695.n4.nabble.com/Updating-a-Markov-Chain-tp4504156p4504156.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.