[R] OC curve in "Quality Control"

Philippe Glaziou glaziou at pasteur-kh.org
Fri Dec 26 10:22:38 CET 2003


WilDscOp <wildscop at yahoo.com> wrote:
> Can anyone please help me about any of the following questions:
> --------------------------------------------
> 1. How can i find "factorial" of any number in R? I tried
> 	> prod(170:1) # to find factorial of 170 or 170!
> Is it the only procedure - or R has any better process / operational 
> character to calculate factorial? Also, is it possible to calculate 
> factorial of 500? Or is there any statistical table available for this?


> gamma(x+1) # gives x! 

As for the factorial of 500, I would go for a log transformation:

> lgamma(501)
[1] 2611.330

But if you really need to see all the digits of 500!, PARI
<http://pari.math.u-bordeaux.fr/> --or rather its shell, may be
called from within R. It returns all digits of that large number
in a fraction of a second on my old laptop:

> system.time(system("echo '500!' | gp"))
[...]
%1 = 12201368259911100687012387854230469262535743428031928421
9241358838584537315388199760549644750220328186301361647714820
[about a thousand other digits follow]
Good bye!
[1] 0.00 0.00 0.05 0.03 0.02


For a more readable output:

> system("echo '500!*1.0' | gp")
[...]
%1 = 1.220136825991110068701238785 E1134



> --------------------------------------------
> 2. Is there any direct procedure / package in R to find "permutation / 
> combination"?


To permute the elements of a vector, you may use:

> perm <- function(v)sample(v,size=length(v),replace=FALSE)
> v <- 1:8
> v
[1] 1 2 3 4 5 6 7 8
> set.seed(101)
> perm(v)
[1] 3 1 5 4 7 6 2 8


Re combinations, does the function choose() do what you are
looking for?

> --------------------------------------------
> 3. Can i find Probability Density of "Hypergeometric Disribution" in R, 
> given all values of the parameter? I can not find any table of 
> Hypergeometric Disribution (if such tables are available on the internet, 
> please let me know).

Does dhyper() do what you are looking for? 

-- 
Philippe Glaziou
Epidemiologist




More information about the R-help mailing list