Generates random variables that are correlated to each other and temporally autocorrelated.

colored_multi_rnorm(timesteps, mean, sd, phi, covMatrix)

Arguments

timesteps

The number of temporally autocorrelated random numbers (one per timestep) you want.

mean

A vector giving the mean of each variable.

sd

A vector giving the standard deviation of each variable.

phi

A vector giving the temporal autocorrelation of each variable.

covMatrix

A valid covariance matrix. The number of rows/columns must match the length of the mu, sigma, and phi vectors.

Value

A matrix with as many rows as timesteps and as many columns as mu/sigma/phi values.

Examples

cov <- matrix(c(1, 0.53, 0.73, 0.53, 1, 0.44, 0.73, 0.44, 1), nrow = 3) test <- colored_multi_rnorm(100, c(0, 3, 5), c(1, 0.5, 1), c(0.5, -0.3, 0), cov) var(test)
#> [,1] [,2] [,3] #> [1,] 1.0736919 0.3894535 0.4757221 #> [2,] 0.3894535 1.0863237 0.3456151 #> [3,] 0.4757221 0.3456151 0.7113503
library(data.table) as.data.table(test)[, .(V1_mean = mean(V1), V2_mean = mean(V2), V3_mean = mean(V3), V1_sd = sd(V1), V2_sd = sd(V2), V3_sd = sd(V3), V1_autocorrelation = autocorrelation(V1), V2_autocorrelation = autocorrelation(V2), V3_autocorrelation = autocorrelation(V3))]
#> V1_mean V2_mean V3_mean V1_sd V2_sd V3_sd V1_autocorrelation #> 1: 0.2716204 3.0046 5.141593 1.036191 1.042269 0.8434158 0.5984353 #> V2_autocorrelation V3_autocorrelation #> 1: -0.4387449 -0.2354361