# Generating strongly correlated data for numerical experiments

**URL:** <https://discourse.julialang.org/t/generating-strongly-correlated-data-for-numerical-experiments/3842>\
**Category:** Statistics\
**Tags:** question\
**Created:** [May 22, 2017, 8:21am UTC](https://discourse.julialang.org/t/generating-strongly-correlated-data-for-numerical-experiments/3842 "2017-05-22T08:21:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![varun7rs](https://avatars.discourse-cdn.com/v4/letter/v/c2a13f/32.png) [@varun7rs](https://discourse.julialang.org/u/varun7rs)\
**Post date:** [May 22, 2017, 8:21am UTC](https://discourse.julialang.org/t/generating-strongly-correlated-data-for-numerical-experiments/3842/1 "2017-05-22T08:21:35Z")

</div>

Since real-life traffic traces are not readily available, for my simulations, I generate traffic traces as follows:

```julia
trace = []
nom = sample(collect(0.5:0.2,0.9), WeightVec([0.3,0.4,0.3]))
for i=1:100
  push!(trace, nom + rand(Normal(0,nom)))
end

```

I repeat this process for all commodities (c\in C) in the network thereby obtaining unique traces for every commodity. However, I would now like to generate strongly correlated traces. Is there a package in Julia that could help me generate such strongly correlated traces?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 22, 2017, 10:00am UTC](https://discourse.julialang.org/t/generating-strongly-correlated-data-for-numerical-experiments/3842/2 "2017-05-22T10:00:26Z")

</div>

It is not clear what you are trying to do — is `dnom` a typo, or a variable that you did not initialize?

In any case, if you want series with correlated noise, you should just draw correlated variables (eg using a multivariate normal with non-diagonal variance matrix, or some more sophisticated hierarchical arrangement) and use them.

---

<div class="post-metadata">

**Author:** ![varun7rs](https://avatars.discourse-cdn.com/v4/letter/v/c2a13f/32.png) [@varun7rs](https://discourse.julialang.org/u/varun7rs)\
**Post date:** [May 22, 2017, 10:22am UTC](https://discourse.julialang.org/t/generating-strongly-correlated-data-for-numerical-experiments/3842/3 "2017-05-22T10:22:00Z")

</div>

Sorry about the typo. I donot want a temporally correlated trace but spatially correlated traces. Assuming we have two commodities c1 and c2, I want their respective traces to be strongly correlated with each other.

---

<div class="post-metadata">

**Author:** ![mcreel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcreel/32/30088_2.png) [@mcreel](https://discourse.julialang.org/u/mcreel)\
**Post date:** [May 22, 2017, 11:03am UTC](https://discourse.julialang.org/t/generating-strongly-correlated-data-for-numerical-experiments/3842/4 "2017-05-22T11:03:57Z")

</div>

The following code generates two series that are strongly correlated with one another, but serially uncorrelated. Is that what you have in mind?

```julia
using Plots
T = 100
Sig = [1 0.9; 0.9 1]
P = chol(Sig)
x = randn(T,2)*P
x = x .+ [-2.0 2.0]
show(cov(x))
plot(x)

```

---

<div class="post-metadata">

**Author:** ![varun7rs](https://avatars.discourse-cdn.com/v4/letter/v/c2a13f/32.png) [@varun7rs](https://discourse.julialang.org/u/varun7rs)\
**Post date:** [May 22, 2017, 11:10am UTC](https://discourse.julialang.org/t/generating-strongly-correlated-data-for-numerical-experiments/3842/5 "2017-05-22T11:10:38Z")

</div>

Thanks a lot. This is exactly what I wanted for my simulations.
