dimanche 20 novembre 2016

Problems with Monte Carlo simulation from memory-intensive simulation model in R

I have a complex microsimulation model (MSM) built in R and I am trying to learn about it through monte carlo simulation. I have avoided loops with respect to units (i.e., it is vectorized), but I use loops for discrete time intervals. Model individuals move through roughly 800 cycles (j = 1:800), and I have about 30,000 people. So the dataframe which keeps track of the progress of individuals is about 30,000 x 800. (Over that I ran into memory problems).

I have found that after opening R, I get different results for the first two runs of the model (as I should given the monte carlo error with a size of 30,000). However, if I run the model a third or fourth, etc, time I get the exact same answers. In parcicular, every individual in the model follows the exact same pathway. I tried reducing the monte carlo size to 100 and the problem remains. I also clear the workspace between runs. However, if I close R and reopen it, I then get a new answer for the first 2 runs.

This makes me think it could be a random number genoration problem. Is a random generating algorithm other than the defaul in R better for this? Or could memmory problems lead to a problem with random number generation? I did not post code from my model since it is extensive.




Aucun commentaire:

Enregistrer un commentaire