Raw File

\title{ Simulate General Linear Process }
Uses the Davies-Harte algorithm to simulate a Gaussian time
series with specified autocovariance function.
DHSimulate(n, r, ReportTestOnly = FALSE, rand.gen = rnorm, ...)
  \item{n}{ length of time series to be generated }
  \item{r}{ autocovariances at lags 0,1,...}
  \item{ReportTestOnly}{ FALSE -- Run normally so terminates with an error if Davies-Harte condition
  does not hold. Othewise if TRUE, then output is TRUE if the Davies-Harte condition holds
  and FALSE if it does not.}
  \item{rand.gen}{ random number generator to use. It is assumed to have mean zero and
  variance one.}
  \item{\dots}{optional arguments passed to \code{rand.gen} }
The method uses the FFT and so is most efficient if the series length, n,
is a power of 2.
The method requires that a complicated non-negativity condition be satisfed.
Craigmile (2003) discusses this condition in more detail and shows for 
anti-persistent time series this condition will always be satisfied.
Sometimes, as in the case of fractinally differenced white noise with
parameter d=0.45 and n=5000, this condition fails and the algorithm doesn't
In this case, an error message is generated and the function halts.
Either a vector of length containing the simulated time series if Davies-Harte condition
holds and ReportTestOnly = FALSE. 
If argument ReportTestOnly is set to TRUE, then output is logical variable indicating
if Davies-Harte condition holds, TRUE, or if it does not, FALSE.

\author{ A.I. McLeod}


Craigmile, P.F. (2003).
Simulating a class of stationary Gaussian processes using the Davies-Harte algorithm, 
with application to long memory processes.
Journal of Time Series Analysis, 24, 505-511.

Davies,  R. B. and Harte, D. S. (1987).
Tests for Hurst Effect. Biometrika 74,  95--101.

McLeod, A.I., Yu, Hao, Krougly, Zinovi L.  (2007).
Algorithms for Linear Time Series Analysis,
Journal of Statistical Software.

\seealso{ \
\code{\link{DLSimulate}} ,

#simulate a process with autocovariance function 1/(k+1), k=0,1,...
# and plot it
z<-DHSimulate(n, r)

#simulate AR(1) and produce a table comparing the theoretical and sample
# autocovariances and autocorrelations
phi<- -0.8
#theoretical autocovariances
z<-DHSimulate(n, tacvf)
sacf<-acf(z, plot=FALSE)$acf
sacvf<-acf(z, plot=FALSE,type="covariance")$acf
dimnames(tb)<-list(0:9, c("Tacvf","Sacvf","Tacf","Sacf"))

#Show the Davies-Harte condition sometimes hold and sometimes does not
#   in the case of fractionally differenced white noise
#Define autocovariance function for fractionally differenced white noise
`tacvfFdwn` <-
function(d, maxlag)
    x <- numeric(maxlag + 1)
    x[1] <- gamma(1 - 2 * d)/gamma(1 - d)^2
    for(i in 1:maxlag) 
        x[i + 1] <- ((i - 1 + d)/(i - d)) * x[i]
#Build table to show values of d for which condition is TRUE when n=5000
ds<-c(-0.45, -0.25, -0.05, 0.05, 0.25, 0.45)
for (kd in 1:length(ds)){
    r<-tacvfFdwn(d, n-1)
    tb[kd]<-DHSimulate(n, r, ReportTestOnly = TRUE)


\keyword{ ts }
\keyword{ datagen }
back to top