# DHSimulate: Simulate General Linear Process In ltsa: Linear Time Series Analysis

## Description

Uses the Davies-Harte algorithm to simulate a Gaussian time series with specified autocovariance function.

## Usage

 `1` ```DHSimulate(n, r, ReportTestOnly = FALSE, rand.gen = rnorm, ...) ```

## Arguments

 `n` length of time series to be generated `r` autocovariances at lags 0,1,... `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. `rand.gen` random number generator to use. It is assumed to have mean zero and variance one. `...` optional arguments passed to `rand.gen`

## Details

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 work. In this case, an error message is generated and the function halts.

## Value

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.

A.I. McLeod

## References

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.

\ `DLSimulate` , `SimGLP`, `arima.sim`
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48``` ```#simulate a process with autocovariance function 1/(k+1), k=0,1,... # and plot it n<-2000 r<-1/sqrt(1:n) z<-DHSimulate(n, r) plot.ts(z) #simulate AR(1) and produce a table comparing the theoretical and sample # autocovariances and autocorrelations phi<- -0.8 n<-4096 g0<-1/(1-phi^2) #theoretical autocovariances tacvf<-g0*(phi^(0:(n-1))) z<-DHSimulate(n, tacvf) #autocorrelations sacf<-acf(z, plot=FALSE)\$acf #autocovariances sacvf<-acf(z, plot=FALSE,type="covariance")\$acf tacf<-tacvf/tacvf tb<-matrix(c(tacvf[1:10],sacvf[1:10],tacf[1:10],sacf[1:10]),ncol=4) dimnames(tb)<-list(0:9, c("Tacvf","Sacvf","Tacf","Sacf")) tb #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 <- gamma(1 - 2 * d)/gamma(1 - d)^2 for(i in 1:maxlag) x[i + 1] <- ((i - 1 + d)/(i - d)) * x[i] x } #Build table to show values of d for which condition is TRUE when n=5000 n<-5000 ds<-c(-0.45, -0.25, -0.05, 0.05, 0.25, 0.45) tb<-logical(length(ds)) names(tb)<-ds for (kd in 1:length(ds)){ d<-ds[kd] r<-tacvfFdwn(d, n-1) tb[kd]<-DHSimulate(n, r, ReportTestOnly = TRUE) } tb ```