Displaying 4 results from an estimated 4 matches for "clusternum".
2017 Aug 28
5
"Improvement with the R code"
...tion 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 some rows of my data frame look like
checkdf=data.frame(clusterNum=c(3,2,3,1,1,3,4,3,2,1,1,3,2,1,3,2)
no_of_state=3
transition_matrix=matrix(NA,nrow=no_of_state, ncol=no_of_state)
for(k in 1: no_of_state)
{
count1=0
count2=0
count3=0
#For last point no transition takes place
for(j in 1: (nrow(checkdf)-1))
{
if(checkdf$clusterNum[j]==k)
{...
2017 Aug 28
0
"Improvement with the R code"
...source_state <- data[k]
dest_state <- data[k+1]
transitions[source_state, dest_state] <- transitions[source_state,
dest_state] + 1
}
for (k in 1:n_states)
transitions[k,] <- transitions[k,] / sum(transitions[k,])
transitions
}
checkdf=data.frame(clusterNum=c(3,2,3,1,1,3,4,3,2,1,1,3,2,1,3,2))
no_of_state=4
transition_matrix= generate_transition_matrix(checkdf$clusterNum,
no_of_state)
transition_matrix
2017-08-28 16:37 GMT+02:00 niharika singhal <niharikasinghal1990 at gmail.com>:
> Hello,
>
> I am trying to implement a formula
>...
2017 Aug 28
0
"Improvement with the R code"
...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)
prop.table(table(head(data, -1), tail(data, -1)), 1)[states,]
checkdf=data.frame(clusterNum=c(3,2,3,1,1,3,1,3,2,1,1,3,2,1,3,2))
states=c(2,3)
transition_matrix= generate_transition_matrix(checkdf$clusterNum, states)
transition_matrix
2017-08-28 18:09 GMT+02:00 niharika singhal <niharikasinghal1990 at gmail.com>:
> yes or S_i= number of state
>
> M[S_i][S_j]= transitio...
2017 Aug 28
0
"Improvement with the R code"
...;-
>>> transitions[source_state, dest_state] + 1
>>> }
>>>
>>> for (k in 1:n_states)
>>> transitions[k,] <- transitions[k,] / sum(transitions[k,])
>>> transitions
>>> }
>>>
>>> checkdf=data.frame(clusterNum=c(3,2,3,1,1,3,4,3,2,1,1,3,2,1,3,2))
>>> no_of_state=4
>>>
>>> transition_matrix= generate_transition_matrix(checkdf$clusterNum,
>>> no_of_state)
>>> transition_matrix
>>>
>>>
>>>
>>> 2017-08-28 16:37 GMT+02:00 niharika...