mirror of
https://github.com/msberends/AMR.git
synced 2025-07-08 07:51:57 +02:00
(v1.0.1.9001) PCA unit tests
This commit is contained in:
@ -33,6 +33,7 @@
|
||||
#' @param ellipse_prob statistical size of the ellipse in normal probability
|
||||
#' @param ellipse_size the size of the ellipse line
|
||||
#' @param ellipse_alpha the alpha (transparency) of the ellipse line
|
||||
#' @param points_size the size of the points
|
||||
#' @param points_alpha the alpha (transparency) of the points
|
||||
#' @param arrows a logical to indicate whether arrows should be drawn
|
||||
#' @param arrows_textsize the size of the text for variable names
|
||||
@ -42,7 +43,7 @@
|
||||
#' @param arrows_alpha the alpha (transparency) of the arrows and their text
|
||||
#' @param base_textsize the text size for all plot elements except the labels and arrows
|
||||
#' @param ... Parameters passed on to functions
|
||||
#' @source The [ggplot_pca()] function is based on the [ggbiplot()] function from the `ggbiplot` package by Vince Vu, as found on GitHub: <https://github.com/vqv/ggbiplot> (retrieved: 2 March 2020, their latest commit: [`7325e88`](https://github.com/vqv/ggbiplot/commit/7325e880485bea4c07465a0304c470608fffb5d9); 12 February 2015).
|
||||
#' @source The [ggplot_pca()] function is based on the `ggbiplot()` function from the `ggbiplot` package by Vince Vu, as found on GitHub: <https://github.com/vqv/ggbiplot> (retrieved: 2 March 2020, their latest commit: [`7325e88`](https://github.com/vqv/ggbiplot/commit/7325e880485bea4c07465a0304c470608fffb5d9); 12 February 2015).
|
||||
#'
|
||||
#' As per their GPL-2 licence that demands documentation of code changes, the changes made based on the source code were:
|
||||
#' 1. Rewritten code to remove the dependency on packages `plyr`, `scales` and `grid`
|
||||
@ -324,14 +325,18 @@ pca_calculations <- function(pca_model,
|
||||
sigma <- var(cbind(x$xvar, x$yvar))
|
||||
mu <- c(mean(x$xvar), mean(x$yvar))
|
||||
ed <- sqrt(qchisq(ellipse_prob, df = 2))
|
||||
data.frame(sweep(circle %*% chol(sigma) * ed, 2, mu, FUN = "+"),
|
||||
el <- data.frame(sweep(circle %*% chol(sigma) * ed, 2, mu, FUN = "+"),
|
||||
groups = x$groups[1])
|
||||
names(el)[1:2] <- c("xvar", "yvar")
|
||||
el
|
||||
}))
|
||||
names(ell)[1:2] <- c("xvar", "yvar")
|
||||
if (NROW(ell) == 0) {
|
||||
ell <- NULL
|
||||
}
|
||||
} else {
|
||||
ell <- NULL
|
||||
}
|
||||
|
||||
|
||||
list(nobs.factor = nobs.factor,
|
||||
d = d,
|
||||
u = u,
|
||||
|
1
R/pca.R
1
R/pca.R
@ -31,6 +31,7 @@
|
||||
#' The result of the [pca()] function is a [`prcomp`] object, with an additional attribute `non_numeric_cols` which is a vector with the column names of all columns that do not contain numeric values. These are probably the groups and labels, and will be used by [ggplot_pca()].
|
||||
#' @rdname pca
|
||||
#' @exportMethod prcomp.data.frame
|
||||
#' @importFrom stats prcomp
|
||||
#' @export
|
||||
#' @examples
|
||||
#' # `example_isolates` is a dataset available in the AMR package.
|
||||
|
Reference in New Issue
Block a user