I am trying to simulate a (very) simple model of snow fall/accumulation using random walks in the following way:

sf = 
  Accumulate[RandomVariate[BernoulliDistribution[0.2], 100] *
    RandomVariate[GammaDistribution[1, 2], 100] /. {0. -> -0.4}]


I generate Bernoulli trials with a success of probability of 0.2 to simulate days that it snows. On a day that it doesn't snow instead of a simple 0 entry I am introducing a negative drift term of -0.4 to emulate the melting of the snow.

Where I am having trouble is that you can't ever have negative snowfall. I want the walker to always remain bigger than or equal to 0. However, I can't just send all negative entries to 0 as that would eliminate the data of days where it snows but the drift term is larger than the snowfall.



1 Answer 1


I don't think Accumulate is powerful enough. Rather, you should use FoldList.

sf =
  FoldList[If[#2 == 0, Max[#1 - .4, 0], #1 + #2] &, 
    RandomVariate[BernoulliDistribution[0.2], 100] *
      RandomVariate[GammaDistribution[1, 2], 100]];



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.