[R] Normal Distribution Quantiles

Charles C. Berry cberry at tajo.ucsd.edu
Sat Jan 8 19:32:00 CET 2011


On Sat, 8 Jan 2011, Rainer Schuermann wrote:

>> Sounds like homework, which is not an encouraged use of the Rhelp
>> list. You can either do it in theory...
>

> It is _from_ a homework but I have the solution already (explicitly got 
> that done first!) - this was the pasted Latex code (apologies for that, 
> but in plain text it looks unreadable[1], and I thought everybody here 
> has his / her favorite Latrex editor open all the time anyway...). I'm 
> just looking, for my own advancement and programming training, for a way 
> of doing that in R - which, from your and Dennis' reply, doesn't seem to 
> exist.

Your question was 'how do I find the smallest integer $n$ such that...', 
right?

Using uniroot and pnorm, you could solve for real $n$ and then round up.

Doing this, I find that in greater than 95% of trials, your bushwalker 
would be done in 105 days or less.

Or you could use findInterval, sapply, and pnorm to get all of the $n$s in 
one expression.

HTH,

Chuck



>
> I would _not_ misuse the list for getting homework done easily, I will not ask "learning statistics" questions here, and I will always try to find the solution myself before posting something here, I promise!
>
> Thanks anyway for the simulation advice,
> Rainer
>
>
>    (4000 - (40*n))   -329
> [1] --------------- = ----
>              1        200
>       (10*(n^-))
>              2
>
>
>
>
> On Saturday 08 January 2011 14:56:20 you wrote:
>>
>> On Jan 8, 2011, at 6:56 AM, Rainer Schuermann wrote:
>>
>>> This is probably embarrassingly basic, but I have spent quite a few
>>> hours in Google and RSeek without getting a clue - probably I'm
>>> asking the wrong questions...
>>>
>>> There is this guy who has decided to walk through Australia, a total
>>> distance of 4000 km. His daily portion (mean) is 40km with an sd of
>>> 10 km. I want to calculate the number of days it takes to arrive
>>> with 80, 90, 95, 99% probability.
>>> I know how to do this manually, eg. for 95%
>>> $\Phi \left( \frac{4000-40n}{10 \sqrt{n}}  \right) \leq 0.05$
>>> find the z score...
>>>
>>> but how would I do this in R? Not qnorm(), but what is it?
>>
>> 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
>>
>>>
>>> Thanks in advance,
>>> and apologies for the level of question...
>>> Rainer
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>> David Winsemius, MD
>> West Hartford, CT
>>
>>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

Charles C. Berry                            Dept of Family/Preventive Medicine
cberry at tajo.ucsd.edu			    UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901



More information about the R-help mailing list