Is there a statistical difference between generating a series of paths for a montecarlo simulation using the following two methods (note that by path I mean a vector of 350 points, normally distributed):
A)
for path = 1:300000
Zn(path, :) = randn(1, 350);
end
or the far more efficient B)
Zn = randn(300000, 350);
I just want to be sure there is no funny added correlation or dependence between the rows in method B that isn’t present in method A. Like maybe method B distributes normally over 2 dimensions where A is over 1 dimension, so maybe that makes the two statistically different?
If there is a difference then I need to know the same for uniform distributions (i.e. rand instead of randn)
Just to add to the answer of @natan (+1), run the following code:
You’ll note that there is no difference between
XandY. That is, there is no difference between building a matrix in one step, and building a matrix from a sequence of vectors.However, there is a difference between my code and yours. Note I am populating the matrix by columns, not rows, since when
randis used to construct a matrix in one step, it populates by column. By the way, I’m not sure if you realize, but as a general rule you should always try and perform vector operations on the columns of matrices, not the rows. I explained why in a response to a question on SO the other day; see here for more…Regarding the question of independence/dependence, one needs to be careful with the language one uses. The sequence of numbers generated by
randare perfectly dependent. For the vast majority of statistical tests, they will appear to be independent – nonetheless, in theory, one could construct a statistical test that would demonstrate the dependency between a sequence of numbers generated byrand.Final thought, if you have a copy of Greene’s “Econometric Analysis”, he gives a neat discussion of random number generation in section 17.2.