The call to sweep in this function which was working in 0.62.2 is giving me
trouble in 62.3:
prcomponents <- function(x, center=TRUE, scale=TRUE, N=nrow(x)-1)
{if (center) center <- apply(x,2,mean)
else center <- rep(0, ncol(x))
if (scale) scale <- sqrt(apply(x,2,var))
else scale <- rep(1, ncol(x))
s <- svd(sweep(sweep(x,2, center),2, scale, FUN="/"))
# remove anything corresponding to effectively zero singular values.
rank <- sum(s$d > (s$d[1]*sqrt(.Machine$double.eps)))
if (rank < ncol(x)) s$v <- s$v[,1:rank, drop=FALSE]
s$d <- s$d/sqrt(max(1,N))
# r <- list(sdev=s$d, proj=s$v,x=x %*% s$v, center=center, scale=scale)
r <- list(sdev=s$d, proj=s$v, center=center, scale=scale)
r
}
Paul Gilbert
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
This does not work in 0.62.2 as I previously reported. The error is associated
with using
data(crimes) which is not what I've usually done. It is fixed by replacing
s <- svd(sweep(sweep(x,2, center),2, scale, FUN="/"))
with
s <- svd(sweep(sweep(as.matrix(x),2, center),2, scale, FUN="/"))
So, I'm not sure if this is a bug or if this is the way it should work? For my
purposes it is fixed already.
Paul Gilbert
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
The call to sweep in this function which was working in 0.62.2 is giving me
trouble in 62.3:
The call is invalid:
?sweep
Sweep out Array Summaries
sweep(x, MARGIN, STATS, FUN="-", ...)
Arguments:
x: an array.
class(crimes)
[1] "data.frame"
If you call sweep on a data frame, as in
sweep(crimes, 2, "-")
it does not work: it should not have done so before. On the other hand, in
0.62.2, valid arithmetic operations on data frames gave matrices,
which helped your illegal example but were incorrect on legal ones.
You need an as.matrix in your code, I believe.
This example also fails in S.
Brian D. Ripley, ripley@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-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Prof Brian D Ripley <ripley@stats.ox.ac.uk> writes:
On Fri, 21 Aug 1998, Paul Gilbert wrote:
The call to sweep in this function which was working in 0.62.2 is giving me
trouble in 62.3:
..
If you call sweep on a data frame, as in
sweep(crimes, 2, "-")
Um, you need some STATS in there...
it does not work: it should not have done so before. On the other hand, in
0.62.2, valid arithmetic operations on data frames gave matrices,
which helped your illegal example but were incorrect on legal ones.
You need an as.matrix in your code, I believe.
This example also fails in S.
Still, something weird is going on. First of all, the error message
about not finding "FUN" is less than obvious and secondly, it's not in
general a problem to do arithmetic on data frames as if they were
matrices. (E.g. crimes - as.matrix(crimes)) I think we have some of
the explanation in:
f<-get("-")
f(crimes,as.matrix(crimes))
Warning: ignored non function "f"
Warning: ignored non function "f"
Warning: ignored non function "f"
Warning: ignored non function "f"
Murder Assault UrbanPop Rape
Alabama 0 0 0 0
Alaska 0 0 0 0
Arizona 0 0 0 0
i.e. "something" applies "f" for each column and there's some kind of
mess related to scoping (there really is no other "f" around before
the function is called!)
It happens only with .Primitive functions like "-". Stuff like
sweep(crimes, 2, apply(crimes, 2, mean), function(x, y) x - y)
works perfectly.
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._