[R] different results form summarization by loop and sum or rowMeans function
Markus Schmidberger
schmidb at ibe.med.uni-muenchen.de
Thu Sep 11 15:49:43 CEST 2008
Hi,
I found different results calculating the rowMeans by the function
rowMeans() and a simple for-loop. The differences are very low. But
after this calculation I will start some optimization algorithms (BFGS
or CG) and there I get huge differences (from the small changes in the
beginning or start values, I changed nothing else in the code).
How I can avoid these differences between sum-loops and sum-functions?
Attached a small testcode using data form Bioconductor.
Best
Markus
library(affy)
data(affybatch.example)
mat <- exprs(affybatch.example)[1:100,1:3]
mat <- exp(1)*mat
mat <- asinh(mat)
rowM1<- rowMeans(mat)
t=rep(0,100) # Vektor mit 0en
for(i in 1:100){
for(j in 1:3)
t[i] <- t[i] + mat[i,j]
}
rowM2 <- t/3
m1 <- mat - rowM1
m2 <- mat -rowM2
print(m1-m2)
sessionInfo()
R version 2.7.1 (2008-06-23)
i386-pc-mingw32
locale:
LC_COLLATE=German_Germany.1252;LC_CTYPE=German_Germany.1252;LC_MONETARY=German_Germany.1252;LC_NUMERIC=C;LC_TIME=German_Germany.1252
attached base packages:
[1] tools stats graphics grDevices utils datasets methods
[8] base
other attached packages:
[1] affy_1.18.2 preprocessCore_1.2.0 affyio_1.8.0
[4] Biobase_2.0.1
--
Dipl.-Tech. Math. Markus Schmidberger
Ludwig-Maximilians-Universität München
IBE - Institut für medizinische Informationsverarbeitung,
Biometrie und Epidemiologie
Marchioninistr. 15, D-81377 Muenchen
URL: http://ibe.web.med.uni-muenchen.de
Mail: Markus.Schmidberger [at] ibe.med.uni-muenchen.de
Tel: +49 (089) 7095 - 4599
More information about the R-help
mailing list