Re: [R] "Improvement with the R code"

2017-08-28 Thread Berry, Charles
> On Aug 28, 2017, at 9:26 AM, Elie Canonici Merle > wrote: > > Chuck (Is it fine to call you Chuck?) In this forum, yes please. > I don't know much about pmin and factor but it might worth looking into if > you want to manipulate states by names (I assume this is why one might want > to use

Re: [R] "Improvement with the R code"

2017-08-28 Thread Elie Canonici Merle
Chuck (Is it fine to call you Chuck?) has far more R jutsu than I do obviously. I don't know much about pmin and factor but it might worth looking into if you want to manipulate states by names (I assume this is why one might want to use it?) generate_transition_matrix <- function(data, states)

Re: [R] "Improvement with the R code"

2017-08-28 Thread Elie Canonici Merle
Ok, I assumed you wanted to compute a matrix M for all states such that M[i][j]= transition from state i to state j / number of transition from state i but from what you just answered it looks like you want to compute a matrix M for a set of states S such that: M[S_i][S_j]= transition from stat

Re: [R] "Improvement with the R code"

2017-08-28 Thread Berry, Charles
All of this can be done without for loops. Use head(..., -1), tail(..., -1) to get the pre and post states. Use factor or pmin to recode them as necessary Use table(pre, post) to get the transition counts. Use prop.table(table_of_counts,1) to get the probabilities. HTH, Chuck > On Aug 28,

Re: [R] "Improvement with the R code"

2017-08-28 Thread Elie Canonici Merle
Hi, I think you overthought this one a little bit, I don't know if this is the kind of code you are expecting but I came up with something like that: generate_transition_matrix <- function(data, n_states) { #To be sure I imagine you should check n_states is right at this point transiti

[R] "Improvement with the R code"

2017-08-28 Thread niharika singhal
Hello, I am trying to implement a formula aij= transition from state S_i to S_j/no of transition at state S_i Code I have written is working with three state {1,2,3 }, but if the number of states become={1,2,3,4,..n} then the code will not work, so can some help me with this. For and s