AR1: Autoregressive model of first order

Description Usage Arguments Examples

View source: R/AR1.R

Description

Generates time series from an AR1 model.

Usage

1
AR1(n, alpha, mean = 0, sd = 1)

Arguments

n

number of values

alpha

lag-1 autocorrelation

mean

mean

sd

standard deviation

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
library(CoSMoS)

## generate 500 values from an AR1 having lag-1 autocorrelation 0.8,
## mean value equal to 0, and standard deviation equal to 1.
n <- 500

## generate white noise for comparsion
x <- rnorm(n)
ggplot() +
 geom_line(aes(x = 1:n,
               y = x)) +
   labs(x = '',
        y = 'value') +
   theme_classic()

## generete values using AR1
y <- AR1(n, .8)
ggplot() +
  geom_line(aes(x = 1:n,
                y = y)) +
  labs(x = '',
       y = 'value') +
  theme_classic()

CoSMoS documentation built on May 30, 2021, 1:06 a.m.