Discussion:
[R-sig-phylo] No PCOA Correction Applied but Corrected Eigenvalues Returned? (ape::pcoa)
David Bapst
2018-10-23 15:11:34 UTC
Permalink
Hi all,

Not exactly phylogenetic, but I've recently uncovered some odd behavior
with `pcoa` in `ape` and I was curious if anyone understood what was going
on.

Usually, if you don't have negative eigenvalues and aren't using a
correction, `pcoa` will return the raw eigenvalues. However, I've found if
there are negative eigenvalues and no correction is used, even though no
correction is applied, the function will still return some corrected
relative eigenvalues, and cumulative corrected eigenvalues. What correction
was used in this case is not clear.

Here's some output using an example dataset from paleotree to demonstrate
the weirdness, both without correction argument specified and with it
specified as "none".

```
library(ape)
library(paleotree)
data(graptDisparity)
dmat<-graptDistMat
res<-pcoa(dmat)
str(res)
List of 5
$ correction: chr [1:2] "none" "1"
$ note : chr "No correction was applied to the negative eigenvalues"
$ values :'data.frame': 183 obs. of 6 variables:
..$ Eigenvalues : num [1:183] 3.22 2.72 1.9 1.74 1.41 ...
..$ Relative_eig : num [1:183] 0.217 0.183 0.128 0.117 0.095 ...
..$ Rel_corr_eig : num [1:183] 0.0495 0.0424 0.031 0.0287 0.0241 ...
..$ Broken_stick : num [1:183] 0.0319 0.0264 0.0236 0.0218 0.0204 ...
..$ Cum_corr_eig : num [1:183] 0.0495 0.0919 0.1229 0.1517 0.1758 ...
..$ Cumul_br_stick: num [1:183] 0.0319 0.0583 0.082 0.1038 0.1242 ...
$ vectors : num [1:183, 1:72] 0.0143 -0.1818 -0.1011 0.104 0.101 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:183] "'Bulmanograptus' macilentus" "'Monograptus'
arciformis" "'Monograptus' austerus" "'Paramplexograptus' kiliani" ...
.. ..$ : chr [1:72] "Axis.1" "Axis.2" "Axis.3" "Axis.4" ...
$ trace : num 14.8
- attr(*, "class")= chr "pcoa"
data(graptDisparity)
dmat<-graptDistMat
res<-pcoa(dmat,correction="none")
str(res)
List of 5
$ correction: chr [1:2] "none" "1"
$ note : chr "No correction was applied to the negative eigenvalues"
$ values :'data.frame': 183 obs. of 6 variables:
..$ Eigenvalues : num [1:183] 3.22 2.72 1.9 1.74 1.41 ...
..$ Relative_eig : num [1:183] 0.217 0.183 0.128 0.117 0.095 ...
..$ Rel_corr_eig : num [1:183] 0.0495 0.0424 0.031 0.0287 0.0241 ...
..$ Broken_stick : num [1:183] 0.0319 0.0264 0.0236 0.0218 0.0204 ...
..$ Cum_corr_eig : num [1:183] 0.0495 0.0919 0.1229 0.1517 0.1758 ...
..$ Cumul_br_stick: num [1:183] 0.0319 0.0583 0.082 0.1038 0.1242 ...
$ vectors : num [1:183, 1:72] 0.0143 -0.1818 -0.1011 0.104 0.101 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:183] "'Bulmanograptus' macilentus" "'Monograptus'
arciformis" "'Monograptus' austerus" "'Paramplexograptus' kiliani" ...
.. ..$ : chr [1:72] "Axis.1" "Axis.2" "Axis.3" "Axis.4" ...
$ trace : num 14.8
- attr(*, "class")= chr "pcoa"
```

Obviously if there are negative eigenvalues, a correction should probably
be applied (although perhaps this is a bit of a philosophical matter), but
still its unclear why the corrected eigenvalues are calculated, or how they
are calculated. They are clearly different from the uncorrected values.

Cheers,
-Dave Bapst
--
David W. Bapst, PhD
Asst Research Professor, Geology & Geophysics, Texas A & M University
Postdoc, Ecology & Evolutionary Biology, Univ of Tenn Knoxville
https://github.com/dwbapst/paleotree

[[alternative HTML version deleted]]

_______________________________________________
R-sig-phylo mailing list - R-sig-***@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/r-sig-***@r-project.org/
Emmanuel Paradis
2018-10-24 03:26:22 UTC
Permalink
Hi David,

Have you tried one of the two possible corrections?

R> res <- pcoa(dmat)
R> res.lingoes <- pcoa(dmat, correction = "lingoes")
R> res.lingoes$note
[1] "Lingoes correction applied to negative eigenvalues: D' = -0.5*D^2 -
0.310850908498892 , except diagonal elements"

The matrix $values of the output is different and contains the corrected
eigenvalues in the second analysis:

R> names(res$values)
[1] "Eigenvalues" "Relative_eig" "Rel_corr_eig" "Broken_stick"
[5] "Cum_corr_eig" "Cumul_br_stick"
R> names(res.lingoes$values)
[1] "Eigenvalues" "Corr_eig" "Rel_corr_eig" "Broken_stick"
[5] "Cum_corr_eig" "Cum_br_stick"
R> any(res.lingoes$values$Corr_eig < 0)
[1] FALSE

Best,

Emmanuel
Post by David Bapst
Hi all,
Not exactly phylogenetic, but I've recently uncovered some odd behavior
with `pcoa` in `ape` and I was curious if anyone understood what was
going on.
Usually, if you don't have negative eigenvalues and aren't using a
correction, `pcoa` will return the raw eigenvalues. However, I've found
if there are negative eigenvalues and no correction is used, even though
no correction is applied, the function will still return some corrected
relative eigenvalues, and cumulative corrected eigenvalues. What
correction was used in this case is not clear.
Here's some output using an example dataset from paleotree to
demonstrate the weirdness, both without correction argument specified
and with it specified as "none".
```
library(ape)
library(paleotree)
data(graptDisparity)
dmat<-graptDistMat
res<-pcoa(dmat)
str(res)
List of 5
 $ correction: chr [1:2] "none" "1"
 $ note      : chr "No correction was applied to the negative eigenvalues"
  ..$ Eigenvalues   : num [1:183] 3.22 2.72 1.9 1.74 1.41 ...
  ..$ Relative_eig  : num [1:183] 0.217 0.183 0.128 0.117 0.095 ...
  ..$ Rel_corr_eig  : num [1:183] 0.0495 0.0424 0.031 0.0287 0.0241 ...
  ..$ Broken_stick  : num [1:183] 0.0319 0.0264 0.0236 0.0218 0.0204 ...
  ..$ Cum_corr_eig  : num [1:183] 0.0495 0.0919 0.1229 0.1517 0.1758 ...
  ..$ Cumul_br_stick: num [1:183] 0.0319 0.0583 0.082 0.1038 0.1242 ...
 $ vectors   : num [1:183, 1:72] 0.0143 -0.1818 -0.1011 0.104 0.101 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:183] "'Bulmanograptus' macilentus" "'Monograptus'
arciformis" "'Monograptus' austerus" "'Paramplexograptus' kiliani" ...
  .. ..$ : chr [1:72] "Axis.1" "Axis.2" "Axis.3" "Axis.4" ...
 $ trace     : num 14.8
 - attr(*, "class")= chr "pcoa"
data(graptDisparity)
dmat<-graptDistMat
res<-pcoa(dmat,correction="none")
str(res)
List of 5
 $ correction: chr [1:2] "none" "1"
 $ note      : chr "No correction was applied to the negative eigenvalues"
  ..$ Eigenvalues   : num [1:183] 3.22 2.72 1.9 1.74 1.41 ...
  ..$ Relative_eig  : num [1:183] 0.217 0.183 0.128 0.117 0.095 ...
  ..$ Rel_corr_eig  : num [1:183] 0.0495 0.0424 0.031 0.0287 0.0241 ...
  ..$ Broken_stick  : num [1:183] 0.0319 0.0264 0.0236 0.0218 0.0204 ...
  ..$ Cum_corr_eig  : num [1:183] 0.0495 0.0919 0.1229 0.1517 0.1758 ...
  ..$ Cumul_br_stick: num [1:183] 0.0319 0.0583 0.082 0.1038 0.1242 ...
 $ vectors   : num [1:183, 1:72] 0.0143 -0.1818 -0.1011 0.104 0.101 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:183] "'Bulmanograptus' macilentus" "'Monograptus'
arciformis" "'Monograptus' austerus" "'Paramplexograptus' kiliani" ...
  .. ..$ : chr [1:72] "Axis.1" "Axis.2" "Axis.3" "Axis.4" ...
 $ trace     : num 14.8
 - attr(*, "class")= chr "pcoa"
```
Obviously if there are negative eigenvalues, a correction should
probably be applied (although perhaps this is a bit of a philosophical
matter), but still its unclear why the corrected eigenvalues are
calculated, or how they are calculated. They are clearly different from
the uncorrected values.
Cheers,
-Dave Bapst
--
David W. Bapst, PhD
Asst Research Professor, Geology & Geophysics, Texas A & M University
Postdoc, Ecology & Evolutionary Biology, Univ of Tenn Knoxville
https://github.com/dwbapst/paleotree
Pour nous remonter une erreur de filtrage, veuillez vous rendre ici
<http://f.security-mail.net/54A3Bt5hcV>
_______________________________________________
R-sig-phylo mailing list - R-sig-***@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/r-sig-***@r-project.org/
David Bapst
2018-10-24 21:07:09 UTC
Permalink
Emmanuel, I'm familiar with the two typical corrections. I'm just curious
why or what `pcoa` is reporting as ` "Rel_corr_eig"` when no correction is
defined by the user.
-Dave
Post by Emmanuel Paradis
Hi David,
Have you tried one of the two possible corrections?
R> res <- pcoa(dmat)
R> res.lingoes <- pcoa(dmat, correction = "lingoes")
R> res.lingoes$note
[1] "Lingoes correction applied to negative eigenvalues: D' = -0.5*D^2 -
0.310850908498892 , except diagonal elements"
The matrix $values of the output is different and contains the corrected
R> names(res$values)
[1] "Eigenvalues" "Relative_eig" "Rel_corr_eig" "Broken_stick"
[5] "Cum_corr_eig" "Cumul_br_stick"
R> names(res.lingoes$values)
[1] "Eigenvalues" "Corr_eig" "Rel_corr_eig" "Broken_stick"
[5] "Cum_corr_eig" "Cum_br_stick"
R> any(res.lingoes$values$Corr_eig < 0)
[1] FALSE
Best,
Emmanuel
Post by David Bapst
Hi all,
Not exactly phylogenetic, but I've recently uncovered some odd behavior
with `pcoa` in `ape` and I was curious if anyone understood what was
going on.
Usually, if you don't have negative eigenvalues and aren't using a
correction, `pcoa` will return the raw eigenvalues. However, I've found
if there are negative eigenvalues and no correction is used, even though
no correction is applied, the function will still return some corrected
relative eigenvalues, and cumulative corrected eigenvalues. What
correction was used in this case is not clear.
Here's some output using an example dataset from paleotree to
demonstrate the weirdness, both without correction argument specified
and with it specified as "none".
```
library(ape)
library(paleotree)
data(graptDisparity)
dmat<-graptDistMat
res<-pcoa(dmat)
str(res)
List of 5
$ correction: chr [1:2] "none" "1"
$ note : chr "No correction was applied to the negative
eigenvalues"
Post by David Bapst
..$ Eigenvalues : num [1:183] 3.22 2.72 1.9 1.74 1.41 ...
..$ Relative_eig : num [1:183] 0.217 0.183 0.128 0.117 0.095 ...
..$ Rel_corr_eig : num [1:183] 0.0495 0.0424 0.031 0.0287 0.0241 ...
..$ Broken_stick : num [1:183] 0.0319 0.0264 0.0236 0.0218 0.0204 ...
..$ Cum_corr_eig : num [1:183] 0.0495 0.0919 0.1229 0.1517 0.1758 ...
..$ Cumul_br_stick: num [1:183] 0.0319 0.0583 0.082 0.1038 0.1242 ...
$ vectors : num [1:183, 1:72] 0.0143 -0.1818 -0.1011 0.104 0.101 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:183] "'Bulmanograptus' macilentus" "'Monograptus'
arciformis" "'Monograptus' austerus" "'Paramplexograptus' kiliani" ...
.. ..$ : chr [1:72] "Axis.1" "Axis.2" "Axis.3" "Axis.4" ...
$ trace : num 14.8
- attr(*, "class")= chr "pcoa"
data(graptDisparity)
dmat<-graptDistMat
res<-pcoa(dmat,correction="none")
str(res)
List of 5
$ correction: chr [1:2] "none" "1"
$ note : chr "No correction was applied to the negative
eigenvalues"
Post by David Bapst
..$ Eigenvalues : num [1:183] 3.22 2.72 1.9 1.74 1.41 ...
..$ Relative_eig : num [1:183] 0.217 0.183 0.128 0.117 0.095 ...
..$ Rel_corr_eig : num [1:183] 0.0495 0.0424 0.031 0.0287 0.0241 ...
..$ Broken_stick : num [1:183] 0.0319 0.0264 0.0236 0.0218 0.0204 ...
..$ Cum_corr_eig : num [1:183] 0.0495 0.0919 0.1229 0.1517 0.1758 ...
..$ Cumul_br_stick: num [1:183] 0.0319 0.0583 0.082 0.1038 0.1242 ...
$ vectors : num [1:183, 1:72] 0.0143 -0.1818 -0.1011 0.104 0.101 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:183] "'Bulmanograptus' macilentus" "'Monograptus'
arciformis" "'Monograptus' austerus" "'Paramplexograptus' kiliani" ...
.. ..$ : chr [1:72] "Axis.1" "Axis.2" "Axis.3" "Axis.4" ...
$ trace : num 14.8
- attr(*, "class")= chr "pcoa"
```
Obviously if there are negative eigenvalues, a correction should
probably be applied (although perhaps this is a bit of a philosophical
matter), but still its unclear why the corrected eigenvalues are
calculated, or how they are calculated. They are clearly different from
the uncorrected values.
Cheers,
-Dave Bapst
--
David W. Bapst, PhD
Asst Research Professor, Geology & Geophysics, Texas A & M University
Postdoc, Ecology & Evolutionary Biology, Univ of Tenn Knoxville
https://github.com/dwbapst/paleotree
Pour nous remonter une erreur de filtrage, veuillez vous rendre ici
<http://f.security-mail.net/54A3Bt5hcV>
--
David W. Bapst, PhD
Asst Research Professor, Geology & Geophysics, Texas A & M University
Postdoc, Ecology & Evolutionary Biology, Univ of Tenn Knoxville
https://github.com/dwbapst/paleotree

[[alternative HTML version deleted]]

_______________________________________________
R-sig-phylo mailing list - R-sig-***@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/r-sig-***@r-project.org/
Emmanuel Paradis
2018-10-25 08:05:51 UTC
Permalink
From the code, a correction is made if some eigenvalues are negative
even if correction="none":

lambda = (lambda - min(lambda))/(tr(Delta) - (n - 1)*min(lambda))

lambda: vector of eigenvalues
Delta: the centered distance matrix

The help page refers to eq. 9.27 in Legendre & Legendre (1998). I'll
have a look it later and clarify the help page if needed.

Best,

Emmanuel
Post by David Bapst
Emmanuel, I'm familiar with the two typical corrections. I'm just
curious why or what `pcoa` is reporting as ` "Rel_corr_eig"` when no
correction is defined by the user.
-Dave
On Tue, Oct 23, 2018 at 10:26 PM Emmanuel Paradis
Hi David,
Have you tried one of the two possible corrections?
R> res <- pcoa(dmat)
R> res.lingoes <- pcoa(dmat, correction = "lingoes")
R> res.lingoes$note
[1] "Lingoes correction applied to negative eigenvalues: D' = -0.5*D^2 -
0.310850908498892 , except diagonal elements"
The matrix $values of the output is different and contains the corrected
R> names(res$values)
[1] "Eigenvalues"    "Relative_eig"   "Rel_corr_eig"   "Broken_stick"
[5] "Cum_corr_eig"   "Cumul_br_stick"
R> names(res.lingoes$values)
[1] "Eigenvalues"  "Corr_eig"     "Rel_corr_eig" "Broken_stick"
[5] "Cum_corr_eig" "Cum_br_stick"
R> any(res.lingoes$values$Corr_eig < 0)
[1] FALSE
Best,
Emmanuel
Post by David Bapst
Hi all,
Not exactly phylogenetic, but I've recently uncovered some odd
behavior
Post by David Bapst
with `pcoa` in `ape` and I was curious if anyone understood what was
going on.
Usually, if you don't have negative eigenvalues and aren't using a
correction, `pcoa` will return the raw eigenvalues. However, I've
found
Post by David Bapst
if there are negative eigenvalues and no correction is used, even
though
Post by David Bapst
no correction is applied, the function will still return some
corrected
Post by David Bapst
relative eigenvalues, and cumulative corrected eigenvalues. What
correction was used in this case is not clear.
Here's some output using an example dataset from paleotree to
demonstrate the weirdness, both without correction argument
specified
Post by David Bapst
and with it specified as "none".
```
  > library(ape)
  > library(paleotree)
  >
  > data(graptDisparity)
  > dmat<-graptDistMat
  > res<-pcoa(dmat)
  > str(res)
List of 5
   $ correction: chr [1:2] "none" "1"
   $ note      : chr "No correction was applied to the negative
eigenvalues"
Post by David Bapst
    ..$ Eigenvalues   : num [1:183] 3.22 2.72 1.9 1.74 1.41 ...
    ..$ Relative_eig  : num [1:183] 0.217 0.183 0.128 0.117 0.095 ...
    ..$ Rel_corr_eig  : num [1:183] 0.0495 0.0424 0.031 0.0287
0.0241 ...
Post by David Bapst
    ..$ Broken_stick  : num [1:183] 0.0319 0.0264 0.0236 0.0218
0.0204 ...
Post by David Bapst
    ..$ Cum_corr_eig  : num [1:183] 0.0495 0.0919 0.1229 0.1517
0.1758 ...
Post by David Bapst
    ..$ Cumul_br_stick: num [1:183] 0.0319 0.0583 0.082 0.1038
0.1242 ...
Post by David Bapst
   $ vectors   : num [1:183, 1:72] 0.0143 -0.1818 -0.1011 0.104
0.101 ...
Post by David Bapst
    ..- attr(*, "dimnames")=List of 2
    .. ..$ : chr [1:183] "'Bulmanograptus' macilentus" "'Monograptus'
arciformis" "'Monograptus' austerus" "'Paramplexograptus'
kiliani" ...
Post by David Bapst
    .. ..$ : chr [1:72] "Axis.1" "Axis.2" "Axis.3" "Axis.4" ...
   $ trace     : num 14.8
   - attr(*, "class")= chr "pcoa"
  >
  > data(graptDisparity)
  > dmat<-graptDistMat
  > res<-pcoa(dmat,correction="none")
  > str(res)
List of 5
   $ correction: chr [1:2] "none" "1"
   $ note      : chr "No correction was applied to the negative
eigenvalues"
Post by David Bapst
    ..$ Eigenvalues   : num [1:183] 3.22 2.72 1.9 1.74 1.41 ...
    ..$ Relative_eig  : num [1:183] 0.217 0.183 0.128 0.117 0.095 ...
    ..$ Rel_corr_eig  : num [1:183] 0.0495 0.0424 0.031 0.0287
0.0241 ...
Post by David Bapst
    ..$ Broken_stick  : num [1:183] 0.0319 0.0264 0.0236 0.0218
0.0204 ...
Post by David Bapst
    ..$ Cum_corr_eig  : num [1:183] 0.0495 0.0919 0.1229 0.1517
0.1758 ...
Post by David Bapst
    ..$ Cumul_br_stick: num [1:183] 0.0319 0.0583 0.082 0.1038
0.1242 ...
Post by David Bapst
   $ vectors   : num [1:183, 1:72] 0.0143 -0.1818 -0.1011 0.104
0.101 ...
Post by David Bapst
    ..- attr(*, "dimnames")=List of 2
    .. ..$ : chr [1:183] "'Bulmanograptus' macilentus" "'Monograptus'
arciformis" "'Monograptus' austerus" "'Paramplexograptus'
kiliani" ...
Post by David Bapst
    .. ..$ : chr [1:72] "Axis.1" "Axis.2" "Axis.3" "Axis.4" ...
   $ trace     : num 14.8
   - attr(*, "class")= chr "pcoa"
```
Obviously if there are negative eigenvalues, a correction should
probably be applied (although perhaps this is a bit of a
philosophical
Post by David Bapst
matter), but still its unclear why the corrected eigenvalues are
calculated, or how they are calculated. They are clearly
different from
Post by David Bapst
the uncorrected values.
Cheers,
-Dave Bapst
--
David W. Bapst, PhD
Asst Research Professor, Geology & Geophysics, Texas A & M University
Postdoc, Ecology & Evolutionary Biology, Univ of Tenn Knoxville
https://github.com/dwbapst/paleotree
Pour nous remonter une erreur de filtrage, veuillez vous rendre ici
<http://f.security-mail.net/54A3Bt5hcV>
--
David W. Bapst, PhD
Asst Research Professor, Geology & Geophysics, Texas A & M University
Postdoc, Ecology & Evolutionary Biology, Univ of Tenn Knoxville
https://github.com/dwbapst/paleotree
_______________________________________________
R-sig-phylo mailing list - R-sig-***@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/r-sig-***@r-project.org/
Loading...