convenience version of the singular value decomposition
Description
Packages results from an SVD on what can be either a cases by variables (features) or variables by cases layout, for use in principal component and related calculations
Usage
1 2 
Arguments
x 
matrix on which SVD is to be performed 
varscores 
logical; should scores be returned? 
cases 
specify either 
center 
logical: if set to 
standardize 
logical: should values of variables be standardized to
zero mean and unit deviance. Takes precedence over the setting of

scale.cases 
set to a value in [0,1]. 
log 
logical: should logarithms be taken, prior to the calculation? 
sc 
the variable scores are divided by sqrt{sc1}. By default,

reflect 
a vector of two elements, by default 
Value
g 
case scores 
h 
variable scores 
avv 
variable means 
sdev 
singular values, divides by the square root of one less than the number of cases 
Author(s)
John Maindonald
See Also
La.svd
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49  USArrests.svd < pcp(x = USArrests)
## The function is currently defined as
function(x=USArrests,
varscores=TRUE,
cases="rows",
center="vars",
standardize=FALSE,
scale.cases=1,
log=FALSE,
sc=1,
reflect=c(1,1))
{
x < as.matrix(x)
avv < 0
sdv < 1
casedim < 2as.logical(cases=="rows")
vardim < 3casedim
## casedim=1 if rows are cases; otherwise casedim=2
## scale.cases=0 gives a pure rotation of the variables
## scale.cases=1 weights a/c the singular values
ncases < dim(x)[casedim]
nvar < dim(x)[vardim]
if(is.null(sc))sc < dim(x)[casedim]1
if(log)x < log(x, base=2)
if(standardize){
avv < apply(x, vardim, mean)
sdv < apply(x, vardim, sd)
x < sweep(x, vardim, avv,"")
x < sweep(x, vardim, sdv,"/")
}
else if(as.logical(match("vars", center, nomatch=0))){
avv < apply(x,vardim, mean)
x < sweep(x, vardim, avv,"")}
svdx < La.svd(x, method = c("dgesdd"))
h < NULL
if(cases=="rows"){
g < sweep(svdx$u, 2, svdx$d^scale.cases, "*")*sqrt(sc)
if(varscores)
h < t((svdx$d^(1scale.cases)* svdx$vt ))/sqrt(sc)
}
else if(cases=="columns"){
g < sweep(t(svdx$vt), 2, svdx$d^scale.cases, "*")*sqrt(sc)
if(varscores)
h < sweep(svdx$u, 2, svdx$d^(1scale.cases),"*")/sqrt(sc)
}
invisible(list(g=g, rotation=h, av=avv, sdev=svdx$d/sqrt(ncases1)))
}

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker. Vote for new features on Trello.