search for: newsum

Displaying 4 results from an estimated 4 matches for "newsum".

2005 Apr 07
2
vectorized approach to cumulative sampling
Hi All, I need to sample a vector ("old"), with replacement, up to the point where my vector of samples ("new") sums to a predefined value ("target"), shortening the last sample if necessary so that the total sum ("newsum") of the samples matches the predefined value. While I can easily do this with a "while" loop (see below for example code), because the length of both "old" and "new" may be > 20,000, a vectorized approach will save me lots of CPU time. Any suggestions woul...
2009 Aug 19
3
R function for Probabilities for the (standard) normal distribution
...( 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...
2002 Nov 16
0
Wishlist: allow NA values in medpolish (package 'eda') (PR#2298)
...apply(z, 2, median) + cdelta <- apply(z, 2, median, na.rm = na.rm) z <- z - matrix(cdelta, nr=nr, nc=nc, byrow=TRUE) c <- c + cdelta - delta <- median(r) + delta <- median(r, na.rm = na.rm) r <- r - delta t <- t + delta - newsum <- sum(abs(z)) + newsum <- sum(abs(z), na.rm = na.rm) converged <- newsum==0 || abs(1-oldsum/newsum) < eps if(converged) break oldsum <- newsum diff -ur R-1.6.1.old/src/library/eda/man/medpolish.Rd R-1.6.1/src/library/eda/man/medpolish.Rd --- R-1.6.1.ol...
2018 Jan 19
1
bug fix integer overflow in medpolish function
...; the matrix in the attached .rda file, I get this rather cryptic error: "Error in if (converged) break : missing value where TRUE/FALSE needed In addition: Warning message: In sum(abs(z), na.rm = na.rm) : integer overflow - use sum(as.numeric(.))" I traced this down to the line: newsum <- sum(abs(z), na.rm = na.rm) I think this "overflow" could be easily fixed by changing this line to: newsum <- sum(as.numeric(abs(z)), na.rm = na.rm) With kind regards Ludger Goeminne ? Ludger Goeminne - Ph.D. Student VIB-UGent Center for Medical Biotechnology Albert...