[R] help

Eik Vettorazzi E.Vettorazzi at uke.uni-hamburg.de
Wed Feb 2 17:08:35 CET 2011


Hi,
maybe you rethink your calculations. Just for curiosity, what's the purpose?

First of all, using
prod(1:j-1-.25)  #and
prod(1:j)

instead of a loop is much more efficent.
If you need all values for a[1] up to a[j] you can use cumprod

But this doesn't get you rid of numeric overflow

but 1/(1*2*3*4*..*j) * (-d)(1-d)(2-d)...(j-1-d)
is the same as
(-d)/1 * (1-d)/2 * (2-d)/3 ... * (j-1-d)/j

(multiplication is commutative)

j<-1:500
a<-cumprod((j-1-.25)/j)

or am I missing something?



Am 01.02.2011 21:51, schrieb Kiogou Lydie:
> 
> 
> PLEASE HELP
> 
> I actually want to do the following:
> 
> a[j] = (1/(j!))*Π (i-1-d), j = 500, Π means product i = 1 to
> j
> 
>  
> 
> Yet, j! will stop at 170 and Π (i-1-d) at 172; so, a[j] will
> not exceed 170.
> 
> I would like to have at least 200 a[j]. 
> 
>  
> 
> WHAT SHOULD I DO?
> 
>  
> 
> PLEASE SEE MY CODE FOR DETAIL!!
> 
> 
> ####################################################
> R CODE:
> ###################################################
> 
> 
> 
> d = .25
> 
> # generate j!
> v=j=1
> for (i in 1:200){
> v[i] = i
>     for (i in 2:200){
> j[1]=1
> j[i] = j[i-1]*v[i]
>     }
> }
> j
> 
> # generate aj
> l=A=a=0
> for (k in 1:200){
> l[k] = (k-1-d)
>   for (i in 2:200){
>     A[1] = l[1]
>     A[i] = A[i-1]*l[i]
>      for ( i in 1:200){
>   a[i]= (1/j[i])*A[i]
>     }
>       
>     }
> }
> a
> 
> ######################################## END CODE ##################
> #####################################################################
> 
> 
> With GOD, everything is POSSIBLE.
> 
> Avec DIEU, tout est POSSIBLE.
> 
> 
>       
> 	[[alternative HTML version deleted]]
> 
> 
> 
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790



More information about the R-help mailing list