adkane
adkane

Reputation: 1441

Is there a way to code a multivariate normal distribution in NetLogo

I want to sample from a multivariate normal distribution for a model in netlogo. I know there's a random-normal function but I'd like to extend this to two dimensions.

Or am I better off coding it up in R and feeding it to the netlogo model that way?

Upvotes: 1

Views: 209

Answers (1)

JenB
JenB

Reputation: 17678

Okay, it's been a long time since I had to do something like this. But you want something like (with rho as your correlation that you control):

set dim1 random-normal 1 0.2
set dim2 rho * dim1 + sqrt(1 - rho ^ 2) * random-normal 5 1

You might want to check on crossvalidated (the statistics equivalent to stackoverflow) to get the correct formula. But it's definitely straightforward to do in NetLogo once you know how to adjust a normal random number to introduce the dependency. Using the R extension is always fiddly and it's not worth the effort if this is all you are doing with it.

Upvotes: 1

Related Questions