Commit e7284bab by Eric Coissac

Adds some docs to the package

parent 51acc0d5
...@@ -17,16 +17,19 @@ Imports: MASS, ...@@ -17,16 +17,19 @@ Imports: MASS,
mvtnorm, mvtnorm,
stats, stats,
doParallel, doParallel,
foreach foreach,
Rdpack
Suggests: knitr, Suggests: knitr,
rmarkdown, rmarkdown,
roxygen2, roxygen2,
vegan vegan
RdMacros: Rdpack
VignetteBuilder: knitr VignetteBuilder: knitr
Collate: Collate:
'internals.R' 'internals.R'
'procmod_frame.R' 'procmod_frame.R'
'multivariate.R' 'multivariate.R'
'procmod.R'
'covls.R' 'covls.R'
'corls_test.R' 'corls_test.R'
'procuste.R' 'procuste.R'
......
...@@ -40,3 +40,4 @@ export(varls) ...@@ -40,3 +40,4 @@ export(varls)
import(MASS) import(MASS)
import(doParallel) import(doParallel)
import(foreach) import(foreach)
importFrom(Rdpack,reprompt)
...@@ -6,9 +6,9 @@ NULL ...@@ -6,9 +6,9 @@ NULL
#' Generate permutation matrix according to a schema. #' Generate permutation matrix according to a schema.
#' #'
#' @param perm #' @param perm xxx
#' @param n #' @param n zzz
#' @param strata #' @param strata eeee
#' #'
#' #'
#' The permutation schema is defined using the `how` function. #' The permutation schema is defined using the `how` function.
......
#' @include procmod.R
#' @include procmod_frame.R #' @include procmod_frame.R
#' @include multivariate.R #' @include multivariate.R
#' @import doParallel #' @import doParallel
...@@ -12,6 +13,9 @@ registerDoParallel(1) ...@@ -12,6 +13,9 @@ registerDoParallel(1)
#' Compute the trace of a square matrix. #' Compute the trace of a square matrix.
#' #'
#' The trace of a square matrix is defined as the sum
#' of its diagonal elements.
#'
#' @param X a square matrix #' @param X a square matrix
#' @return the trace of X #' @return the trace of X
#' #'
...@@ -20,16 +24,12 @@ registerDoParallel(1) ...@@ -20,16 +24,12 @@ registerDoParallel(1)
#' ProcMod:::.Trace(m) #' ProcMod:::.Trace(m)
#' @note Internal function do not use. #' @note Internal function do not use.
#' #'
#' @rdname internal.getPermuteMatrix #' @rdname internal.Trace
#' @author Eric Coissac #' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima #' @author Christelle Gonindard-Melodelima
#' #'
.Trace <- function(X) sum(diag(X)) .Trace <- function(X) sum(diag(X))
.estimate_mode <- function(x) {
d <- density(x)
d$x[which.max(d$y)]
}
.var2cor <- function(c) { .var2cor <- function(c) {
v <- sqrt(diag(c)) v <- sqrt(diag(c))
...@@ -37,20 +37,62 @@ registerDoParallel(1) ...@@ -37,20 +37,62 @@ registerDoParallel(1)
c / vv c / vv
} }
#' Compute the variance, covariance matrix of K coordinate matrices. #' Compute the procrustean variance, covariance matrix of K matrices.
#' #'
#' Covariance between two matrices is defined as the sum of the #' Procrustean covariance between two matrices X and Y, is defined as the sum
#' sigular values of the X'Y matrix. All the matrices must have #' of the singular values of the X'Y matrix
#' \insertCite{Gower:71:00,Lingoes:74:00}{Rdpack}. Both the matrices must have
#' the same number of rows. #' the same number of rows.
#' #'
#' @param ... the set of matrices #' \code{varls} computes the variance covariance matrix of a set of matrices
#' following the above definition. The variances and covariances are corrected
#' to avoid over fitting \insertCite{Coissac-Eric:19:00}{Rdpack}. .
#'
#' Before computing the covariances, matrices are projected into an
#' orthogonal space using the \code{\link[ProcMod]{ortho}} function.
#'
#' @references{
#' \insertRef{Gower:71:00}{ProcMod}
#'
#' \insertRef{Lingoes:74:00}{ProcMod}
#'
#' \insertRef{Coissac-Eric:19:00}{ProcMod}
#' }
#'
#' @param ... the set of matrices or a \code{\link[ProcMod]{procmod.frame}}
#' object.
#' @param nrand number of randomisation used to estimate the mean #' @param nrand number of randomisation used to estimate the mean
#' covariance observed between two random matrix. #' covariance observed between two random matrix.
#' If rand is \code{NULL} or equal to \code{0}, no correction
#' is estimated and the raw procrustean covariances are
#' estimated.
#' @param p.adjust.method the multiple test correction method used #' @param p.adjust.method the multiple test correction method used
#' to adjust p values. \code{p.adjust.method} belongs #' to adjust p values. \code{\link[stats]{p.adjust.method}}
#' one of the folowing values: "holm", "hochberg", "hommel", #' belongsone of the folowing values: \code{"holm"},
#' "bonferroni", "BH", "BY", "fdr", "none". The default is #' \code{"hochberg"}, \code{"hommel"}, \code{"bonferroni"},
#' set to "holm". #' \code{"BH"}, \code{"BY"}, \code{"fdr"}, \code{"none"}.
#' The default is,set to \code{"holm"}.
#'
#' @return a \code{procmod.varls} object which corresponds to a numeric
#' matrix annotated by several attributes.
#'
#' The following attribute is always added:
#'
#' - \code{nrand} an integer value indicating the number of
#' randomisations used to estimate the mean of the random
#' covariance.
#'
#' When \code{nrand} is greater than 0 a couple of attributes
#' is added:
#'
#' - \code{rcovls} a numeric matrix containing the estimation
#' of the mean of the random covariance.
#'
#' - \code{p.value} a numeric matrix containing the estimations
#' of the p.values of tests checking that the observed
#' covariance is larger than the mean of the random covariance.
#' p.values are corrected for multiple tests according to the
#' method specified by the \code{p.adjust.method} parameter.
#' #'
#' @examples #' @examples
#' # Build Three matrices of 3 rows. #' # Build Three matrices of 3 rows.
...@@ -60,6 +102,8 @@ registerDoParallel(1) ...@@ -60,6 +102,8 @@ registerDoParallel(1)
#' # compute the variance covariance matrix #' # compute 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)
#' varls(data)
#' @author Eric Coissac #' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima #' @author Christelle Gonindard-Melodelima
#' @export #' @export
......
#' @docType package
#' @importFrom Rdpack reprompt
NULL
...@@ -238,7 +238,7 @@ procmod.frame <- function(..., ...@@ -238,7 +238,7 @@ procmod.frame <- function(...,
.siteNames(value[[i]]) <- NULL .siteNames(value[[i]]) <- NULL
} }
return(make_subS3Class(value, "procmod.frame")) make_subS3Class(value, "procmod.frame")
} }
#' #'
...@@ -386,7 +386,8 @@ dim.procmod.frame <- function(x) ...@@ -386,7 +386,8 @@ dim.procmod.frame <- function(x)
#' @export #' @export
`$<-.procmod.frame` <- function(x, name, value) { `$<-.procmod.frame` <- function(x, name, value) {
x[[name]] <- value x[[name]] <- value
return(x)
x
} }
#' @author Eric Coissac #' @author Eric Coissac
...@@ -437,7 +438,7 @@ dim.procmod.frame <- function(x) ...@@ -437,7 +438,7 @@ dim.procmod.frame <- function(x)
attr(y, "row.names") <- rownames(y[[1]]) attr(y, "row.names") <- rownames(y[[1]])
} }
return(y) y
} }
#' @author Eric Coissac #' @author Eric Coissac
...@@ -469,5 +470,6 @@ subset.procmod.frame <- function(x, subset, select, drop = FALSE, ...) { ...@@ -469,5 +470,6 @@ subset.procmod.frame <- function(x, subset, select, drop = FALSE, ...) {
#' @export #' @export
as.list.procmod.frame <- function(x, ...) { as.list.procmod.frame <- function(x, ...) {
class(x) <- "list" class(x) <- "list"
return(x)
x
} }
...@@ -11,7 +11,7 @@ NULL ...@@ -11,7 +11,7 @@ NULL
#' #'
#' The optimal rotation is computed according to the procruste methode. #' The optimal rotation is computed according to the procruste methode.
#' Rotation is based on singular value decomposition (SVD). #' Rotation is based on singular value decomposition (SVD).
#' No scaling is done, only the rotation. #' No scaling and no centrering are done, before computing the SVD.
#' #'
#' @param src a numeric matrix to be rotated #' @param src a numeric matrix to be rotated
#' @param dest a numeric matrix used as reference space #' @param dest a numeric matrix used as reference space
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
%% http://bibdesk.sourceforge.net/ %% http://bibdesk.sourceforge.net/
%% Created for Eric Coissac at 2019-07-12 16:37:23 +0200 %% Created for Eric Coissac at 2019-08-19 09:13:32 +0200
%% Saved with string encoding Unicode (UTF-8) %% Saved with string encoding Unicode (UTF-8)
...@@ -15,7 +15,15 @@ ...@@ -15,7 +15,15 @@
@inbook{Theil:58:00, @article{Coissac-Eric:19:00,
Author = {Coissac, Eric and Gonindard-Melodelima, Christelle},
Date-Added = {2019-08-19 09:07:57 +0200},
Date-Modified = {2019-08-19 09:12:35 +0200},
Journal = {in prep},
Title = {Assessing the shared variation among high-dimensional data matrices: a modified version of the Procrustean correlation coefficient},
Year = {2019}}
@book{Theil:58:00,
Address = {Amsterdam}, Address = {Amsterdam},
Annote = {Le R2 ajuster de R Annote = {Le R2 ajuster de R
...@@ -24,7 +32,7 @@ http://www.sudoc.abes.fr/xslt/DB=2.1//SRCH?IKT=12&TRM=005519756 ...@@ -24,7 +32,7 @@ http://www.sudoc.abes.fr/xslt/DB=2.1//SRCH?IKT=12&TRM=005519756
}, },
Author = {Theil, Henri, and Cramer, Jan Salomon, and Moerman, H. and Russchen, A.}, Author = {Theil, Henri, and Cramer, Jan Salomon, and Moerman, H. and Russchen, A.},
Date-Added = {2019-07-11 15:10:21 +0200}, Date-Added = {2019-07-11 15:10:21 +0200},
Date-Modified = {2019-07-12 16:37:23 +0200}, Date-Modified = {2019-08-19 09:13:20 +0200},
Keywords = {Economics, Mathematical; Forecasting; Business}, Keywords = {Economics, Mathematical; Forecasting; Business},
Language = {en}, Language = {en},
Pages = {213}, Pages = {213},
......
...@@ -7,7 +7,14 @@ ...@@ -7,7 +7,14 @@
getPermuteMatrix(perm, n, strata = NULL) getPermuteMatrix(perm, n, strata = NULL)
} }
\arguments{ \arguments{
\item{strata}{The permutation schema is defined using the `how` function. \item{perm}{xxx}
\item{n}{zzz}
\item{strata}{eeee
The permutation schema is defined using the `how` function.
The implementation of this function is inspired The implementation of this function is inspired
from the VEGAN package and reproduced here to avoid an extra from the VEGAN package and reproduced here to avoid an extra
dependency on an hidden vegan function.} dependency on an hidden vegan function.}
......
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
the trace of X the trace of X
} }
\description{ \description{
Compute the trace of a square matrix. The trace of a square matrix is defined as the sum
of its diagonal elements.
} }
\note{ \note{
Internal function do not use. Internal function do not use.
......
...@@ -17,7 +17,7 @@ a numeric matrix ...@@ -17,7 +17,7 @@ a numeric matrix
\description{ \description{
The optimal rotation is computed according to the procruste methode. The optimal rotation is computed according to the procruste methode.
Rotation is based on singular value decomposition (SVD). Rotation is based on singular value decomposition (SVD).
No scaling is done, only the rotation. No scaling and no centrering are done, before computing the SVD.
} }
\examples{ \examples{
# Renerate a random matrix of size 10 x 15 # Renerate a random matrix of size 10 x 15
......
...@@ -2,27 +2,63 @@ ...@@ -2,27 +2,63 @@
% Please edit documentation in R/covls.R % Please edit documentation in R/covls.R
\name{varls} \name{varls}
\alias{varls} \alias{varls}
\title{Compute the variance, covariance matrix of K coordinate matrices.} \title{Compute the procrustean variance, covariance matrix of K matrices.}
\usage{ \usage{
varls(..., nrand = 100, p.adjust.method = "holm") varls(..., nrand = 100, p.adjust.method = "holm")
} }
\arguments{ \arguments{
\item{...}{the set of matrices} \item{...}{the set of matrices or a \code{\link[ProcMod]{procmod.frame}}
object.}
\item{nrand}{number of randomisation used to estimate the mean \item{nrand}{number of randomisation used to estimate the mean
covariance observed between two random matrix.} covariance observed between two random matrix.
If rand is \code{NULL} or equal to \code{0}, no correction
is estimated and the raw procrustean covariances are
estimated.}
\item{p.adjust.method}{the multiple test correction method used \item{p.adjust.method}{the multiple test correction method used
to adjust p values. \code{p.adjust.method} belongs to adjust p values. \code{\link[stats]{p.adjust.method}}
one of the folowing values: "holm", "hochberg", "hommel", belongsone of the folowing values: \code{"holm"},
"bonferroni", "BH", "BY", "fdr", "none". The default is \code{"hochberg"}, \code{"hommel"}, \code{"bonferroni"},
set to "holm".} \code{"BH"}, \code{"BY"}, \code{"fdr"}, \code{"none"}.
The default is,set to \code{"holm"}.}
}
\value{
a \code{procmod.varls} object which corresponds to a numeric
matrix annotated by several attributes.
The following attribute is always added:
- \code{nrand} an integer value indicating the number of
randomisations used to estimate the mean of the random
covariance.
When \code{nrand} is greater than 0 a couple of attributes
is added:
- \code{rcovls} a numeric matrix containing the estimation
of the mean of the random covariance.
- \code{p.value} a numeric matrix containing the estimations
of the p.values of tests checking that the observed
covariance is larger than the mean of the random covariance.
p.values are corrected for multiple tests according to the
method specified by the \code{p.adjust.method} parameter.
} }
\description{ \description{
Covariance between two matrices is defined as the sum of the Procrustean covariance between two matrices X and Y, is defined as the sum
sigular values of the X'Y matrix. All the matrices must have of the singular values of the X'Y matrix
\insertCite{Gower:71:00,Lingoes:74:00}{Rdpack}. Both the matrices must have
the same number of rows. the same number of rows.
} }
\details{
\code{varls} computes the variance covariance matrix of a set of matrices
following the above definition. The variances and covariances are corrected
to avoid over fitting \insertCite{Coissac-Eric:19:00}{Rdpack}. .
Before computing the covariances, matrices are projected into an
orthogonal space using the \code{\link[ProcMod]{ortho}} function.
}
\examples{ \examples{
# Build Three matrices of 3 rows. # Build Three matrices of 3 rows.
A <- matrix(1:9, nrow = 3) A <- matrix(1:9, nrow = 3)
...@@ -31,6 +67,17 @@ C <- matrix(20:31, nrow = 3) ...@@ -31,6 +67,17 @@ C <- matrix(20:31, nrow = 3)
# compute the variance covariance matrix # compute 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)
varls(data)
}
\references{
{
\insertRef{Gower:71:00}{ProcMod}
\insertRef{Lingoes:74:00}{ProcMod}
\insertRef{Coissac-Eric:19:00}{ProcMod}
}
} }
\author{ \author{
Eric Coissac Eric Coissac
......
\documentclass{bioinfo} \IfFileExists{bioinfo.cls}{%
\copyrightyear{2015} \pubyear{2015} \def\mode{0}%
}{%
\def\mode{1}%
}
\access{Advance Access Publication Date: Day Month Year} \if 0\mode
\appnotes{Manuscript Category} \documentclass{bioinfo}%
\copyrightyear{2015} \pubyear{2015}%
\access{Advance Access Publication Date: Day Month Year}%
\appnotes{Manuscript Category}%
\else
\documentclass{article}%
\newcommand\firstpage[1]{}
\newcommand\subtitle[1]{}
\fi
\usepackage{amsmath} \usepackage{amsmath}
\usepackage{multirow} \usepackage{multirow}
...@@ -29,6 +40,7 @@ ...@@ -29,6 +40,7 @@
\newcommand{\Y}{\mathbf{Y}} \newcommand{\Y}{\mathbf{Y}}
\begin{document} \begin{document}
\firstpage{1} \firstpage{1}
\subtitle{Data and text mining} \subtitle{Data and text mining}
...@@ -1304,7 +1316,7 @@ This work has been supported by the... Text Text Text Text. ...@@ -1304,7 +1316,7 @@ This work has been supported by the... Text Text Text Text.
% %
%\bibliographystyle{plain} %\bibliographystyle{plain}
% %
\bibliography{Document} \bibliography{../inst/REFERENCES}
\renewcommand\thesubsection{\Alph{subsection}} \renewcommand\thesubsection{\Alph{subsection}}
......
No preview for this file type
\documentclass{bioinfo}\usepackage[]{graphicx}\usepackage[]{color} \IfFileExists{bioinfo.cls}{%
\def\mode{0}%
}{%
\def\mode{1}%
}
\if 0\mode
\documentclass{bioinfo}\usepackage[]{graphicx}\usepackage[]{color}
% maxwidth is the original width if it is less than linewidth % maxwidth is the original width if it is less than linewidth
% otherwise use linewidth (to make sure the graphics do not exceed the margin) % otherwise use linewidth (to make sure the graphics do not exceed the margin)
\makeatletter \makeatletter
...@@ -48,11 +55,15 @@ ...@@ -48,11 +55,15 @@
\definecolor{errorcolor}{rgb}{1, 0, 0} \definecolor{errorcolor}{rgb}{1, 0, 0}
\newenvironment{knitrout}{}{} % an empty environment to be redefined in TeX \newenvironment{knitrout}{}{} % an empty environment to be redefined in TeX
\usepackage{alltt} \usepackage{alltt}%
\copyrightyear{2015} \pubyear{2015} \copyrightyear{2015} \pubyear{2015}%
\access{Advance Access Publication Date: Day Month Year}%
\access{Advance Access Publication Date: Day Month Year} \appnotes{Manuscript Category}%
\appnotes{Manuscript Category} \else
\documentclass{article}%
\newcommand\firstpage[1]{}
\newcommand\subtitle[1]{}
\fi
\usepackage{amsmath} \usepackage{amsmath}
\usepackage{multirow} \usepackage{multirow}
...@@ -79,6 +90,7 @@ ...@@ -79,6 +90,7 @@
\newcommand{\Y}{\mathbf{Y}} \newcommand{\Y}{\mathbf{Y}}
\IfFileExists{upquote.sty}{\usepackage{upquote}}{} \IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\begin{document} \begin{document}
\firstpage{1} \firstpage{1}
\subtitle{Data and text mining} \subtitle{Data and text mining}
...@@ -341,7 +353,7 @@ To evaluate relative power of the three considered tests, pairs of to random mat ...@@ -341,7 +353,7 @@ To evaluate relative power of the three considered tests, pairs of to random mat
\begin{table}[!t] \begin{table}[!t]
\processtable{Estimation of $\overline{\rcovls(\X,\Y)}$ according to the number of random matrices (k) aligned.\label{tab:mrcovls}}{ \processtable{Estimation of $\overline{\rcovls(\X,\Y)}$ according to the number of random matrices (k) aligned.\label{tab:mrcovls}}{
% latex table generated in R 3.5.2 by xtable 1.8-4 package % latex table generated in R 3.5.2 by xtable 1.8-4 package
% Fri Jul 12 17:51:46 2019 % Wed Aug 21 09:31:39 2019
\begin{tabular}{rrrrrrr} \begin{tabular}{rrrrrrr}
\hline \hline
& & \multicolumn{2}{c}{normal} & & \multicolumn{2}{c}{exponential}\\ \cline{3-4} \cline{6-7}p & k &\multicolumn{1}{c}{mean} & \multicolumn{1}{c}{sd} & \multicolumn{1}{c}{ } &\multicolumn{1}{c}{mean} & \multicolumn{1}{c}{sd}\\\hline\multirow{3}{*}{10} & 10 & 0.5746 & $1.3687 \times 10^{-2}$ & & 0.5705 & $1.1714 \times 10^{-2}$ \\ & & \multicolumn{2}{c}{normal} & & \multicolumn{2}{c}{exponential}\\ \cline{3-4} \cline{6-7}p & k &\multicolumn{1}{c}{mean} & \multicolumn{1}{c}{sd} & \multicolumn{1}{c}{ } &\multicolumn{1}{c}{mean} & \multicolumn{1}{c}{sd}\\\hline\multirow{3}{*}{10} & 10 & 0.5746 & $1.3687 \times 10^{-2}$ & & 0.5705 & $1.1714 \times 10^{-2}$ \\
...@@ -443,7 +455,7 @@ whatever the $p$ tested (Table~\ref{tab:alpha_pvalue}). This ensure that the pro ...@@ -443,7 +455,7 @@ whatever the $p$ tested (Table~\ref{tab:alpha_pvalue}). This ensure that the pro
of the distribution of $P_{values}$ correlation test to $\mathcal{U}(0,1)$ of the distribution of $P_{values}$ correlation test to $\mathcal{U}(0,1)$
under the null hypothesis.\label{tab:alpha_pvalue}} { under the null hypothesis.\label{tab:alpha_pvalue}} {
% latex table generated in R 3.5.2 by xtable 1.8-4 package % latex table generated in R 3.5.2 by xtable 1.8-4 package
% Fri Jul 12 17:51:49 2019 % Wed Aug 21 09:31:44 2019
\begin{tabular*}{0.98\linewidth}{@{\extracolsep{\fill}}crrr} \begin{tabular*}{0.98\linewidth}{@{\extracolsep{\fill}}crrr}
\hline \hline
& \multicolumn{3}{c}{Cramer-Von Mises p.value} \\ & \multicolumn{3}{c}{Cramer-Von Mises p.value} \\
...@@ -465,7 +477,7 @@ Power of the $CovLs$ test based on the estimation of $\overline{RCovLs(X,Y)}$ is ...@@ -465,7 +477,7 @@ Power of the $CovLs$ test based on the estimation of $\overline{RCovLs(X,Y)}$ is
\begin{table}[!t] \begin{table}[!t]
\processtable{Power estimation of the procruste tests for two low level of shared variations $5\%$ and $10\%$.\label{tab:power}} { \processtable{Power estimation of the procruste tests for two low level of shared variations $5\%$ and $10\%$.\label{tab:power}} {
% latex table generated in R 3.5.2 by xtable 1.8-4 package % latex table generated in R 3.5.2 by xtable 1.8-4 package
% Fri Jul 12 17:51:49 2019 % Wed Aug 21 09:31:44 2019
\begin{tabular}{lcrrrrrrrrr} \begin{tabular}{lcrrrrrrrrr}
\hline \hline
& $R^2$ & \multicolumn{4}{c}{5\%} & &\multicolumn{4}{c}{10\%} \\ & $R^2$ & \multicolumn{4}{c}{5\%} & &\multicolumn{4}{c}{10\%} \\
...@@ -550,7 +562,7 @@ This work has been supported by the... Text Text Text Text. ...@@ -550,7 +562,7 @@ This work has been supported by the... Text Text Text Text.
% %
%\bibliographystyle{plain} %\bibliographystyle{plain}
% %
\bibliography{Document} \bibliography{../inst/REFERENCES}
\renewcommand\thesubsection{\Alph{subsection}} \renewcommand\thesubsection{\Alph{subsection}}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment