Learn R Programming

RMC (version 0.2)

simRandWalk: Simulate a continuous auto-regressive process.

Description

Simulates an autoregressive process for a specified number of sets of observations. The first observation in each chain is drawn from an independent normal and subsequent observations are drawn from another normal with mean equal to the last observation.

Usage

simRandWalk( nc=5, ni=rep( 1000, nc), init.var=1, seq.var=0.1)

Arguments

nc
the number of chains to simulate
ni
the length of each chain (must be a vector of length nc)
init.var
the variance to use for the initial random number generation (distribution will have mean zero)
seq.var
the variance to use in the sequential simulation

Value

Details

The autoregressive process is simulated for each of nc chains. The first element of each chain is simulated from a normal with zero mean and variance init.var. The subsequent values are simulated from a random draw from a normal with mean equal to the previous observation and variance seq.var.

Examples

Run this code
ni <- c( 30, 300, 3000)
simDat <- simRandWalk( nc=3, ni=ni, init.var=1, seq.var=0.1)
par( mfrow=c( 1, 3))
plot( 1:ni[1], simDat[1:ni[1],2], type='b', pch=20, ylab="Random Variable", xlab="Index", main="Chain 1")
plot( 1:ni[2], simDat[ni[1]+1:ni[2],2], type='b', pch=20, ylab="Random Variable", xlab="Index", main="Chain 2")
plot( 1:ni[3], simDat[sum(ni[1:2])+1:ni[3],2], type='b', pch=20, ylab="Random Variable", xlab="Index", main="Chain 3")

Run the code above in your browser using DataLab