colored_multi_rnorm: Generate Multiple Cross-Correlated & Autocorrelated Variables

View source: R/RcppExports.R

colored_multi_rnormR Documentation

Generate Multiple Cross-Correlated & Autocorrelated Variables

Description

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

Usage

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)
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))]

colorednoise documentation built on Sept. 22, 2023, 5:12 p.m.