Hi all,
   I wrote the following function to generate data following a mixture-ar1
model.
   The model is described as below:

      theta is a m-vector with each entries identically and
independent Bernoulli trials with
success probability pi1.

       x is a m-vector with entries follow a ar1 model "x_{i+1}=rho * x_{i}
+ e_{i} + mu1 * theta[i]''.
In other words, the dependence is like ar1 model, however, the mean is mu1
or 0 according to
whether theta is 1 or 0.


I am not too familar with the r functions generating time series data. Can
some
one have a look at the function I wrote? Thank you very much!



rdata.mix.ar1<-function(pi1,m, rho, mu1)
{
## generate data from the following mixture-ar1 model:
## {theta[i]} is m-vector of iid bernoulli trials with
## success prob pi1.
## generate observations from a ar1 model:
##     x_{i}=rho * x_{i-1}+epslon_{i}+mu1*theta[i]
## in other word; if theta_{i} is 1, mean is mu1;
## otherwise mean is 0; but the
## dependence structure is like a ar1 model.

##pi1 <- 0.5
##m <- 10
##rho <- 0.6
##mu1 <- 1
set.seed(66)
## generate states
theta <-rbinom(m, 1, pi1)
## generate data
x <- arima.sim(list(order=c(1,0,0), ar=rho), n=m)+mu1*theta
data<-list(s=theta, o=x, p=p)
return(data)
}

	[[alternative HTML version deleted]]

