Displaying 20 results from an estimated 30 matches for "lchoose".
Did you mean:
choose
2009 Dec 15
3
RFC: lchoose() vs lfactorial() etc
lgamma(x) and lfactorial(x) are defined to return
ln|Gamma(x)| {= log(abs(gamma(x)))} or ln|Gamma(x+1)| respectively.
Unfortunately, we haven't chosen the analogous definition for
lchoose().
So, currently
> lchoose(1/2, 1:10)
[1] -0.6931472 -2.0794415 NaN -3.2425924 NaN -3.8869494
[7] NaN -4.3357508 NaN -4.6805913
Warning message:
In lchoose(n, k) : NaNs produced
>
which (the NaN's) is not particularly useful.
(I have use case...
2011 Feb 11
3
How can we make a vector call a function element-wise efficiently?
Hello
I have a time-comsuming program which need to simplify, I have tested the annotated program as follow:
> #define function which will be call
> calsta <- function(c, n=100000)
+ {
+ i <- seq(from=0, length=c)
+ logx <- lchoose(NT-n, CT-i) + lchoose(n, i)
+ logmax <- max(logx)
+ logmax + log(sum(exp(logx - logmax)))
+ }
> CT=6000 #assignment to CT
> NT=29535210 #assignment to NT
>
> vec<-c(2331,524,918,218,1100,547,289,1167,450,1723)
> vec
[1] 2331 524 918 218 1100 547 289 1167 450 172...
2004 Sep 30
1
Vectorising and loop (was Re: optim "a log-likelihood function")
...9;t really have much to do with optim, so I changed
>the subject line.
>
>It's difficult to see what you're trying to accomplish without a complete
>example. Could you post one? Also, for loops are necessarily bad.
>
>One thing to note is that you're better off using lchoose in the above
>code. I.e.
>
>log.s <- lchoose(j, i) + lchoose(k - j, l - i) - lchoose(k, l)
>s[l] <- exp(log.s)
>
>--sundar
>
>
I have a matrix of 200 by 2, namely z, the columns are i and j. K is the
maximum of j.
x0 is a k dimension vector.
ss<-rep(0,200)
for (...
2008 Feb 27
1
dhyper, phyper (PR#10853)
...wrote a small function to sum its
probabilities, modeled after phyper() and taking the arguments in the
same order (the names have changed to suit the archaeological
situation):
> seber <- function(p,l,n,r)
> {
> y <- 0
> for (x in 0:p)
> y <- y + exp(lchoose(l,x) + lchoose(n-l,r-x) - lchoose(n,r))
> y
> }
When used in the larger routine, this yields results that very
closely approximate the results in Fieller and Turner's table 1.
I initially thought I could use the function phyper() for this
because, as I interpret the help files...
2011 Jan 07
4
how to calculate this natural logarithm
Hello
I want to calculate natural logarithm of sum of combinations as follow: (R code)
{
com_sum=choose(2000000,482)*choose(1000000,118)+choose(2000000,483)*choose(1000000,117)+...+choose(2000000,i)*choose(1000000,600-i)+...+choose(2000000,600)*choose(1000000,0) #calculate the sum
result=log(com_sum) #calculate the log of the sum
}
But
2004 Nov 24
1
(PR#7393) Re: dhyper() does not allow non-integer values for
...r(1,10.5,90,10)
>
> # OK
> qhyper(0.71,10,90,10)
> qhyper(0.71,10.5,90,10)
>
> # OK
> rhyper(1,10,90,10)
> rhyper(1,10.5,90,10)
>
>
>
> # this "naive" version of dhyper() works
>
> dhyperx<-function(x,m,n,k,log=3DFALSE){
> lp<-lchoose(m, x) + lchoose(n, k-x) - lchoose( m+n, k)
> if (log) {lp} else {exp(lp)}
> }
>
> # OK
> dhyperx(1,10,90,10)
> dhyperx(1,10.5,90,10)
>
>
>
> Erik J=F8rgensen
> Danish Institute of Agricultural Sciences
>
>
>
> --please do not edit the info...
2011 Feb 12
1
how to improve the precison of this calculation?
...#39;t implement due to the precision problem
i<-0:(c-1)
vec<-choose(n,i)*choose(NT-n,CT-i) #get the vector which need summation
result<-log(sum(vec)) #get the log of summation
# thanks to Petr, we have a solution
calsta <- function(c, n) {
i <- seq(from=0, length=c)
logx <- lchoose(NT-n, CT-i) + lchoose(n, i)
logmax <- max(logx)
logmax + log(sum(exp(logx - logmax)))
}
# now, new problem arise, in theory, the "result" of different (c,n) pair should most probably differ, so I can order them, but
> calsta(918,100000)-calsta(718,100000)
[1] 0
> calsta(718,...
2008 Feb 18
2
Huge number
Hi,
I'm trying to calculate p-value to findout definitely expressed genes
compare A to B situation.
I got this data(this is a part of data) from whole organism , and each
number means each expression values (that means, we could think 'a' gene
is 13 in A situation, and it turns 30 in B situation)
To findout probability, I'm going to use Audic - Claverie Method. ( The
significance
2020 Jan 14
4
[R] choose(n, k) as n approaches k
...lose to integers (within 1e-7). In those cases, k is silently rounded to integer. As I read your suggestion, n would only be rounded to integer if k > n-k. I think both n and k should be rounded to integer in this near-integer situation, regardless of the value of k.
>
> I believe that lchoose(n, k) already does this.
>
> Duncan Murdoch
>
>> double r, k0 = k;
>> k = R_forceint(k);
>> ...
>> if (fabs(k - k0) > 1e-7)
>> MATHLIB_WARNING2(_("'k' (%.2f) must be integer, rounded to %.0f"), k0, k);
>>
>...
2020 Jan 14
2
[R] choose(n, k) as n approaches k
> On 14 Jan 2020, at 16:21 , Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
>
> On 14/01/2020 10:07 a.m., peter dalgaard wrote:
>> Yep, that looks wrong (probably want to continue discussion over on R-devel)
>> I think the culprit is here (in src/nmath/choose.c)
>> if (k < k_small_max) {
>> int j;
>> if(n-k < k
2000 Jul 06
1
factorial(), modulus()
Dear R friends,
I was wondering if there were factorial and modulus functions out there
that I've somehow overlooked?
-P.
--
Peter L. Hurd, Ph.D.
phurd at uts.cc.utexas.edu
http://www.zo.utexas.edu/research/phurd fax 512.471-3878
Section of Integrative Biology, University of Texas, Austin TX 78712 USA
2011 May 09
1
Stirlings Approximation
I have some big combinations like:
4444444444444444444444444444 choose 784645433
Can R compute these?
Is there any package that does stirlings approximation in R?
--
Thanks,
Jim.
[[alternative HTML version deleted]]
2020 Jan 14
0
[R] choose(n, k) as n approaches k
...are close to integers (within 1e-7). In those
cases, k is silently rounded to integer. As I read your suggestion, n
would only be rounded to integer if k > n-k. I think both n and k
should be rounded to integer in this near-integer situation, regardless
of the value of k.
I believe that lchoose(n, k) already does this.
Duncan Murdoch
>
> double r, k0 = k;
> k = R_forceint(k);
> ...
> if (fabs(k - k0) > 1e-7)
> MATHLIB_WARNING2(_("'k' (%.2f) must be integer, rounded to %.0f"), k0, k);
>
>
>> Duncan Murdoch
&...
2020 Jan 15
1
[R] choose(n, k) as n approaches k
...(within 1e-7). In those cases, k is silently rounded to integer. As I read your suggestion, n would only be rounded to integer if k > n-k. I think both n and k should be rounded to integer in this near-integer situation, regardless of the value of k.
>>>
>>> I believe that lchoose(n, k) already does this.
>>>
>>> Duncan Murdoch
>>>
>>>> double r, k0 = k;
>>>> k = R_forceint(k);
>>>> ...
>>>> if (fabs(k - k0) > 1e-7)
>>>> MATHLIB_WARNING2(_("'k' (%.2f) must...
2012 Jul 11
0
declaring negative log likelihood of a distribution
...9 samples
*
Now to estimate the parameters, I first declared the negative log
likelihood function of this new distribution as below(I used two methods,
one with a loop and one without the loop)
#without any loops
*> Loglik.newdis1<- function(x,a,b,fre,n){
KBLL1<-sum(fre*(log(a*b)+lchoose(n,x)+log(sum((-1)**(0:1000) *
choose(b-1, 0:1000) * beta(x+a+a*0:1000, n-x+1)))))
return(-KBLL1)
}*
#here a and b are the parameters to be estimated and x=binomial
values, fre=frequencies and n=binomial trials
#and since the inner series is a convergent infinite series, a lar...
2011 Oct 27
3
2 x 3 Probability under the null
I have a 2 x 3 matrix called snp and I want to compute the following
probability:
choose(sum(snp[,1]), snp[1,1]) * choose(sum(snp[,2]), snp[1,2]) *
choose(sum(snp[,3]), snp[1,3])/choose(sum(snp), sum(snp[1,]))
but I keep getting Infs and NaNs. Is there a function that can do this in R?
--
Thanks,
Jim.
[[alternative HTML version deleted]]
2020 Jan 14
0
[R] choose(n, k) as n approaches k
...integers (within 1e-7). In those cases, k is silently rounded to integer. As I read your suggestion, n would only be rounded to integer if k > n-k. I think both n and k should be rounded to integer in this near-integer situation, regardless of the value of k.
>>
>> I believe that lchoose(n, k) already does this.
>>
>> Duncan Murdoch
>>
>>> double r, k0 = k;
>>> k = R_forceint(k);
>>> ...
>>> if (fabs(k - k0) > 1e-7)
>>> MATHLIB_WARNING2(_("'k' (%.2f) must be integer, rounded to %.0f&quo...
1997 Jun 25
3
R-alpha: lbeta, ctrl-C and crashes
1. lbeta and beta do not work properly: lbeta returns its first
argument and beta gives the lbeta result.
In names.c lines 245-6, the codes for these should be 2 and 3 instead
of 1 and 2
2. crtl-C does not work (except the first time) on Red Hat elf Linux
(which has many many other problems as well) nor on the previous
version of Linux for Amiga. It worked on Slackware aout Linux and now
works
1997 Jun 25
3
R-alpha: lbeta, ctrl-C and crashes
1. lbeta and beta do not work properly: lbeta returns its first
argument and beta gives the lbeta result.
In names.c lines 245-6, the codes for these should be 2 and 3 instead
of 1 and 2
2. crtl-C does not work (except the first time) on Red Hat elf Linux
(which has many many other problems as well) nor on the previous
version of Linux for Amiga. It worked on Slackware aout Linux and now
works
2020 Jan 13
3
choose(n, k) as n approaches k
This struck me as incorrect:
> choose(3.999999, 4)
[1] 0.9999979
> choose(3.9999999, 4)
[1] 0
> choose(4, 4)
[1] 1
> choose(4.0000001, 4)
[1] 4
> choose(4.000001, 4)
[1] 1.000002
Should base::choose(n, k) check whether n is within machine precision of k and return 1?
Thanks,
Erik
***
sessionInfo()
R version 3.6.0 beta (2019-04-15 r76395)
Platform: x86_64-apple-darwin15.6.0