Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
ProcMod
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LECASofts
ProcMod
Commits
e60a0810
Commit
e60a0810
authored
Jun 12, 2018
by
Eric Coissac
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add of the mcor.partial function estimating the partial correlation coeficients matrix
parent
44d6a669
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
0 deletions
+85
-0
mcov.R
R/mcov.R
+85
-0
No files found.
R/mcov.R
0 → 100644
View file @
e60a0810
#' @include procmod.frame.R
#'
NULL
#' 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
#' mvar(A,B,C)
#' mvar(A=A,B=B,C=C)
#'
#' @author Eric Coissac & Christelle Gonindard-Melodelima
#' @export
mvar
=
function
(
...
)
{
Xs
<-
list
(
...
)
if
(
length
(
Xs
)
==
1
)
if
(
is.list
(
Xs
[[
1
]]))
Xs
=
as.procmod.frame
(
Xs
[[
1
]])
else
if
(
is.procmod.frame
(
Xs
[[
1
]]))
Xs
=
Xs
[[
1
]]
else
Xs
=
procmod.frame
(
Xs
[[
1
]])
else
Xs
=
as.procmod.frame
(
Xs
)
Xnames
=
names
(
Xs
)
Xs
<-
lapply
(
Xs
,
scale
,
scale
=
FALSE
)
nX
=
length
(
Xs
)
Xx
<-
rep
(
1
:
nX
,
nX
)
Xy
<-
rep
(
1
:
nX
,
rep
(
nX
,
nX
))
XXs
<-
mapply
(
function
(
x
,
y
)
crossprod
(
Xs
[[
x
]],
Xs
[[
y
]]),
Xx
,
Xy
,
SIMPLIFY
=
FALSE
)
sol_xxs
<-
lapply
(
XXs
,
svd
)
CovXXs
=
sapply
(
sol_xxs
,
function
(
sol
)
sum
(
sol
$
d
))
dim
(
CovXXs
)
=
c
(
nX
,
nX
)
colnames
(
CovXXs
)
=
Xnames
rownames
(
CovXXs
)
=
Xnames
return
(
CovXXs
)
}
#' Compute the person correlation matrix of K coordinate matrices
#'
#' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima
#' @export
mcor
=
function
(
...
)
{
cov
=
mvar
(
...
)
s
=
sqrt
(
diag
(
cov
))
vv
=
outer
(
s
,
s
)
return
(
cov
/
vv
)
}
#' Compute the person partial correlation matrix of K coordinate matrices
#'
#' @author Eric Coissac
#' @author Christelle Gonindard-Melodelima
#' @export
mcor.partial
=
function
(
...
)
{
C
=
solve
(
mcor
(
...
))
D
=
sqrt
(
diag
(
C
)
%o%
diag
(
C
))
return
(
C
/
D
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment