From: li li <hannah.hlx_at_gmail.com>

Date: Wed, 09 Jun 2010 12:17:21 -0400

R-help_at_r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 09 Jun 2010 - 16:19:27 GMT

Date: Wed, 09 Jun 2010 12:17:21 -0400

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]]

R-help_at_r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 09 Jun 2010 - 16:19:27 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Wed 09 Jun 2010 - 16:20:28 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*