Skip to content
Prev 61 / 2152 Next

Avoiding looping on vector with stochastic dependency

Hi Guillaume --
Guillaume Chapron wrote:
This question really belongs on the R-help list; this list is for 
questions related to cluster and other parallel computing solutions.

The sum of binomial or Poisson random variables are themselves binomial 
or Poisson distributed, so that sum(rpois(...)) can be replaced by 
rpois(sum(...), ...), etc. This replaces several 'expensive' calls 
(rbinom, rpois) with just one.

The transitions you describe are time-invariant (independent of i), so 
that you can pre-compute, probably analytically but certainly 
numerically, a matrix T[i,j] describing the probability of transition to 
state i, given current state j. The 'simulation' of a single transition 
is to sample from the distribution described by column j.

The simulation describes a first-order Markov process. For this there 
are explicit solutions, e.g., for the stationary distribution (wikipedia 
Markov Chain gives an introduction). So for the problem you outline what 
you likely want to do is to calculate T, and solve for the properties 
you're interested in. This will most easily involve a combination of 
analytic (formulating the solution in an abstract way) and numeric 
(finding the solution for your particular parameters) approaches.

This is not my area of expertise, so better advice might well be available.

Martin