randindx: Generates random indexes with a specified probability...

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

Returns an array of T indexes distributed as specified by p (which should be a normalized probability vector).

Usage

1
randindx(p, Total, NO_CHK)

Arguments

p

A row vector of normalized probabilities that dictate the transition probability from the current state to the next state. For example, p = [0.2, 0.8] indicates that the current state transitoins to state 1 at 0.2 and 2 at 0.8. The current state itself can either be the state 1 or 2.

Total

Total number of states needed to be generated using the input transition vector.

NO_CHK

Check whether the first argument is a valid row vector of normalized probabilities.

Details

The function is used by nbh_gen to generate random data point based on the user-supplied transition probability matrix.

Value

I

Index/Indices or state(s) sampled following the transition.

probability.

Author(s)

Yue Li

References

Capp\'e, O. (2001). H2M : A set of MATLAB/OCTAVE functions for the EM estimation of mixtures and hidden Markov models. (http://perso.telecom-paristech.fr/cappe/h2m/)

See Also

nbh_gen

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# Total contains the length of data to simulate
Total <- 100

# number of states
N <- 2

# transition probabilities between states
TRANS <- matrix(c(0.9, 0.1, 0.3, 0.7), nrow=2, byrow=TRUE)

label <- matrix(0, Total, 1)

# Simulate initial state
label[1] <- randindx(matrix(1,ncol=N)/N, 1, 1)

# Use Markov property for the following time index
for(t in 2:Total) {
	
	label[t] <- randindx(TRANS[label[t-1],], 1, 1)
}	

plot(label)

yueli-compbio/RIPSeeker documentation built on May 8, 2019, 2:34 a.m.