From cf80ff9f6a5bb12bdf63f964ded2bcf8a7c72725 Mon Sep 17 00:00:00 2001
From: Eric Coissac
Date: Fri, 8 Feb 2019 10:45:55 +0100
Subject: [PATCH] Change names of the *.q functions to *_q
---
NAMESPACE | 12 +++----
R/entropy.R | 16 ++++-----
R/generalized_log.R | 4 +--
index.Rmd | 61 +++++++++++++++++++++++-----------
index.html | 68 ++++++++++++++++++++------------------
man/{exp.q.Rd => exp_q.Rd} | 6 ++--
man/{log.q.Rd => log_q.Rd} | 6 ++--
7 files changed, 100 insertions(+), 73 deletions(-)
rename man/{exp.q.Rd => exp_q.Rd} (80%)
rename man/{log.q.Rd => log_q.Rd} (84%)
diff --git a/NAMESPACE b/NAMESPACE
index f3e04da..835f9f3 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -1,11 +1,11 @@
# Generated by roxygen2: do not edit by hand
-S3method(exp,q)
-S3method(log,q)
-export(D.q)
-export(D.spectrum)
-export(H.q)
-export(H.spectrum)
+export(D_q)
+export(D_spectrum)
+export(H_q)
+export(H_spectrum)
+export(exp_q)
+export(log_q)
export(mode)
export(tag_bad_pcr)
importFrom(Rdpack,reprompt)
diff --git a/R/entropy.R b/R/entropy.R
index 581a85e..d662970 100644
--- a/R/entropy.R
+++ b/R/entropy.R
@@ -1,23 +1,23 @@
#' @author Eric Coissac
#' @export
-H.q = function(x,q=1) {
- sum(x * log.q(1/x,q),na.rm = TRUE)
+H_q = function(x,q=1) {
+ sum(x * log_q(1/x,q),na.rm = TRUE)
}
#' @author Eric Coissac
#' @export
-D.q = function(x,q=1) {
- exp.q(H.q(x,q),q)
+D_q = function(x,q=1) {
+ exp_q(H_q(x,q),q)
}
#' @author Eric Coissac
#' @export
-H.spectrum = function(x,q=1) {
- sapply(q,function(Q) H.q(x,Q))
+H_spectrum = function(x,q=1) {
+ sapply(q,function(Q) H_q(x,Q))
}
#' @author Eric Coissac
#' @export
-D.spectrum = function(x,q=1) {
- sapply(q,function(Q) D.q(x,Q))
+D_spectrum = function(x,q=1) {
+ sapply(q,function(Q) D_q(x,Q))
}
diff --git a/R/generalized_log.R b/R/generalized_log.R
index 7d5006a..982585b 100644
--- a/R/generalized_log.R
+++ b/R/generalized_log.R
@@ -13,7 +13,7 @@ NULL
#'
#' @author Eric Coissac
#' @export
-log.q = function(x,q=1) {
+log_q = function(x,q=1) {
if (q==1)
log(x)
else (x^(1-q)-1)/(1-q)
@@ -27,7 +27,7 @@ log.q = function(x,q=1) {
#'
#' @author Eric Coissac
#' @export
-exp.q = function(x,q=1,base=exp(1)) {
+exp_q = function(x,q=1,base=exp(1)) {
if (q==1)
exp(x)
else
diff --git a/index.Rmd b/index.Rmd
index a37cdaf..cf2940b 100644
--- a/index.Rmd
+++ b/index.Rmd
@@ -18,6 +18,7 @@ library(knitr)
library(tidyverse)
library(kableExtra)
library(latex2exp)
+library(MetabarSchool)
opts_chunk$set(echo = FALSE,
cache = TRUE,
@@ -498,7 +499,7 @@ $$
$$
```{r echo=TRUE, eval=FALSE}
-log.q = function(x,q=1) {
+log_q = function(x,q=1) {
if (q==1)
log(x)
else
@@ -506,6 +507,28 @@ log.q = function(x,q=1) {
}
```
+## Impact of $q$ on the `log_q` function
+
+```{r}
+layout(matrix(c(1,1,2),nrow=1))
+qs = seq(0,5,by=1)
+x = seq(0.001,1,length.out = 100)
+plot(x,log_q(x,0),lty=2,lwd=3,col=0,type="l",
+ ylab = TeX("$^q\\log$"),
+ ylim=c(-10,0))
+
+for (i in seq_along(qs)) {
+ points(x,log_q(x,qs[i]),lty=1,lwd=1,col=i,type="l")
+}
+
+points(x,log(x),lty=2,lwd=3,col="red",type="l")
+
+plot(0,type='n',axes=FALSE,ann=FALSE)
+legend("topleft",legend = qs,fill = seq_along(qs),cex=1.5)
+
+
+```
+
## And its inverse function {.flexbox .vcenter}
$$
@@ -517,7 +540,7 @@ $$
\right.
$$
```{r echo=TRUE, eval=FALSE}
-exp.q = function(x,q=1) {
+exp_q = function(x,q=1) {
if (q==1)
exp(x)
else
@@ -532,8 +555,8 @@ $$
$$
```{r echo=TRUE, eval=FALSE}
-H.q = function(x,q=1) {
- sum(x * log.q(1/x,q),na.rm = TRUE)
+H_q = function(x,q=1) {
+ sum(x * log_q(1/x,q),na.rm = TRUE)
}
```
@@ -544,22 +567,22 @@ $$
^qD=^qe^{^qH}
$$
```{r echo=TRUE, eval=FALSE}
- D.q = function(x,q=1) {
- exp.q(H.q(x,q),q)
+ D_q = function(x,q=1) {
+ exp_q(H_q(x,q),q)
}
```
## Biodiversity spectrum (1) {.flexbox .vcenter}
```{r echo=TRUE, eval=FALSE}
-H.spectrum = function(x,q=1) {
- sapply(q,function(Q) H.q(x,Q))
+H_spectrum = function(x,q=1) {
+ sapply(q,function(Q) H_q(x,Q))
}
```
```{r echo=TRUE, eval=FALSE}
-D.spectrum = function(x,q=1) {
- sapply(q,function(Q) D.q(x,Q))
+D_spectrum = function(x,q=1) {
+ sapply(q,function(Q) D_q(x,Q))
}
```
@@ -568,8 +591,8 @@ D.spectrum = function(x,q=1) {
```{r echo=TRUE,warning=FALSE,error=FALSE}
library(MetabarSchool)
qs = seq(from=0,to=3,by=0.1)
-environments.hq = apply(environments,MARGIN = 1,H.spectrum,q=qs)
-environments.dq = apply(environments,MARGIN = 1,D.spectrum,q=qs)
+environments.hq = apply(environments,MARGIN = 1,H_spectrum,q=qs)
+environments.dq = apply(environments,MARGIN = 1,D_spectrum,q=qs)
```
```{r}
@@ -616,8 +639,8 @@ $q$ can be considered as a penality you give to rare species
## Biodiversity spectrum of the mock community
```{r echo=TRUE}
-H.mock = H.spectrum(plants.16$dilution,qs)
-D.mock = D.spectrum(plants.16$dilution,qs)
+H.mock = H_spectrum(plants.16$dilution,qs)
+D.mock = D_spectrum(plants.16$dilution,qs)
```
```{r}
@@ -640,7 +663,7 @@ abline(v=c(0,1,2),lty=2,col=4:6)
```{r echo=TRUE}
positive.H = apply(positive.count.relfreq,
MARGIN = 1,
- FUN = H.spectrum,
+ FUN = H_spectrum,
q=qs)
```
```{r}
@@ -672,7 +695,7 @@ positive.H.means = rowMeans(positive.H)
```{r echo=TRUE}
positive.D = apply(positive.count.relfreq,
MARGIN = 1,
- FUN = D.spectrum,
+ FUN = D_spectrum,
q=qs)
```
@@ -720,7 +743,7 @@ positive.clean.count.relfreq = decostand(positive.clean.count,
positive.clean.H = apply(positive.clean.count.relfreq,
MARGIN = 1,
- FUN = H.spectrum,
+ FUN = H_spectrum,
q=qs)
```
@@ -738,7 +761,7 @@ points(H.mock,col="red",type="l")
```{r echo=TRUE}
positive.clean.D = apply(positive.clean.count.relfreq,
MARGIN = 1,
- FUN = D.spectrum,
+ FUN = D_spectrum,
q=qs)
```
@@ -1144,7 +1167,7 @@ legend("topleft",legend = levels(samples.type),fill = 1:4,cex=1.2)
```{r}
guiana.relfreq.final = apply(guiana.relfreq.final,
MARGIN = 1,
- FUN = H.spectrum,
+ FUN = H_spectrum,
q=qs)
```
diff --git a/index.html b/index.html
index 5a22cb7..eeb275f 100644
--- a/index.html
+++ b/index.html
@@ -1842,13 +1842,17 @@ Environment.2
\right.
\]
-log.q = function(x,q=1) {
+log_q = function(x,q=1) {
if (q==1)
log(x)
else
(x^(1-q)-1)/(1-q)
}
+Impact of \(q\) on the log_q function
+
+
+
And its inverse function
\[
@@ -1860,7 +1864,7 @@ Environment.2
\right.
\]
-exp.q = function(x,q=1) {
+exp_q = function(x,q=1) {
if (q==1)
exp(x)
else
@@ -1873,8 +1877,8 @@ Environment.2
^qH = - \sum_{i=1}^S pi \times ^q\log pi
\]
-H.q = function(x,q=1) {
- sum(x * log.q(1/x,q),na.rm = TRUE)
+H_q = function(x,q=1) {
+ sum(x * log_q(1/x,q),na.rm = TRUE)
}
and generalized the previously presented Hill's number
@@ -1883,28 +1887,28 @@ Environment.2
^qD=^qe^{^qH}
\]
- D.q = function(x,q=1) {
- exp.q(H.q(x,q),q)
+ D_q = function(x,q=1) {
+ exp_q(H_q(x,q),q)
}
Biodiversity spectrum (1)
-H.spectrum = function(x,q=1) {
- sapply(q,function(Q) H.q(x,Q))
+H_spectrum = function(x,q=1) {
+ sapply(q,function(Q) H_q(x,Q))
}
-D.spectrum = function(x,q=1) {
- sapply(q,function(Q) D.q(x,Q))
+D_spectrum = function(x,q=1) {
+ sapply(q,function(Q) D_q(x,Q))
}
Biodiversity spectrum (2)
library(MetabarSchool)
qs = seq(from=0,to=3,by=0.1)
-environments.hq = apply(environments,MARGIN = 1,H.spectrum,q=qs)
-environments.dq = apply(environments,MARGIN = 1,D.spectrum,q=qs)
+environments.hq = apply(environments,MARGIN = 1,H_spectrum,q=qs)
+environments.dq = apply(environments,MARGIN = 1,D_spectrum,q=qs)
-
+
Generalized entropy \(vs\) \(\alpha\)-diversity indices
@@ -1934,32 +1938,32 @@ environments.dq = apply(environments,MARGIN = 1,D.spectrum,q=qs)
Biodiversity spectrum of the mock community
Biodiversity spectrum and metabarcoding (1)
positive.H = apply(positive.count.relfreq,
MARGIN = 1,
- FUN = H.spectrum,
+ FUN = H_spectrum,
q=qs)
-
+
Biodiversity spectrum and metabarcoding (2)
-
+
Biodiversity spectrum and metabarcoding (3)
positive.D = apply(positive.count.relfreq,
MARGIN = 1,
- FUN = D.spectrum,
+ FUN = D_spectrum,
q=qs)
-
+
Impact of data cleaning on \(\alpha\)-diversity (1)
@@ -1992,19 +1996,19 @@ positive.clean.count.relfreq = decostand(positive.clean.count,
positive.clean.H = apply(positive.clean.count.relfreq,
MARGIN = 1,
- FUN = H.spectrum,
+ FUN = H_spectrum,
q=qs)
-
+
Impact of data cleaning on \(\alpha\)-diversity (3)
positive.clean.D = apply(positive.clean.count.relfreq,
MARGIN = 1,
- FUN = D.spectrum,
+ FUN = D_spectrum,
q=qs)
-
+
\(\beta\)-diversity
@@ -2163,7 +2167,7 @@ data("guiana.samples")
s = tag_bad_pcr(guiana.samples$sample,guiana.count)
-
+
guiana.count.clean = guiana.count[s$keep,]
guiana.samples.clean = guiana.samples[s$keep,]
@@ -2178,7 +2182,7 @@ guiana.samples.clean = guiana.samples[s$keep,]
s = tag_bad_pcr(guiana.samples.clean$sample,guiana.count.clean)
-
+
guiana.count.clean = guiana.count.clean[s$keep,]
guiana.samples.clean = guiana.samples.clean[s$keep,]
@@ -2193,7 +2197,7 @@ guiana.samples.clean = guiana.samples.clean[s$keep,]
s = tag_bad_pcr(guiana.samples.clean$sample,guiana.count.clean)
-
+
guiana.count.clean = guiana.count.clean[s$keep,]
guiana.samples.clean = guiana.samples.clean[s$keep,]
@@ -2260,7 +2264,7 @@ xy = xy[,1:2]
xy.hellinger = decostand(xy,method = "hellinger")
-

+
@@ -2301,17 +2305,17 @@ guiana.jac.50.pcoa = cmdscale(guiana.jac.50.dist,k=3,eig = TRUE)
Principale coordinate analysis (2)
-
+
Principale composante analysis
guiana.hellinger.pca = prcomp(guiana.hellinger.final,center = TRUE, scale. = FALSE)
-
+
Comparing diversity of the environments
-
+
Bibliography
diff --git a/man/exp.q.Rd b/man/exp_q.Rd
similarity index 80%
rename from man/exp.q.Rd
rename to man/exp_q.Rd
index 21590c8..b2f7575 100644
--- a/man/exp.q.Rd
+++ b/man/exp_q.Rd
@@ -1,10 +1,10 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/generalized_log.R
-\name{exp.q}
-\alias{exp.q}
+\name{exp_q}
+\alias{exp_q}
\title{Generalized exponential function.}
\usage{
-\method{exp}{q}(x, q = 1, base = exp(1))
+exp_q(x, q = 1, base = exp(1))
}
\description{
Generalized exponential function.
diff --git a/man/log.q.Rd b/man/log_q.Rd
similarity index 84%
rename from man/log.q.Rd
rename to man/log_q.Rd
index d1fb77e..8fc1667 100644
--- a/man/log.q.Rd
+++ b/man/log_q.Rd
@@ -1,10 +1,10 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/generalized_log.R
-\name{log.q}
-\alias{log.q}
+\name{log_q}
+\alias{log_q}
\title{Generalized logaritmic function.}
\usage{
-\method{log}{q}(x, q = 1)
+log_q(x, q = 1)
}
\description{
\deqn{x \longmapsto 1 : \log(x) \approx x-1}