# R/doAngle.R In PCADSC: Tools for Principal Component Analysis-Based Data Structure Comparisons

#### Documented in doAngle

```#' @title Compute angle information
#'
#' @description Computes the information that is needed in order to make an \code{\link{anglePlot}}
#' from a \code{PCADSC} or \code{pcaRes} object. Typically, this function is called on a partial
#'
#' @param x Either a \code{PCADSC} or a \code{pcaRes} object.
#'
#' @examples
#' data(iris)
#'
#' #Define grouping variable, grouping the observations by whether their species is
#' #Setosa or not
#' iris\$group <- "setosa"
#' iris\$group[iris\$Species != "setosa"] <- "non-setosa"
#' iris\$Species <- NULL
#'
#'\dontrun{
#' #make a partial PCADSC object, splitting the data by "group"
#'
#' #No angleInfo available
#'
#' }
#'
#' #Make a partial PCADSC object and only add angle information for a
#' #faster runtime
#'   doChroma = FALSE, doCE = FALSE)
#'
#'
#' @export
doAngle <- function(x) {
UseMethod("doAngle")
}

#x: pcaRes
#' @export
doAngle.pcaRes <- function(x) {
eigen1 <- x\$eigen1
eigen2 <- x\$eigen2
n1 <- x\$n1
n2 <- x\$n2
d <- x\$d
splitBy <- x\$splitBy
splitLevels <- x\$splitLevels
vars <- x\$vars

#make angleFrame for plotting

# find angles
angles <- matrix(0, d, d)

#Calculate vector lengths
max.eigen <- max(c(eigen1[1],eigen2[1]))
len1 <- len2 <- matrix(NA, d, d)

for (i in 1:d) for (j in 1:d) {
}

#Store in data.frame ready for plotting
aF <- data.frame(x = rep(1:d, 2*d),
y = rep(rep(1:d, each = d),2),
xend = c(rep(1:d, d) + c(len1)*cos((pi-c(angles))/2),
rep(1:d, d) + c(len2)*cos(c(angles)/2)),
yend = c(rep(1:d, each = d) + c(len1)*sin((pi-c(angles))/2),
rep(1:d, each = d) + c(len2)*sin(c(angles)/2)),
type = rep(c("1st", "2nd"), each = d*d))

#pack and return output
out <- list(aF = aF, splitLevels = splitLevels, d = d)
class(out) <- "angleInfo"
out
}

#' @export
x\$angleInfo <- doAngle(x\$pcaRes)
x
}
```

Any scripts or data that you put into this service are public.

PCADSC documentation built on May 2, 2019, 1:09 p.m.