Dear all, 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? -------------------------------------------- 2. Is there any direct procedure / package in R to find "permutation / combination"? -------------------------------------------- 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). -------------------------------------------- 4. Is there any way i can perform "Quality control" calculations (like p-chart / np-chart / c-chart / u-chart / OC curves / AOQ / AOQL / ATI / ASN / plan design) in R? I guess such procedures are available in SAS / Statistica or other statistical softwares. If there are such operations in R, please refer me to the appropriate documentations. -------------------------------------------- 5. Particularly, if we have lots of size N = 50000 and the receiving inspection procedure used in single-sampling plan with n = 50 and c = 1; then i need to draw the type-A and type-B operating characteristic curve for the plan. Can i do it on R? ----------------- --------------------------- Any comment / suggestion / idea / web-link / replies will be gladly accepted. Thanks for your time. _______________________ Mohammad Ehsanul Karim <wildscop at yahoo.com> Institute of Statistical Research and Training University of Dhaka, Dhaka- 1000, Bangladesh
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
Dear All, First of all, thanks to "Philippe Glaziou" and "Andrew C. Ward" for their nice and very helpful e-mail. Well.. ----------------- --------------------------- For Number 1 problem: about <http://pari.math.u-bordeaux.fr/>, sorry i didnot understand what to download or what to call! From <http://pari.math.u-bordeaux.fr/download.html> can you please tell me what should i download and how to use(i could not find any doc)? An exact link for download may be helpful:) ----------------- --------------------------- For Number 2 problem: perm function is a very nice one. And yes "choose()" works fine for me. Also gregmisc package <http://cran.r-project.org/bin/windows/contrib/1.9/gregmisc_0.8.7.zip> is good. ----------------- --------------------------- For Number 3 problem: i had some problem using dhyper() because i cannot match the parameters there. I used > N<-5000; n<-50; D<-seq(0,500,1); d<-0 # (For d = 1 i just recalculated it with d<-1) > hypg <- (choose(D, d)* choose((N-D), (n-d)) / choose(N,n)) instead and it surves my purpose. Anyway, is there any better procedure? I could not find Hypergeometric() in the base. ----------------- --------------------------- For Number 5 problem: I did as follows: # For type A OC curve > N<-5000; n<-50; D<-seq(1,500,1); d1<-0; d2<-1; p<-(seq(1,500,1)/5000); Pa<-((choose(D, d1)* choose((N-D), (n-d1)) / choose(N,n)) + (choose(D, d2)* choose((N-D), (n-d2)) / choose(N,n))); plot(p,Pa,pch="o", main="Type A \nOperating Characteristic Curve", sub="Using Hypergeometric Distribution", xlab="Proportion defective", ylab="Probability of Acceptance", xlim=c(0.00,0.10), ylim=c(0.00,1.00), type="p", axes =T, col=1) # here, p = D/N # For type B OC curve > N<-5000; n<-50; D<-seq(0,500,1); d1<-0; d2<-1; p<-(seq(0,500,1)/5000); Pa1<- dpois(0, (n*p), log = FALSE); Pa2<- dpois(1, (n*p), log = FALSE); Pa<-Pa1+Pa2; plot(p,Pa,pch="o", main="Type B \nOperating Characteristic Curve", sub="Using Poisson as an approximation of Binomial Distribution", xlab="Proportion defective", ylab="Probability of Acceptance", xlim=c(0.00,0.10), ylim=c(0.00,1.00), type="p", axes =T, col=1) And these works fine. Thank you for your time. _______________________ Mohammad Ehsanul Karim <wildscop at yahoo.com> Institute of Statistical Research and Training University of Dhaka, Dhaka- 1000, Bangladesh