Skip to content

Change uniroot to uniroot.integer for target_param == "n"#1

Open
ddueber wants to merge 1 commit into
CenterForOpenScience:mainfrom
ddueber:patch-1
Open

Change uniroot to uniroot.integer for target_param == "n"#1
ddueber wants to merge 1 commit into
CenterForOpenScience:mainfrom
ddueber:patch-1

Conversation

@ddueber

@ddueber ddueber commented Nov 13, 2025

Copy link
Copy Markdown

When searching for a sample size, uniroot wastes HUGE amounts of time narrowing down the fractional part of the solution instead of just stopping when it finds the integer part of the solution. uniroot.integer from the ssanv package will only try integer values. In my tests, this leads to about a 10x speedup. If you don't want to rely on ssanv, all uniroot.integer does is a simple binary search, which is easy enough to code.

When searching for a sample size, uniroot wastes HUGE amounts of time narrowing down the fractional part of the solution instead of just stopping when it finds the integer part of the solution. uniroot.integer from the ssanv package will only try integer values. In my tests, this leads to about a 10x speedup. If you don't want to rely on ssanv, all uniroot.integer does is a simple binary search, which is easy enough to code.
@ddueber

ddueber commented Nov 14, 2025

Copy link
Copy Markdown
Author

ok, I did a larger scale test and the speedup was more like a factor of 2 with 500 simulations per replication. Still, it was substantial

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant