Quantcast

function for the average or expected range?; CORECTION

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

function for the average or expected range?; CORECTION

Spencer Graves
Hi, All:

** My previous email on this subject seemed to contain an error;  check
the correction:

      Is there a function in R to compute the expected range of a sample
of size n from some distribution?  I ask, because I was recently asked
about the control chart constant 'd2', which is the expected range for a
sample of size n from a standard normal.

      There is a fairly simple formula for the expected value of the
range, given, e.g., in Kendall and Stuart (1969) The Advanced Theory of
Statistics, vol. 1, Distribution Theory, 3rd ed. (Hafner, expression
(14.82), sec. 14.25:  The exact distribution of the range, p. 339).
Unfortunately, either I don't understand this formula, or it's wrong.
Using expression (14.1) in the same reference, I get the following:

     E(R) = n*integral{-Inf to Inf of [(F(x))**(n-1) -
(1-F(x))**(n-1)]dF(x).

      Thanks,
      Spencer Graves

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: function for the average or expected range?; CORECTION

Greg Snow-2
The "ptukey" and "qtukey" functions may be what you want (or at least in
the right direction).

You could also easily estimate this by simulation.

Hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[hidden email]
(801) 408-8111
 
 

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of Spencer Graves
> Sent: Friday, March 21, 2008 11:13 AM
> To: [hidden email]
> Subject: [R] function for the average or expected range?; CORECTION
>
> Hi, All:
>
> ** My previous email on this subject seemed to contain an
> error;  check the correction:
>
>       Is there a function in R to compute the expected range
> of a sample of size n from some distribution?  I ask, because
> I was recently asked about the control chart constant 'd2',
> which is the expected range for a sample of size n from a
> standard normal.
>
>       There is a fairly simple formula for the expected value
> of the range, given, e.g., in Kendall and Stuart (1969) The
> Advanced Theory of Statistics, vol. 1, Distribution Theory,
> 3rd ed. (Hafner, expression (14.82), sec. 14.25:  The exact
> distribution of the range, p. 339).
> Unfortunately, either I don't understand this formula, or it's wrong.
> Using expression (14.1) in the same reference, I get the following:
>
>      E(R) = n*integral{-Inf to Inf of [(F(x))**(n-1) -
> (1-F(x))**(n-1)]dF(x).
>
>       Thanks,
>       Spencer Graves
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: function for the average or expected range?; CORECTION

Spencer Graves
Hi, Greg:

      Thanks very much for the reply.

      1.  The 'ptukey' and 'qtukey' function are the distribution of the
studentized range, not the range.  I tried "sum(ptukey(x, 2, df=Inf,
lower=FALSE))*.1" and got 1.179 vs. 1.128 in the standard table of d2
for n = 2 observations per subgroup.

      2.  I tried simulation and found that I needed 1e7 or 1e8 random
normal deviates to get the accuracy of the published table.

      3.  Then I programmed in Excel the integral over seq(-5, 5, .1)
using a correction to the formula I got from Kendall and Stuart and got
the exact numbers in the published table except in one case where it was
off by 1 in the last significant digit.

      Thanks again,
      Spencer

Greg Snow wrote:
> The "ptukey" and "qtukey" functions may be what you want (or at least in
> the right direction).
>
> You could also easily estimate this by simulation.
>
> Hope this helps,
>
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: function for the average or expected range?; CORECTION

Greg Snow-2
Why do the integration in Excel instead of using the integrate function in R?  The R function will allow integration from -Inf to Inf.
 
What was the correction to the formula?  The last one you showed  looked like the difference between the average min and average max, but did not take into account the correlation between the max and min (going from memory, don't have my theory books handy). For large n the correlation is probably small enough that it makes a good approximation.

________________________________

From: Spencer Graves [mailto:[hidden email]]
Sent: Fri 3/21/2008 3:39 PM
To: Greg Snow
Cc: [hidden email]
Subject: Re: [R] function for the average or expected range?; CORECTION



Hi, Greg:

      Thanks very much for the reply.

      1.  The 'ptukey' and 'qtukey' function are the distribution of the
studentized range, not the range.  I tried "sum(ptukey(x, 2, df=Inf,
lower=FALSE))*.1" and got 1.179 vs. 1.128 in the standard table of d2
for n = 2 observations per subgroup.

      2.  I tried simulation and found that I needed 1e7 or 1e8 random
normal deviates to get the accuracy of the published table.

      3.  Then I programmed in Excel the integral over seq(-5, 5, .1)
using a correction to the formula I got from Kendall and Stuart and got
the exact numbers in the published table except in one case where it was
off by 1 in the last significant digit.

      Thanks again,
      Spencer

Greg Snow wrote:
> The "ptukey" and "qtukey" functions may be what you want (or at least in
> the right direction).
>
> You could also easily estimate this by simulation.
>
> Hope this helps,
>
>  



        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: function for the average or expected range?; CORECTION

Spencer Graves
Hi, Greg:

      1.  I did the integration in Excel for four reasons:  First, it's
easier (even for me) to see what's happening and debug for something
that simple.  Second, my audience were people who were probably not R
literate, and they could likely understand and use the Excel file easier
than than an R script.  Third, my experience with the R 'integrate' has
been less than satisfactory, especially when integrating from (-Inf) to
Inf.  Finally, to check my work, I often program things like that first
in Excel then in R.  If I get the same answer in both, I feel more
confident in my R results.  I haven't programmed this result in R yet,
but if I do, the fact that I already did it in Excel will make it easier
for me to be confident of the answers.  The function
"getParamerFun{qAnalyst}" gets the correct answer from n = 2:25 but
returns wrong answers outside that range.


      2.  I think the "CORRECTION TO CORRECTION" included a correct
formula:

           E(R) = n*integral{-Inf to Inf of x*[(F(x))**(n-1) -
(1-F(x))**(n-1)]*dF(x).

      The "CORRECTION" omitted the "x*".  The first version had many
more problems.

      Am I communicating?  
      Best Wishes,
      Spencer

Greg Snow wrote:

> Why do the integration in Excel instead of using the integrate
> function in R?  The R function will allow integration from -Inf to Inf.
>  
> What was the correction to the formula?  The last one you showed  
> looked like the difference between the average min and average max,
> but did not take into account the correlation between the max and min
> (going from memory, don't have my theory books handy). For large n the
> correlation is probably small enough that it makes a good approximation.
>
> ------------------------------------------------------------------------
> *From:* Spencer Graves [mailto:[hidden email]]
> *Sent:* Fri 3/21/2008 3:39 PM
> *To:* Greg Snow
> *Cc:* [hidden email]
> *Subject:* Re: [R] function for the average or expected range?; CORECTION
>
> Hi, Greg:
>
>       Thanks very much for the reply.
>
>       1.  The 'ptukey' and 'qtukey' function are the distribution of the
> studentized range, not the range.  I tried "sum(ptukey(x, 2, df=Inf,
> lower=FALSE))*.1" and got 1.179 vs. 1.128 in the standard table of d2
> for n = 2 observations per subgroup.
>
>       2.  I tried simulation and found that I needed 1e7 or 1e8 random
> normal deviates to get the accuracy of the published table.
>
>       3.  Then I programmed in Excel the integral over seq(-5, 5, .1)
> using a correction to the formula I got from Kendall and Stuart and got
> the exact numbers in the published table except in one case where it was
> off by 1 in the last significant digit.
>
>       Thanks again,
>       Spencer
>
> Greg Snow wrote:
> > The "ptukey" and "qtukey" functions may be what you want (or at least in
> > the right direction).
> >
> > You could also easily estimate this by simulation.
> >
> > Hope this helps,
> >
> >  
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: function for the average or expected range?; CORECTION

Greg Snow-2
Well it looks like you found your answer.  Further the fact that my
suggestions of possibilities did not help and the fact that noone else
has chimed in would suggest that there is not any easier way to get your
answer.

 I was thinking that taking into account the correlation between the min
and the max may give different answers than your formula, but so far my
tests have not shown enough of a difference to matter.  If you use this
with a distribution rather than the normal, you may want to do a couple
of simulations just to check, but otherwise your formula seems to be
working fine.

Hope this helped,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[hidden email]
(801) 408-8111
 
 

> -----Original Message-----
> From: Spencer Graves [mailto:[hidden email]]
> Sent: Saturday, March 22, 2008 9:40 AM
> To: Greg Snow
> Cc: [hidden email]
> Subject: Re: [R] function for the average or expected range?;
> CORECTION
>
> Hi, Greg:
>
>       1.  I did the integration in Excel for four reasons:  
> First, it's easier (even for me) to see what's happening and
> debug for something that simple.  Second, my audience were
> people who were probably not R literate, and they could
> likely understand and use the Excel file easier than than an
> R script.  Third, my experience with the R 'integrate' has
> been less than satisfactory, especially when integrating from
> (-Inf) to Inf.  Finally, to check my work, I often program
> things like that first in Excel then in R.  If I get the same
> answer in both, I feel more confident in my R results.  I
> haven't programmed this result in R yet, but if I do, the
> fact that I already did it in Excel will make it easier for
> me to be confident of the answers.  The function
> "getParamerFun{qAnalyst}" gets the correct answer from n =
> 2:25 but returns wrong answers outside that range.
>
>
>       2.  I think the "CORRECTION TO CORRECTION" included a correct
> formula:
>
>            E(R) = n*integral{-Inf to Inf of x*[(F(x))**(n-1)
> - (1-F(x))**(n-1)]*dF(x).
>
>       The "CORRECTION" omitted the "x*".  The first version
> had many more problems.
>
>       Am I communicating?  
>       Best Wishes,
>       Spencer
>
> Greg Snow wrote:
> > Why do the integration in Excel instead of using the integrate
> > function in R?  The R function will allow integration from
> -Inf to Inf.
> >  
> > What was the correction to the formula?  The last one you showed
> > looked like the difference between the average min and average max,
> > but did not take into account the correlation between the
> max and min
> > (going from memory, don't have my theory books handy). For
> large n the
> > correlation is probably small enough that it makes a good
> approximation.
> >
> >
> ----------------------------------------------------------------------
> > --
> > *From:* Spencer Graves [mailto:[hidden email]]
> > *Sent:* Fri 3/21/2008 3:39 PM
> > *To:* Greg Snow
> > *Cc:* [hidden email]
> > *Subject:* Re: [R] function for the average or expected range?;
> > CORECTION
> >
> > Hi, Greg:
> >
> >       Thanks very much for the reply.
> >
> >       1.  The 'ptukey' and 'qtukey' function are the
> distribution of
> > the studentized range, not the range.  I tried "sum(ptukey(x, 2,
> > df=Inf, lower=FALSE))*.1" and got 1.179 vs. 1.128 in the standard
> > table of d2 for n = 2 observations per subgroup.
> >
> >       2.  I tried simulation and found that I needed 1e7 or
> 1e8 random
> > normal deviates to get the accuracy of the published table.
> >
> >       3.  Then I programmed in Excel the integral over
> seq(-5, 5, .1)
> > using a correction to the formula I got from Kendall and Stuart and
> > got the exact numbers in the published table except in one
> case where
> > it was off by 1 in the last significant digit.
> >
> >       Thanks again,
> >       Spencer
> >
> > Greg Snow wrote:
> > > The "ptukey" and "qtukey" functions may be what you want (or at
> > > least in the right direction).
> > >
> > > You could also easily estimate this by simulation.
> > >
> > > Hope this helps,
> > >
> > >  
> >
>

______________________________________________
[hidden email] 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.
Loading...