[R] t-test on multiple time series
Ben Bolker
bolker at zoo.ufl.edu
Mon Apr 3 20:36:16 CEST 2006
[redirected from R-devel: this really belongs on R-help]
I have two sets of time-series that I imported from Excel using RODBC
and placed in
"securities" and "factors".
What I need to do is generate t-scores for each security-factor pair.
I tried the following:
t1 <- t.test(securities[,3:42], factors[,2:41], var.equal=TRUE)
ANSWER:
If securities and factors are both data frames then something like
m1 <- mapply(t.test,securities[3:42],factors[2:41],SIMPLIFY=FALSE,
MoreArgs=list(var.equal=TRUE))
(note the lack of commas in the square brackets -- this extracts
the columns you want as sublists, although it might work with
commas as well, haven't tried it) will give you a list of t-test
results. If all you want is the t-statistic, something like
sapply(m1,"[[","statistic")
should do it.
Poke around in the documentation (?mapply, ?sapply, etc.) to
see why this all works.
--
620B Bartram Hall bolker at zoo.ufl.edu
Zoology Department, University of Florida http://www.zoo.ufl.edu/bolker
Box 118525 (ph) 352-392-5697
Gainesville, FL 32611-8525 (fax) 352-392-3704
More information about the R-help
mailing list