Commit 4ffde83e by Eric Coissac

Merge branch 'Release-1.0' into 'master'

Release 1.0

See merge request !2
parents cb0a71e2 4976bcea
^.*\.Rproj$ ^.*\.Rproj$
^\.Rproj\.user$ ^\.Rproj\.user$
^LICENCE-CECILL-2.1.txt$
LICENCE-CECILL-2.1.txt
Package: ProcMod Package: ProcMod
Type: Package Type: Package
Title: Informative Procrustean Matrix Correlation Title: Informative Procrustean Matrix Correlation
Version: 1.0.0 Version: 1.0.2
Author: Eric Coissac, Christelle Gonindard-Melodelima Author: Eric Coissac, Christelle Gonindard-Melodelima
Maintainer: Eric Coissac <eric.coissac@metabarcoding.org> Maintainer: Eric Coissac <eric.coissac@metabarcoding.org>
Description: Estimates procrustean corrected correlation between matrices for removing overfitting effect. Description: Estimates corrected Procrustean correlation between matrices for removing overfitting effect.
License: CECILL-2.1 License: CeCILL-2
Encoding: UTF-8 Encoding: UTF-8
LazyData: true LazyData: true
RoxygenNote: 6.1.1 RoxygenNote: 6.1.1
...@@ -16,16 +16,16 @@ Imports: MASS, ...@@ -16,16 +16,16 @@ Imports: MASS,
Matrix, Matrix,
mvtnorm, mvtnorm,
stats, stats,
doParallel,
foreach, foreach,
Rdpack Rdpack
Suggests: knitr, Suggests: knitr,
rmarkdown, rmarkdown,
roxygen2, roxygen2,
vegan, vegan,
testthat testthat,
ade4,
doParallel
RdMacros: Rdpack RdMacros: Rdpack
VignetteBuilder: knitr
Collate: Collate:
'internals.R' 'internals.R'
'procmod_frame.R' 'procmod_frame.R'
......
...@@ -34,11 +34,10 @@ export(pca) ...@@ -34,11 +34,10 @@ export(pca)
export(pcoa) export(pcoa)
export(procmod_frame) export(procmod_frame)
export(protate) export(protate)
export(rmatrix)
export(simulate_correlation) export(simulate_correlation)
export(simulate_matrix)
export(varls) export(varls)
import(MASS) import(MASS)
import(doParallel)
import(foreach) import(foreach)
import(permute) import(permute)
import(stats) import(stats)
......
...@@ -67,6 +67,18 @@ NULL ...@@ -67,6 +67,18 @@ NULL
#' \insertRef{Jackson:95:00}{ProcMod} #' \insertRef{Jackson:95:00}{ProcMod}
#' } #' }
#' #'
#' @examples
#' A <- simulate_matrix(10,3)
#' B <- simulate_matrix(10,5)
#' C <- simulate_correlation(B,10,r2=0.6)
#'
#' # Computes the correlation matrix
#' data <- procmod_frame(A = A, B = B, C = C)
#'
#' corls_test(A, B, permutations = 100)
#' corls_test(B, C, permutations = 100)
#' corls_test(data, permutations = 100)
#'
#' @seealso \code{\link[stats]{p.adjust}} #' @seealso \code{\link[stats]{p.adjust}}
#' #'
#' @author Eric Coissac #' @author Eric Coissac
...@@ -95,7 +107,7 @@ corls_test <- function(..., ...@@ -95,7 +107,7 @@ corls_test <- function(...,
xs <- ortho(xs) xs <- ortho(xs)
cov <- varls(xs, nperm = 0) cov <- varls(xs, nrand = 0)
lcov <- cov - eps lcov <- cov - eps
ngreater <- array(0,dim = dim(cov)) ngreater <- array(0,dim = dim(cov))
...@@ -123,7 +135,7 @@ corls_test <- function(..., ...@@ -123,7 +135,7 @@ corls_test <- function(...,
function(j) xs[[j]][pmatrix[ps[j], ], ] function(j) xs[[j]][pmatrix[ps[j], ], ]
) )
), ),
nperm = 0 nrand = 0
) )
ngreater <- ngreater + ( ngreater <- ngreater + (
rcov >= lcov) rcov >= lcov)
......
#' @include procmod.R #' @include procmod.R
#' @include procmod_frame.R #' @include procmod_frame.R
#' @include multivariate.R #' @include multivariate.R
#' @import doParallel
#' @import foreach #' @import foreach
#' @import stats #' @import stats
#' #'
...@@ -9,8 +8,8 @@ ...@@ -9,8 +8,8 @@
#' @author Eric Coissac #' @author Eric Coissac
NULL NULL
library(doParallel) .has_doParallel <- is.element("doParallel",installed.packages())
registerDoParallel(1) if (.has_doParallel) require(doParallel)
#' Compute the trace of a square matrix. #' Compute the trace of a square matrix.
#' #'
...@@ -125,15 +124,24 @@ registerDoParallel(1) ...@@ -125,15 +124,24 @@ registerDoParallel(1)
#' #'
#' @examples #' @examples
#' # Build Three matrices of 3 rows. #' # Build Three matrices of 3 rows.
#' A <- matrix(1:9, nrow = 3) #' A <- simulate_matrix(10,3)
#' B <- matrix(10:15, nrow = 3) #' B <- simulate_matrix(10,5)
#' C <- matrix(20:31, nrow = 3) #' C <- simulate_correlation(B,10,r2=0.6)
#' # compute the variance covariance matrix #'
#' # Computes the variance covariance matrix
#' varls(A, B, C) #' varls(A, B, C)
#' varls(A = A, B = B, C = C) #' varls(A = A, B = B, C = C)
#'
#' data = procmod_frame(A = A, B = B, C = C) #' data = procmod_frame(A = A, B = B, C = C)
#' varls(data) #' varls(data)
#' #'
#' # Computes the correlation matrix
#' corls(data, nrand = 500)
#'
#' # Computes the partial correlation matrix
#' corls_partial(data)
#' corls_partial(data, nrand = 0)
#'
#' @author Eric Coissac #' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima #' @author Christelle Gonindard-Melodelima
#' #'
...@@ -193,10 +201,15 @@ varls <- function(..., ...@@ -193,10 +201,15 @@ varls <- function(...,
for (i in seq_len(nx)) for (i in seq_len(nx))
v_xs[[i]] <- var(xs[[i]]) v_xs[[i]] <- var(xs[[i]])
if (! getDoParRegistered()) registerDoParallel(1) if (.has_doParallel && getDoParRegistered()) {
`%dp%` <- `%dopar%`
}
else{
`%dp%` <- `%do%`
}
s_cov_xxs <- foreach(k = seq_len(nrand), s_cov_xxs <- foreach(k = seq_len(nrand),
.combine = cbind) %dopar% { .combine = cbind) %dp% {
s1_cov_xxs <- matrix(0, nrow = nx, ncol = nx) s1_cov_xxs <- matrix(0, nrow = nx, ncol = nx)
r_xs <- vector(mode = "list", nx) r_xs <- vector(mode = "list", nx)
r_ys <- vector(mode = "list", nx) r_ys <- vector(mode = "list", nx)
...@@ -297,12 +310,24 @@ corls_partial <- function(..., nrand = 100) { ...@@ -297,12 +310,24 @@ corls_partial <- function(..., nrand = 100) {
make_subS3Class(rp, "procmod_corls") make_subS3Class(rp, "procmod_corls")
} }
#' Print procrustean variance / covariance matrix. #' Print procrustean Variance / Covariance Matrix.
#' #'
#' @param x a \code{procmod_varls} #' @param x a \code{procmod_varls}
#' object #' object
#' @param ... other parameters passed to other functions #' @param ... other parameters passed to other functions
#' #'
#' @examples
#' # Build Three matrices of 3 rows.
#' A <- simulate_matrix(10,3)
#' B <- simulate_matrix(10,5)
#' C <- simulate_correlation(B,10,r2=0.6)
#'
#' # Computes the variance covariance matrix
#' data <- procmod_frame(A = A, B = B, C = C)
#' v <- varls(data, nrand = 1000)
#'
#' print(v)
#'
#' @seealso \code{\link[ProcMod]{varls}} #' @seealso \code{\link[ProcMod]{varls}}
#' #'
#' @author Eric Coissac #' @author Eric Coissac
...@@ -323,6 +348,27 @@ print.procmod_varls <- function(x, ...) { ...@@ -323,6 +348,27 @@ print.procmod_varls <- function(x, ...) {
attr(x,name) attr(x,name)
} }
#' The Names of the elements of a Variance / Covariance Matrix.
#'
#' Returns the names of the elements associated to a \code{procmod_varls}
#' object.
#'
#' @param x a \code{procmod_varls} object
#'
#' @examples
#' # Build Three matrices of 3 rows.
#' A <- simulate_matrix(10,3)
#' B <- simulate_matrix(10,5)
#' C <- simulate_correlation(B,10,r2=0.6)
#'
#' # Computes the variance covariance matrix
#' data <- procmod_frame(A = A, B = B, C = C)
#' v <- varls(data, nrand = 1000)
#'
#' names(v)
#'
#' @seealso \code{\link[ProcMod]{varls}}
#'
#' @author Eric Coissac #' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima #' @author Christelle Gonindard-Melodelima
#' @export #' @export
...@@ -334,12 +380,24 @@ names.procmod_varls <- function(x) { ...@@ -334,12 +380,24 @@ names.procmod_varls <- function(x) {
} }
#' Print procrustean correlation matrix. #' Print a procrustean Correlation Matrix.
#' #'
#' @param x a \code{procmod_corls} #' @param x a \code{procmod_corls}
#' object #' object
#' @param ... other parameters passed to other functions #' @param ... other parameters passed to other functions
#' #'
#' @examples
#' # Build Three matrices of 3 rows.
#' A <- simulate_matrix(10,3)
#' B <- simulate_matrix(10,5)
#' C <- simulate_correlation(B,10,r2=0.6)
#'
#' # Computes the correlation matrix
#' data <- procmod_frame(A = A, B = B, C = C)
#' cls <- corls(data, nrand = 1000)
#'
#' print(cls)
#'
#' @seealso \code{\link[ProcMod]{corls}} #' @seealso \code{\link[ProcMod]{corls}}
#' #'
#' @author Eric Coissac #' @author Eric Coissac
...@@ -362,6 +420,27 @@ print.procmod_corls <- function(x, ...) { ...@@ -362,6 +420,27 @@ print.procmod_corls <- function(x, ...) {
} }
#' The Names of the elements of a Correlation Matrix
#'
#' Returns the names of the elements associated to a \code{procmod_corls}
#' object.
#'
#' @param x a \code{procmod_corls} object
#'
#' @examples
#' # Build Three matrices of 3 rows.
#' A <- simulate_matrix(10,3)
#' B <- simulate_matrix(10,5)
#' C <- simulate_correlation(B,10,r2=0.6)
#'
#' # Computes the correlation matrix
#' data <- procmod_frame(A = A, B = B, C = C)
#' cls <- corls(data, nrand = 1000)
#'
#' names(cls)
#'
#' @seealso \code{\link[ProcMod]{corls}}
#'
#' @author Eric Coissac #' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima #' @author Christelle Gonindard-Melodelima
#' @export #' @export
......
...@@ -22,6 +22,16 @@ NULL ...@@ -22,6 +22,16 @@ NULL
#' \code{\link[base]{matrix}} method. #' \code{\link[base]{matrix}} method.
#' @param ... additional arguments to be passed to or from methods. #' @param ... additional arguments to be passed to or from methods.
#' #'
#' @examples
#' data(bacteria)
#' bacteria_rel_freq <- sweep(bacteria,
#' 1,
#' rowSums(bacteria),
#' "/")
#' bacteria_hellinger <- sqrt(bacteria_rel_freq)
#' bacteria_dist <- dist(bacteria_hellinger)
#' bdf <- as.data.frame(bacteria_dist)
#'
#' @author Eric Coissac #' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima #' @author Christelle Gonindard-Melodelima
#' @export #' @export
...@@ -62,6 +72,17 @@ as.data.frame.dist <- function(x, row.names = NULL, optional = FALSE, ...) { ...@@ -62,6 +72,17 @@ as.data.frame.dist <- function(x, row.names = NULL, optional = FALSE, ...) {
#' \code{n} the number pf observations. This matrix defines the #' \code{n} the number pf observations. This matrix defines the
#' coordinates of each point in the orthogonal space. #' coordinates of each point in the orthogonal space.
#' #'
#' @examples
#' data(bacteria)
#' bacteria_rel_freq <- sweep(bacteria,
#' 1,
#' rowSums(bacteria),
#' "/")
#' bacteria_hellinger <- sqrt(bacteria_rel_freq)
#' bacteria_dist <- dist(bacteria_hellinger)
#'
#' project <- nmds(bacteria_dist)
#'
#' @author Eric Coissac #' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima #' @author Christelle Gonindard-Melodelima
#' @export #' @export
...@@ -117,6 +138,17 @@ nmds <- function(distances, ...@@ -117,6 +138,17 @@ nmds <- function(distances,
#' \code{n} the number pf observations. This matrix defines the #' \code{n} the number pf observations. This matrix defines the
#' coordinates of each point in the orthogonal space. #' coordinates of each point in the orthogonal space.
#' #'
#' @examples
#' data(bacteria)
#' bacteria_rel_freq <- sweep(bacteria,
#' 1,
#' rowSums(bacteria),
#' "/")
#' bacteria_hellinger <- sqrt(bacteria_rel_freq)
#' bacteria_dist <- dist(bacteria_hellinger)
#'
#' project <- pcoa(bacteria_dist)
#'
#' @author Eric Coissac #' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima #' @author Christelle Gonindard-Melodelima
#' @export #' @export
...@@ -154,6 +186,16 @@ pcoa <- function(distances) { ...@@ -154,6 +186,16 @@ pcoa <- function(distances) {
#' \code{n} the number pf observations. This matrix defines the #' \code{n} the number pf observations. This matrix defines the
#' coordinates of each point in the orthogonal space. #' coordinates of each point in the orthogonal space.
#' #'
#' @examples
#' data(bacteria)
#' bacteria_rel_freq <- sweep(bacteria,
#' 1,
#' rowSums(bacteria),
#' "/")
#' bacteria_hellinger <- sqrt(bacteria_rel_freq)
#'
#' project <- pca(bacteria_hellinger)
#'
#' @author Eric Coissac #' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima #' @author Christelle Gonindard-Melodelima
#' @export #' @export
...@@ -184,6 +226,12 @@ pca <- function(data, scale = FALSE) { ...@@ -184,6 +226,12 @@ pca <- function(data, scale = FALSE) {
#' @return a \code{numeric} matrix centred by rows #' @return a \code{numeric} matrix centred by rows
#' and columns #' and columns
#' #'
#' @examples
#' data(bacteria)
#' bact_bc <- bicenter(bacteria)
#' sum(rowSums(bact_bc))
#' sum(colSums(bact_bc))
#'
#' @author Eric Coissac #' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima #' @author Christelle Gonindard-Melodelima
#' @export #' @export
...@@ -208,6 +256,21 @@ bicenter <- function(m) { ...@@ -208,6 +256,21 @@ bicenter <- function(m) {
#' considered positive if it is larger than #' considered positive if it is larger than
#' -tol*lambda1 where lambda1 is the largest eigenvalue. #' -tol*lambda1 where lambda1 is the largest eigenvalue.
#' #'
#' @examples
#' library(vegan)
#' data(bacteria)
#'
#' bacteria_rel_freq <- sweep(bacteria,
#' 1,
#' rowSums(bacteria),
#' "/")
#'
#' bacteria_bray <- vegdist(bacteria_rel_freq,method = "bray")
#' is_euclid(bacteria_bray)
#'
#' bacteria_chao <- vegdist(floor(bacteria*10000),method = "chao")
#' is_euclid(bacteria_chao)
#'
#' @author Eric Coissac #' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima #' @author Christelle Gonindard-Melodelima
#' @export #' @export
...@@ -258,6 +321,33 @@ is_orthogonal <- function(x) { ...@@ -258,6 +321,33 @@ is_orthogonal <- function(x) {
#' \code{n} the number pf observations. This matrix defines the #' \code{n} the number pf observations. This matrix defines the
#' coordinates of each point in the orthogonal space. #' coordinates of each point in the orthogonal space.
#' #'
#' @examples
#' library(vegan)
#' data(bacteria)
#' data(eukaryotes)
#' data(soil)
#'
#' dataset <- procmod_frame(euk = vegdist(decostand(eukaryotes,
#' method = "hellinger"),
#' method = "euclidean"),
#' bac = vegdist(decostand(bacteria,
#' method = "hellinger"),
#' method = "euclidean"),
#' soil = scale(soil,
#' center = TRUE,
#' scale = TRUE))
#'
#' dp <- ortho(dataset)
#'
#' bacteria_rel_freq <- sweep(bacteria,
#' 1,
#' rowSums(bacteria),
#' "/")
#' bacteria_hellinger <- sqrt(bacteria_rel_freq)
#' bacteria_dist <- dist(bacteria_hellinger)
#'
#' project <- ortho(bacteria_dist)
#'
#' @author Eric Coissac #' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima #' @author Christelle Gonindard-Melodelima
#' @export #' @export
......
#' @title Informative Procrustean Matrix Correlation
#' @name procmod
#' @description Estimates corrected Procrustean correlation between
#' matrices for removing overfitting effect.
#' @details
#' The functions in the ProcMod package aims to estimate and to test correlation
#' between matrices, correcting for the spurious correlations because of the
#' over-fitting effect.
#'
#' The ProcMod package is developed on the metabarcoding.org gitlab
#' (https://git.metabarcoding.org/lecasofts/ProcMod).
#' The gitlab of metabarcoding.org provides up-to-date information and
#' forums for bug reports.
#'
#' @author Christelle Gonindard-Melodelima
#' @author Eric Coissac
#'
#' @docType package #' @docType package
#' @importFrom Rdpack reprompt #' @importFrom Rdpack reprompt
NULL NULL
...@@ -8,7 +25,8 @@ NULL ...@@ -8,7 +25,8 @@ NULL
#' is a simplified version of a full data set #' is a simplified version of a full data set
#' describing biodiversity changes along a South-North #' describing biodiversity changes along a South-North
#' gradient on the Australian East Coast, from Sidney to #' gradient on the Australian East Coast, from Sidney to
#' North Cap. The gradient is constituted of 21 locations. #' North Cap using a DNA metabarcoding approach.
#' The gradient is constituted of 21 locations.
#' #'
#' \describe{ #' \describe{
#' \item{bacteria}{is a 21 x 2150 \code{data.frame} describing bacterial #' \item{bacteria}{is a 21 x 2150 \code{data.frame} describing bacterial
......
...@@ -309,6 +309,18 @@ procmod_frame <- function(..., ...@@ -309,6 +309,18 @@ procmod_frame <- function(...,
#' \code{TRUE} if \code{x} is a \code{procmod_frame}, #' \code{TRUE} if \code{x} is a \code{procmod_frame},
#' \code{FALSE} otherwise. #' \code{FALSE} otherwise.
#' #'
#' @examples
#' # Builds a procmod_frame with two random matrices
#' m1 <- simulate_matrix(10,20)
#' m2 <- simulate_matrix(10,30)
#' pmf <- procmod_frame(m1 = m1, m2 = m2)
#'
#' # Returns TRUE
#' is_procmod_frame(pmf)
#'
#' # Returns FALSE
#' is_procmod_frame(3)
#'
#' @author Eric Coissac #' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima #' @author Christelle Gonindard-Melodelima
#' @export #' @export
...@@ -327,6 +339,28 @@ is_procmod_frame <- function(x) { ...@@ -327,6 +339,28 @@ is_procmod_frame <- function(x) {
#' implementation of that method #' implementation of that method
#' @return a \code{procmod_frame} object #' @return a \code{procmod_frame} object
#' #'
#' @examples
#' # Builds a list containing two random matrices
#' m1 <- simulate_matrix(10,20)
#' m2 <- simulate_matrix(10,30)
#' l <- list(m1 = m1, m2 = m2)
#'
#' # Converts the list to a procmod_frame
#' pmf1 <- as_procmod_frame(l)
#'
#' # Builds a procmod_frame from a matrix
#' m3 <- matrix(1:12,nrow=3)
#' pmf2 <- as_procmod_frame(matrix(1:12,nrow=3))
#' # Returns 4, the column count of the input matrix
#' length(pmf2)
#'
#' # Builds a 3D array
#' a <- array(1:24,dim = c(3,4,2))
#'
#' # The conversion to a procmod_frame makes
#' # an procmod element from each third dimension
#' as_procmod_frame(a)
#'
#' @author Eric Coissac #' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima #' @author Christelle Gonindard-Melodelima
#' @export #' @export
...@@ -390,9 +424,20 @@ as_procmod_frame.matrix <- function(data, ...) { ...@@ -390,9 +424,20 @@ as_procmod_frame.matrix <- function(data, ...) {
#' Dimensions of a ProcMod Frame. #' Dimensions of a ProcMod Frame.
#' #'
#' Dimension 1 is the number of rows (individus)
#' shared by the aggregated matrices. Dimension 2
#' is the number of aggregated matrices
#'
#' @param x a \code{\link[ProcMod]{procmod_frame}} #' @param x a \code{\link[ProcMod]{procmod_frame}}
#' object #' object
#' #'
#' @examples
#' # Builds a procmod_frame with two random matrices
#' m1 <- simulate_matrix(10,20)
#' m2 <- simulate_matrix(10,30)
#' pmf <- procmod_frame(m1 = m1, m2 = m2)
#' dim(pmf)
#'
#' @author Eric Coissac #' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima #' @author Christelle Gonindard-Melodelima
#' @export #' @export
...@@ -504,6 +549,58 @@ dim.procmod_frame <- function(x) ...@@ -504,6 +549,58 @@ dim.procmod_frame <- function(x)
y y
} }
#' Subsetting Procmod Frames
#'
#' This is the implementation of the \code{\link[base]{subset}} generic function for
#' \code{procmod_frame}.
#'
#' The subset argument works on rows. Note that subset will be evaluated in the
#' \code{procmod_frame}, so columns can be referred to (by name) as variables
#' in the expression (see the examples).
#'
#' The select argument if provided indicates with matrices
#' have to be conserved. It works by first replacing column names in the selection
#' expression with the corresponding column numbers in the \code{procmod_frame} and then using
#' the resulting integer vector to index the columns. This allows the use of the
#' standard indexing conventions so that for example ranges of columns can
#' be specified easily, or single columns can be dropped (see the examples). Remember
#' that each column of a \code{procmod_frame} is actually a matrix.
#'
#' The drop argument is passed on to the \code{procmod_frame} indexing method.
#' The default value is \code{FALSE}.
#'
#' @param x object to be subsetted.
#' @param subset logical expression indicating elements or
#' rows to keep: missing values are taken as false.
#' @param select expression, indicating columns to select from a data frame.
#' @param drop passed on to [ indexing operator.
#' @param ... further arguments to be passed to or from other methods.
#'
#' @return A \code{procmod_frame} containing just the selected rows and columns.
#'
#' @examples
#' library(vegan)
#' data(bacteria)
#' data(eukaryotes)
#' data(soil)
#'
#' dataset <- procmod_frame(euk = vegdist(decostand(eukaryotes,
#' method = "hellinger"),
#' method = "euclidean"),
#' bac = vegdist(decostand(bacteria,
#' method = "hellinger"),
#' method = "euclidean"),
#' soil = scale(soil,
#' center = TRUE,
#' scale = TRUE))
#' dim(dataset)
#'
#' higher_ph = subset(dataset,soil[,"pH"] > 0)
#' dim(higher_ph)
#'
#' without_bacteria = subset(dataset,soil[,"pH"] > 0, -bac)
#' dim(without_bacteria)
#'
#' @author Eric Coissac #' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima #' @author Christelle Gonindard-Melodelima
#' @export #' @export
......
#' @include internals.R #' @include internals.R
#' #'
#' @title ProcMod
#' @name procmod
#' @description blabla
#' @author Christelle Gonindard-Melodelima
#' @author Eric Coissac
#'
NULL NULL
#' Rotate the \code{src} matrix to fit into the space of the \code{dest} matrix. #' Rotate the \code{src} matrix to fit into the space of the \code{dest} matrix.
...@@ -20,9 +14,11 @@ NULL ...@@ -20,9 +14,11 @@ NULL
#' @return a numeric matrix #' @return a numeric matrix
#' #'
#' @examples #' @examples
#' # Renerate a random matrix of size 10 x 15 #' # Generates two random matrices of size 10 x 15
#' m1 <- rmatrix(10, 15) #' m1 <- simulate_matrix(10, 15)
#' m2 <- rmatrix(10, 20) #' m2 <- simulate_matrix(10, 20)
#'
#' # Rotates matrix m1 on m2
#' mr <- protate(m1, m2) #' mr <- protate(m1, m2)
#' #'
#' @author Christelle Gonindard-Melodelima #' @author Christelle Gonindard-Melodelima
......
...@@ -17,14 +17,14 @@ ...@@ -17,14 +17,14 @@
#' @return a numeric matrix of \code{n} rows and \code{p} columns #' @return a numeric matrix of \code{n} rows and \code{p} columns
#' #'
#' @examples #' @examples
#' sim1 <- rmatrix(25,10) #' sim1 <- simulate_matrix(25,10)
#' class(sim1) #' class(sim1)
#' dim(sim1) #' dim(sim1)
#' #'
#' @author Eric Coissac #' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima #' @author Christelle Gonindard-Melodelima
#' @export #' @export
rmatrix <- function(n, p, equal_var = TRUE) { simulate_matrix <- function(n, p, equal_var = TRUE) {
new <- rnorm(n * p, mean = 0, sd = 1) new <- rnorm(n * p, mean = 0, sd = 1)
dim(new) <- c(n, p) dim(new) <- c(n, p)
...@@ -33,12 +33,10 @@ rmatrix <- function(n, p, equal_var = TRUE) { ...@@ -33,12 +33,10 @@ rmatrix <- function(n, p, equal_var = TRUE) {
attributes(new)$`scaled:center` <- NULL attributes(new)$`scaled:center` <- NULL
attributes(new)$`scaled:scale` <- NULL attributes(new)$`scaled:scale` <- NULL
new.sd <- sqrt(sum(new^2) / (n - 1))