rdata1.hmm<-function(NUM, pii, A, f0, f1) { ## USAGE # rdata.hmm(n, pi, A, ...) ## ARGUEMENTS # NUM: sample size # pii=(pii[1], pii[2]): initial state distribution # A=(a00, a01 \\ a10 a11): transition matrix # f0: parameter set for the null distribution # f1: parameter set for the non-null mixture distribution ## DETAILS # xi are independent given si, which constitute a markov chain characterized # --by initial state distribution pi0 and transition matrix A ## VALUES # rdata1.hmm generates random variables # from a normal mixture via a hidden markov model # x: continuous observed data # theta: binary unobserved states theta<-rep(0, NUM) x<-rep(0, NUM) ## generating the states # initial state theta[1]<-rbinom(1, 1, pii[2]) # other states for (i in 2:NUM) { if (theta[i-1]==0) theta[i]<-rbinom(1, 1, A[1, 2]) else theta[i]<-rbinom(1, 1, A[2, 2]) } ## generating the observations for (i in 1:NUM) { if (theta[i]==0) { x[i]<-rnorm(1, mean=f0[1], sd=f0[2]) } else { x[i]<-rnorm(1, mean=f1[1], sd=f1[2]) } } data<-list(s=theta, o=x) return (data) }