I am trying to run a function that outputs a very large number. The problem is that the return says inf.
The function is as follows:
comb.prob <- function(n){
choose(2000,n)*choose(28000,(300-n))/choose(30000,300)
}
However If I reduce my input numbers by 1/10, R returns a value to me.
Eg.
comb.prob <- function(n){
choose(200,n)*choose(2800,(30-n))/choose(3000,30)
}
I was wondering if there was a way to boost R’s computing power or another method so I could get R to run the first equation?
You might want to try using the log version of choose (lchoose). I show an example with smaller numbers that these are equivalent.
Using some log identities, namely that log(a*b/c)=log(a)+log(b)-log(c)
comb.prob.log <- function(n){
exp(lchoose(2000,n)+lchoose(28000,(300-n))-lchoose(30000,300))
}
n <- 2
exp(lchoose(20,n)+lchoose(280,(3-n))-lchoose(300,3))
#> [1] 0.01194137
choose(20,n)*choose(280,(3-n))/choose(300,3)
#> [1] 0.01194137
Created on 2022-07-20 by the reprex package (v2.0.1)
Thank you for your reply! It seemed to do the trick.
Josh
system
Closed
4
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.