txSpca | R Documentation |
txSpca
transforms data using supervised principal component
analysis.
TODO
txSpca(x, y = diag(1,
nrow(x)), k = 3,
...)
x |
a data matrix (features in columns, samples in rows) |
y |
target classification of |
k |
number of dimensions of the result, defaults to 3 in order to be usable in 'plot3dProj' |
... |
additional arguments to 'spca' |
Transform function taking two arguments: a data matrix y
to transform, and a logical center
determining whether
the data are to be centered, or not. The parameters of the
transform get returned in the params
attribute
(see spca
).
In addition, there is the varExplained
function added to
the parameters, which takes k
, the number of components,
and returns the contribution of individual dimensions to the top
k
components.
Tomas Sieger
spca
, txPca
, plot3dProj
tx<-txSpca(iris[,1:4],iris$Species)
plot(tx(iris[1:10,1:4])[,1:2])
# comparison of PCA vs. SPCA
# TODO
opar<-par(mfrow=c(1,2))
plot(txSpca(iris[,1:4],iris$Species)(iris[,1:4])[,1:2],col=c('red','green','blue')[as.numeric(iris$Species)])
plot(txPca(iris[,1:4])(iris[,1:4])[,1:2],col=c('red','green','blue')[as.numeric(iris$Species)])
par(opar)
if (interactive() && require(rgl)) {
# a 3D example
x<-iris[,1:4]
y<-iris$Species
plot3dProj(x, cls=y, tx=txSpca(x,y))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.