Bug 15792 - power.t.test fails when required N > 1e7
Summary: power.t.test fails when required N > 1e7
Alias: None
Product: R
Classification: Unclassified
Component: Analyses (show other bugs)
Version: R-devel (trunk)
Hardware: All All
: P5 normal
Assignee: R-core
Depends on:
Reported: 2014-05-05 23:43 UTC by Dean Eckles
Modified: 2014-12-23 16:00 UTC (History)
2 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Dean Eckles 2014-05-05 23:43:05 UTC
In its call to uniroot, power.t.test uses 1e7 as the upper bound for required N:
n <- uniroot(function(n) eval(p.body) - power, c(2, 1e+07))$root

So if the the required N > 1e7 then it fails with a uniroot error message:
> power.t.test(delta = 1e-4, sd = .35, power = .8)
Error in uniroot(function(n) eval(p.body) - power, c(2, 1e+07)) : 
  f() values at end points not of opposite sign

This can be fixed by increasing this limit, allowing a user-specified limit, or catching the uniroot error and increasing the limit only in the case.

Similar errors occur when solving for quantities other than N (such as very small values of delta). Experienced users/statisticians can route around this problem by doing some math.
Comment 1 Victor Wykoff 2014-12-19 21:17:06 UTC
We often run tests with sample sizes greater than 10 million. Updating the R function manually to increase the limit is straightforward, but I advocate for increasing the default limit in the call to the uniroot function from to 1e+07 to 1e+08 so others don't need to worry about this.

Thank you.
Comment 2 Martin Maechler 2014-12-23 08:42:56 UTC
This is a nice example - I think - where the new uniroot() features can be made use off, in a nice way:

No need to change the search interval (==> we keep 100% back compatibility for the cases it works), but allow uniroot() to search outside if necessary...

However, as there are so many use cases - it seems - for calling this,
I'm also adding a tolerance - so people can get nominally more precise results if desired.
Comment 3 Martin Maechler 2014-12-23 16:00:18 UTC
(In reply to Martin Maechler from comment #2)

Fixed in R-devel and R-patched  {svn rev 67205 etc}