Commit 1a01681c by Eric Coissac

End of the RV2 trial branche

parent 44b6d649
......@@ -31,4 +31,5 @@ Collate:
'covv.R'
'plot.pm.R'
'procuste.R'
'rls.R'
'zzzz.R'
......@@ -32,6 +32,8 @@ S3method(residuals,pm)
S3method(subset,multivariate.data.frame)
export(as.multivariate.data.frame)
export(bicenter)
export(covls)
export(covls2)
export(covv)
export(covv2)
export(is.euclid)
......@@ -46,6 +48,10 @@ export(pcoa)
export(pm)
export(project)
export(protate)
export(rls)
export(rls.partial)
export(rls2)
export(rls2.partial)
export(rv)
export(rv.partial)
export(rv2)
......
......@@ -27,8 +27,7 @@ NULL
return(XX)
}
..covv = function(...,
tcrossprod=..tcrossprod) {
..covv = function(...,tcp) {
Xs <- list(...)
if (length(Xs)==1) {
......@@ -46,7 +45,7 @@ NULL
Xnames=names(Xs)
Xs <- project(Xs)
Xs <- as.multivariate.data.frame(mapply(tcrossprod,
Xs <- as.multivariate.data.frame(mapply(tcp,
Xs,
SIMPLIFY = FALSE))
......@@ -55,11 +54,11 @@ NULL
Xx <- rep(1:nX,nX)
Xy <- rep(1:nX,rep(nX,nX))
n <- nrow(Xs)-1
n <- nrow(Xs)
CovXXs <- mapply(function(x,y) sum(Xs[[x]] * Xs[[y]]),
Xx,Xy,
SIMPLIFY = TRUE) / n
SIMPLIFY = TRUE) / (n-1)
dim(CovXXs)=c(nX,nX)
......@@ -69,17 +68,17 @@ NULL
return(CovXXs)
}
..rv = function(...,covv=covv) {
cov = covv(...)
s = sqrt(diag(cov))
vv= outer(s,s)
return(cov/vv)
..rv = function(...,cov) {
COV = cov(...)
s = sqrt(diag(COV))
VV= outer(s,s)
return(COV/VV)
}
..rv.partial = function(...,rv=..rv) {
C = solve(rv(...))
..rv.partial = function(...,r) {
C = solve(sqrt(r(...)))
D = sqrt(diag(C) %o% diag(C))
return(C/D)
return((C/D)^2)
}
......@@ -103,7 +102,7 @@ NULL
#' @author Eric Coissac & Christelle Gonindard-Melodelima
#' @export
covv = function(...) {
..covv(...,tcrossprod = ..tcrossprod)
..covv(...,tcp = ..tcrossprod)
}
......@@ -127,7 +126,7 @@ covv = function(...) {
#' @author Eric Coissac & Christelle Gonindard-Melodelima
#' @export
covv2 = function(...) {
..covv(...,tcrossprod = ..tcrossprod_diag0)
..covv(...,tcp = ..tcrossprod_diag0)
}
#' Compute RV coefficient matrix of K coordinate matrices.
......@@ -138,7 +137,7 @@ covv2 = function(...) {
#' @author Christelle Gonindard-Melodelima
#' @export
rv = function(...) {
..rv(...,covv=covv)
..rv(...,cov = covv)
}
#' Compute RV2 coefficient matrix of K coordinate matrices.
......@@ -149,7 +148,7 @@ rv = function(...) {
#' @author Christelle Gonindard-Melodelima
#' @export
rv2 = function(...) {
..rv(...,covv=covv2)
..rv(...,cov = covv2)
}
......@@ -159,7 +158,7 @@ rv2 = function(...) {
#' @author Christelle Gonindard-Melodelima
#' @export
rv.partial = function(...) {
..rv.partial(...,rv=rv)
..rv.partial(...,r=rv)
}
#' Compute the RV2 partial correlation matrix of K coordinate matrices
......@@ -168,7 +167,7 @@ rv.partial = function(...) {
#' @author Christelle Gonindard-Melodelima
#' @export
rv2.partial = function(...) {
..rv.partial(...,rv=rv2)
..rv.partial(...,r=rv2)
}
......@@ -108,7 +108,7 @@ pm = function (formula,data, subset, weights, na.action, method = "qr",
nvars=ncol(vars)
irep = attr(vars,"response")
data.cov = mvar(vars)
data.cov = covv2(vars)
variances= diag(data.cov)
std.dev = sqrt(variances)
......@@ -130,7 +130,7 @@ pm = function (formula,data, subset, weights, na.action, method = "qr",
vars.norm = vars.norm[subset.w,]
}
data.cov = mvar(vars.norm)
data.cov = covv2(vars.norm)
z = pm.fit(data.cov,
y = irep, xs = seq_len(nvars)!=irep,
......
#' @include multivariate.data.frame.R
#' @include multivariate.R
#' @include covv.R
#'
NULL
..trace = function(X) sum(diag(X))
..covls = function(...,tcp) {
Xs <- list(...)
if (length(Xs)==1) {
x = Xs[[1]]
if (is.multivariate.data.frame(x))
Xs=x
else if (is.pm(x))
return(x$cov)
else
Xs=multivariate.data.frame(x)
}
else
Xs=as.multivariate.data.frame(Xs)
Xnames=names(Xs)
Xs <- project(Xs)
Xs <- as.multivariate.data.frame(mapply(tcp,
Xs,
SIMPLIFY = FALSE))
nX <- length(Xs)
Xx <- rep(1:nX,nX)
Xy <- rep(1:nX,rep(nX,nX))
n <- nrow(Xs)-1
CovXXs <- mapply(function(x,y) ..trace(sqrtm(Xs[[x]] %*% Xs[y])),
Xx,Xy,
SIMPLIFY = TRUE) / n
dim(CovXXs)=c(nX,nX)
colnames(CovXXs)=Xnames
rownames(CovXXs)=Xnames
return(CovXXs)
}
..rls = function(...,cov) {
COV = cov(...)
s = sqrt(diag(COV))
VV= outer(s,s)
return(COV/VV)
}
..rls.partial = function(...,r) {
C = solve(r(...))
D = sqrt(diag(C) %o% diag(C))
return(C/D)
}
#' Compute the variance, covariance matrix of K coordinate matrices.
#'
#' Covariance between two matrices is defined as the sum of the
#' sigular values of the X'Y matrix. All the matrices must have
#' the same number of rows.
#'
#' @param ... the set of matrices
#'
#' @examples
#' # Build Three matrices of 3 rows.
#' A <- matrix(1:9,nrow=3)
#' B <- matrix(10:15,nrow=3)
#' C <- matrix(20:31,nrow=3)
#' # compute the variance covariance matrix
#' covls(A,B,C)
#' covls(A=A,B=B,C=C)
#'
#' @author Eric Coissac & Christelle Gonindard-Melodelima
#' @export
covls = function(...) {
..covls(...,tcp = ..tcrossprod)
}
#' Compute the variance, covariance matrix of K coordinate matrices.
#'
#' Covariance between two matrices is defined as the sum of the
#' sigular values of the X'Y matrix. All the matrices must have
#' the same number of rows.
#'
#' @param ... the set of matrices
#'
#' @examples
#' # Build Three matrices of 3 rows.
#' A <- matrix(1:9,nrow=3)
#' B <- matrix(10:15,nrow=3)
#' C <- matrix(20:31,nrow=3)
#' # compute the variance covariance matrix
#' covls2(A,B,C)
#' covls2(A=A,B=B,C=C)
#'
#' @author Eric Coissac & Christelle Gonindard-Melodelima
#' @export
covls2 = function(...) {
..covls(...,tcp = ..tcrossprod_diag0)
}
#' Compute RV coefficient matrix of K coordinate matrices.
#'
#'
#'
#' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima
#' @export
rls = function(...) {
..rls(...,cov=covls)
}
#' Compute RV2 coefficient matrix of K coordinate matrices.
#'
#'
#'
#' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima
#' @export
rls2 = function(...) {
..rls(...,cov=covls2)
}
#' Compute the RV2 partial correlation matrix of K coordinate matrices
#'
#' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima
#' @export
rls.partial = function(...) {
..rls.partial(...,r=rls)
}
#' Compute the RV2 partial correlation matrix of K coordinate matrices
#'
#' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima
#' @export
rls2.partial = function(...) {
..rls.partial(...,r=rls2)
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/rls.R
\name{covls}
\alias{covls}
\title{Compute the variance, covariance matrix of K coordinate matrices.}
\usage{
covls(...)
}
\arguments{
\item{...}{the set of matrices}
}
\description{
Covariance between two matrices is defined as the sum of the
sigular values of the X'Y matrix. All the matrices must have
the same number of rows.
}
\examples{
# Build Three matrices of 3 rows.
A <- matrix(1:9,nrow=3)
B <- matrix(10:15,nrow=3)
C <- matrix(20:31,nrow=3)
# compute the variance covariance matrix
covls(A,B,C)
covls(A=A,B=B,C=C)
}
\author{
Eric Coissac & Christelle Gonindard-Melodelima
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/rls.R
\name{covls2}
\alias{covls2}
\title{Compute the variance, covariance matrix of K coordinate matrices.}
\usage{
covls2(...)
}
\arguments{
\item{...}{the set of matrices}
}
\description{
Covariance between two matrices is defined as the sum of the
sigular values of the X'Y matrix. All the matrices must have
the same number of rows.
}
\examples{
# Build Three matrices of 3 rows.
A <- matrix(1:9,nrow=3)
B <- matrix(10:15,nrow=3)
C <- matrix(20:31,nrow=3)
# compute the variance covariance matrix
covls2(A,B,C)
covls2(A=A,B=B,C=C)
}
\author{
Eric Coissac & Christelle Gonindard-Melodelima
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/rls.R
\name{rls}
\alias{rls}
\title{Compute RV coefficient matrix of K coordinate matrices.}
\usage{
rls(...)
}
\description{
Compute RV coefficient matrix of K coordinate matrices.
}
\author{
Eric Coissac
Christelle Gonindard-Melodelima
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/rls.R
\name{rls.partial}
\alias{rls.partial}
\title{Compute the RV2 partial correlation matrix of K coordinate matrices}
\usage{
rls.partial(...)
}
\description{
Compute the RV2 partial correlation matrix of K coordinate matrices
}
\author{
Eric Coissac
Christelle Gonindard-Melodelima
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/rls.R
\name{rls2}
\alias{rls2}
\title{Compute RV2 coefficient matrix of K coordinate matrices.}
\usage{
rls2(...)
}
\description{
Compute RV2 coefficient matrix of K coordinate matrices.
}
\author{
Eric Coissac
Christelle Gonindard-Melodelima
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/rls.R
\name{rls2.partial}
\alias{rls2.partial}
\title{Compute the RV2 partial correlation matrix of K coordinate matrices}
\usage{
rls2.partial(...)
}
\description{
Compute the RV2 partial correlation matrix of K coordinate matrices
}
\author{
Eric Coissac
Christelle Gonindard-Melodelima
}
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