I need to calculate a large number of t statistics, and would like to do so via matrix operations. So far I have figured out a way to calculate the mean of each row of the matrix: d <- matrix(runif(100000,1,10), 1000, 10) # some test data s <- rep(1,ncol(d)) # a sum vector to use for matrix multiplication means <- (d%*%s)/ncol(d) This is at least 1 order of magnitude faster than iterating through the rows and using the mean function (<1/100th seconds vs. 13/100th seconds on my computer). Two questions: 1) Do you see a way to further optimize/simplify/elegantize this calculation of the row means? 2) How do I proceed to calculate the row variances with matrix operations (specifically, how can I use matrix operations to subtract each element of each row from the corresponding row mean)? Thank you, Eric Kort -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
t-test via matrix operations
4 messages · Kort, Eric, Brian Ripley, Pauline Gu +1 more
On Wed, 14 Aug 2002, Kort, Eric wrote:
I need to calculate a large number of t statistics, and would like to do so via matrix operations. So far I have figured out a way to calculate the mean of each row of the matrix: d <- matrix(runif(100000,1,10), 1000, 10) # some test data s <- rep(1,ncol(d)) # a sum vector to use for matrix multiplication means <- (d%*%s)/ncol(d) This is at least 1 order of magnitude faster than iterating through the
rows and using the mean function (<1/100th seconds vs. 13/100th seconds on my computer).
Two questions: 1) Do you see a way to further optimize/simplify/elegantize this
calculation of the row means? function rowMeans
2) How do I proceed to calculate the row variances with matrix
operations (specifically, how can I use matrix operations to subtract each element of each row from the corresponding row mean)? sweep does the subtraction, but I would make use of rowmeans(d^2) and rowmeans(d) in the classic hand-calculation formula.
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Dear R experts and Omega experts,
I am trying to run the R from Java. Now, I am facing the problem:
UnsatisfiedLinkError: SJava.dll, please see the detail Error message below:
Path is
/cygdrive/c/Tcl/bin:.:/cygdrive/c/ora9iclient/jdk/jre/bin/classic:/cygdr
ive/c/Documents and
Settings/pgu/Desktop/oldmachine/rtools:/cygdrive/e/R/gcc/bin
:/cygdrive/c/WINNT/system32:/cygdrive/c/WINNT:/cygdrive/c/WINNT/system32/WBEM:/c
ygdrive/c/ora9iclient/bin:/cygdrive/c/ora9iclient/jdk/bin:/cygdrive/c/Perl/bin:/
cygdrive/f/Mingw/bin:/cygdrive/c/Program Files/HTML Help
Workshop:/cygdrive/e/r-
1.5.1/library/SJava/libs:/cygdrive/e/r-1.5.1/src/gnuwin32
Hello...
Exception in thread "main" java.lang.UnsatisfiedLinkError:
E:\R-1.5.1\library\SJ
ava\libs\SJava.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at
org.omegahat.R.Java.RForeignReference.<clinit>(RForeignReference.java
:25)
As one can see, that I do have the SJava.dll directory
(e/r-1.5.1/library/SJava/libs) in the path. Please help. Thanks.
OS: Window 2000
R version: R1.5.1 (compiled from Source code)
RSJava version: 0.65
Thanks in advance for your help.
Pauline
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Pauline, Notice your path is separated by colons, and you seem to be using windows. Brad Buchsbaum
On Wed, 14 Aug 2002, Pauline Gu wrote:
Dear R experts and Omega experts,
I am trying to run the R from Java. Now, I am facing the problem:
UnsatisfiedLinkError: SJava.dll, please see the detail Error message below:
Path is
/cygdrive/c/Tcl/bin:.:/cygdrive/c/ora9iclient/jdk/jre/bin/classic:/cygdr
ive/c/Documents and
Settings/pgu/Desktop/oldmachine/rtools:/cygdrive/e/R/gcc/bin
:/cygdrive/c/WINNT/system32:/cygdrive/c/WINNT:/cygdrive/c/WINNT/system32/WBEM:/c
ygdrive/c/ora9iclient/bin:/cygdrive/c/ora9iclient/jdk/bin:/cygdrive/c/Perl/bin:/
cygdrive/f/Mingw/bin:/cygdrive/c/Program Files/HTML Help
Workshop:/cygdrive/e/r-
1.5.1/library/SJava/libs:/cygdrive/e/r-1.5.1/src/gnuwin32
Hello...
Exception in thread "main" java.lang.UnsatisfiedLinkError:
E:\R-1.5.1\library\SJ
ava\libs\SJava.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at
org.omegahat.R.Java.RForeignReference.<clinit>(RForeignReference.java
:25)
As one can see, that I do have the SJava.dll directory
(e/r-1.5.1/library/SJava/libs) in the path. Please help. Thanks.
OS: Window 2000
R version: R1.5.1 (compiled from Source code)
RSJava version: 0.65
Thanks in advance for your help.
Pauline
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._