Dear All, I need to write an R function which computes values of Probabilities for the (standard) normal distribution, ¦µ(z) for z > 0 by summing this power series. (We should accumulate terms until the sum doesn't change). I also need to make the function work for vector of values z.
The initial fomular is ¦µ(z) = ( 1/ sqrt(2¦Ð) )* ¡Ò e^(-t^2/2)dt (¡Ò is from -¡Þ, z) = 1/ 2 + ( 1/ sqrt(2¦Ð) )* ¡Ò e^(-t^2/2)dt (¡Ò is from 0 to z) I can substituting x = -t^2/2 into the series expansion for the exponential function e^x = ¡Æ x^n/n! (¡Æ is from n=0 to ¡Þ) I can obtain the series e^(-t^2/2) = ¡Æ (-1)^k*t^2k / 2^k*k! (¡Æ is from n=0 to ¡Þ) This series can be integrated term by term to obtain the formula ¦µ(z) = 1/ 2 + ( 1/ sqrt(2¦Ð) ) * ¡Æ (-1)^k*z^(2k+1) / (2^k*k! *(2k+1)) (¡Æ is from n=0 to ¡Þ) I know how to write the R function for exponential function e^x expf = function (x) { x=ifelse((neg=(x<0)),-x,x) n=0;term=1 oldsum=0; newsum=1 while(any(newsum != oldsum)) { oldsum=newsum n=n+1 term = term*x/n newsum = newsum+term} ifelse(neg, 1/newsum, newsum) } I know it will be similar to the above coding, but I don¡¯t know exactly how should we modify the above coding in order to get Probabilities for the (standard) normal distribution, ¦µ(z) for z > 0. Can anybody advise me on this?? Thanks a lot. Rene. [[alternative HTML version deleted]]
______________________________________________ R-help@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.