Learn R Programming

codadiags (version 1.0)

AR1: Generate auto-regressive order 1 sequence

Description

Generate auto-regressive order 1 sequence

Usage

AR1(length = 1000, mean = 0, sd = 1, rho = 0.1,
    rand = function() {     rnorm(1) })

Arguments

length
size of the sequence
mean
mean value of the sequence $$\mu$$
sd
standard deviation of the sequence $$\sigma$$
rho
auto-correlation factor
rand
function to generate one random step

Value

  • Auto Regressive ("AR") sequence $$X=\mu * \left{ x_n \right}_{1 \leq n \leq N}, x_1 = \sigma * u_1 / \sqrt{1-\rho^2}, x_n=\rho * x_{n-1} + \sigma * u_n$$

Examples

Run this code
x = AR1()
plot(x,type='l',col=rgb(.5,0,0,.5))

Run the code above in your browser using DataLab