Skip to content
Prev 246824 / 398506 Next

Normal Distribution Quantiles

On Jan 8, 2011, at 6:56 AM, Rainer Schuermann wrote:

            
Sounds like homework, which is not an encouraged use of the Rhelp  
list. You can either do it in theory or you can simulate it. Here's a  
small step toward a simulation approach.

 > cumsum(rnorm(100, mean=40, sd=10))
   [1]   41.90617   71.09148  120.55569  159.56063  229.73167   
255.35290  300.74655
snipped
  [92] 3627.25753 3683.24696 3714.11421 3729.41203 3764.54192  
3809.15159 3881.71016
  [99] 3917.16512 3932.00861
 > cumsum(rnorm(100, mean=40, sd=10))
   [1]   38.59288   53.82815  111.30052  156.58190  188.15454   
207.90584  240.64078
snipped
  [92] 3776.25476 3821.90626 3876.64512 3921.16797 3958.83472  
3992.33155 4045.96649
  [99] 4091.66277 4134.45867

The first realization did not make it in the expected 100 days so  
further efforts should extend the simulation runs to maybe 120 days.  
The second realization had him making it on the 98th day. There is an  
R replicate() function available once you get a function running that  
will return a specific value for an instance. This one might work:
 > min(which(cumsum(rnorm(120, mean=40, sd=10)) >= 4000) )
[1] 97

If you wanted a forum that does not explicitly discourage homework and  
would be a better place to ask theory and probability questions, there  
is CrossValidated:
http://stats.stackexchange.com/faq