Learn R Programming

egcm (version 1.0.8)

rar1: Random AR(1) vector

Description

Generates a random realization of an AR(1) sequence

Usage

rar1(n, a0 = 0, a1 = 1, trend = 0, sd = 1, x0 = 0)

Arguments

n
Length of vector to produce
a0
Constant term in AR(1) sequence
a1
Coefficient of mean-reversion
trend
Linear trend
sd
Standard deviation of sequence of innovations
x0
Starting value of sequence

Value

  • If trend=0, returns a vector of length n representing a simulation of an AR(1) process $$X[k] = a_0 + a_1 * X[k-1] + \epsilon[t]$$ where $\epsilon[t]$ is a sequence of independent and identically distributed samples from a normal distribution with mean zero and standard deviation sd.

    If trend != 0, returns a vector of length n representing a simulation of a trend-stationary AR(1) process $$R[k] = a_0 + a_1 * R[k-1] + \epsilon[t]$$ $$X[k] = k * trend + R[k]$$

See Also

rcoint

Examples

Run this code
rar1(100, 0, 0)          # Equivalent to rnorm(100)
rar1(100, 0, 1)          # Equivalent to cumsum(rnorm(100))
acor(rar1(100, 1, .5))   # Should be about 0.5
tseries::adf.test(rar1(100, 0, .5))  # Should have a low p-value

Run the code above in your browser using DataLab