Commit cf80ff9f by Eric Coissac

Change names of the *.q functions to *_q

parent 657aaa73
# 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)
#' @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))
}
......@@ -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
......
......@@ -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)
```
......
......@@ -1842,13 +1842,17 @@ Environment.2
\right.
\]</p>
<pre class = 'prettyprint lang-r'>log.q = function(x,q=1) {
<pre class = 'prettyprint lang-r'>log_q = function(x,q=1) {
if (q==1)
log(x)
else
(x^(1-q)-1)/(1-q)
}</pre>
</article></slide><slide class=""><hgroup><h2>Impact of \(q\) on the <code>log_q</code> function</h2></hgroup><article id="impact-of-q-on-the-log_q-function" class="smaller ">
<p><img src="index_files/figure-html/unnamed-chunk-45-1.png" width="720" /></p>
</article></slide><slide class=""><hgroup><h2>And its inverse function</h2></hgroup><article id="and-its-inverse-function" class="smaller flexbox vcenter">
<p>\[
......@@ -1860,7 +1864,7 @@ Environment.2
\right.
\]</p>
<pre class = 'prettyprint lang-r'>exp.q = function(x,q=1) {
<pre class = 'prettyprint lang-r'>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
\]</p>
<pre class = 'prettyprint lang-r'>H.q = function(x,q=1) {
sum(x * log.q(1/x,q),na.rm = TRUE)
<pre class = 'prettyprint lang-r'>H_q = function(x,q=1) {
sum(x * log_q(1/x,q),na.rm = TRUE)
}</pre>
<p>and generalized the previously presented Hill&#39;s number</p>
......@@ -1883,28 +1887,28 @@ Environment.2
^qD=^qe^{^qH}
\]</p>
<pre class = 'prettyprint lang-r'> D.q = function(x,q=1) {
exp.q(H.q(x,q),q)
<pre class = 'prettyprint lang-r'> D_q = function(x,q=1) {
exp_q(H_q(x,q),q)
}</pre>
</article></slide><slide class=""><hgroup><h2>Biodiversity spectrum (1)</h2></hgroup><article id="biodiversity-spectrum-1" class="smaller flexbox vcenter">
<pre class = 'prettyprint lang-r'>H.spectrum = function(x,q=1) {
sapply(q,function(Q) H.q(x,Q))
<pre class = 'prettyprint lang-r'>H_spectrum = function(x,q=1) {
sapply(q,function(Q) H_q(x,Q))
}</pre>
<pre class = 'prettyprint lang-r'>D.spectrum = function(x,q=1) {
sapply(q,function(Q) D.q(x,Q))
<pre class = 'prettyprint lang-r'>D_spectrum = function(x,q=1) {
sapply(q,function(Q) D_q(x,Q))
}</pre>
</article></slide><slide class=""><hgroup><h2>Biodiversity spectrum (2)</h2></hgroup><article id="biodiversity-spectrum-2" class="smaller ">
<pre class = 'prettyprint lang-r'>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)</pre>
environments.hq = apply(environments,MARGIN = 1,H_spectrum,q=qs)
environments.dq = apply(environments,MARGIN = 1,D_spectrum,q=qs)</pre>
<p><img src="index_files/figure-html/unnamed-chunk-51-1.png" width="720" /></p>
<p><img src="index_files/figure-html/unnamed-chunk-52-1.png" width="720" /></p>
</article></slide><slide class=""><hgroup><h2>Generalized entropy \(vs\) \(\alpha\)-diversity indices</h2></hgroup><article id="generalized-entropy-vs-alpha-diversity-indices" class="smaller ">
......@@ -1934,32 +1938,32 @@ environments.dq = apply(environments,MARGIN = 1,D.spectrum,q=qs)</pre>
</article></slide><slide class=""><hgroup><h2>Biodiversity spectrum of the mock community</h2></hgroup><article id="biodiversity-spectrum-of-the-mock-community" class="smaller ">
<pre class = 'prettyprint lang-r'>H.mock = H.spectrum(plants.16$dilution,qs)
D.mock = D.spectrum(plants.16$dilution,qs)</pre>
<pre class = 'prettyprint lang-r'>H.mock = H_spectrum(plants.16$dilution,qs)
D.mock = D_spectrum(plants.16$dilution,qs)</pre>
<p><img src="index_files/figure-html/unnamed-chunk-53-1.png" width="720" /></p>
<p><img src="index_files/figure-html/unnamed-chunk-54-1.png" width="720" /></p>
</article></slide><slide class=""><hgroup><h2>Biodiversity spectrum and metabarcoding (1)</h2></hgroup><article id="biodiversity-spectrum-and-metabarcoding-1" class="smaller smaller">
<pre class = 'prettyprint lang-r'>positive.H = apply(positive.count.relfreq,
MARGIN = 1,
FUN = H.spectrum,
FUN = H_spectrum,
q=qs)</pre>
<p><img src="index_files/figure-html/unnamed-chunk-55-1.png" width="720" /></p>
<p><img src="index_files/figure-html/unnamed-chunk-56-1.png" width="720" /></p>
</article></slide><slide class=""><hgroup><h2>Biodiversity spectrum and metabarcoding (2)</h2></hgroup><article id="biodiversity-spectrum-and-metabarcoding-2" class="smaller flexbox vcenter smaller">
<p><img src="index_files/figure-html/unnamed-chunk-56-1.png" width="720" /></p>
<p><img src="index_files/figure-html/unnamed-chunk-57-1.png" width="720" /></p>
</article></slide><slide class=""><hgroup><h2>Biodiversity spectrum and metabarcoding (3)</h2></hgroup><article id="biodiversity-spectrum-and-metabarcoding-3" class="smaller smaller">
<pre class = 'prettyprint lang-r'>positive.D = apply(positive.count.relfreq,
MARGIN = 1,
FUN = D.spectrum,
FUN = D_spectrum,
q=qs)</pre>
<p><img src="index_files/figure-html/unnamed-chunk-58-1.png" width="720" /></p>
<p><img src="index_files/figure-html/unnamed-chunk-59-1.png" width="720" /></p>
</article></slide><slide class=""><hgroup><h2>Impact of data cleaning on \(\alpha\)-diversity (1)</h2></hgroup><article id="impact-of-data-cleaning-on-alpha-diversity-1" class="smaller ">
......@@ -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)</pre>
<p><img src="index_files/figure-html/unnamed-chunk-61-1.png" width="720" /></p>
<p><img src="index_files/figure-html/unnamed-chunk-62-1.png" width="720" /></p>
</article></slide><slide class=""><hgroup><h2>Impact of data cleaning on \(\alpha\)-diversity (3)</h2></hgroup><article id="impact-of-data-cleaning-on-alpha-diversity-3" class="smaller ">
<pre class = 'prettyprint lang-r'>positive.clean.D = apply(positive.clean.count.relfreq,
MARGIN = 1,
FUN = D.spectrum,
FUN = D_spectrum,
q=qs)</pre>
<p><img src="index_files/figure-html/unnamed-chunk-63-1.png" width="720" /></p>
<p><img src="index_files/figure-html/unnamed-chunk-64-1.png" width="720" /></p>
</article></slide><slide class="segue dark nobackground level1"><hgroup class = 'auto-fadein'><h2>\(\beta\)-diversity</h2></hgroup><article id="beta-diversity" class="smaller ">
......@@ -2163,7 +2167,7 @@ data(&quot;guiana.samples&quot;)</pre>
<pre class = 'prettyprint lang-r'>s = tag_bad_pcr(guiana.samples$sample,guiana.count)</pre>
<p><img src="index_files/figure-html/unnamed-chunk-68-1.png" width="720" /></p>
<p><img src="index_files/figure-html/unnamed-chunk-69-1.png" width="720" /></p>
<pre class = 'prettyprint lang-r'>guiana.count.clean = guiana.count[s$keep,]
guiana.samples.clean = guiana.samples[s$keep,]</pre>
......@@ -2178,7 +2182,7 @@ guiana.samples.clean = guiana.samples[s$keep,]</pre>
<pre class = 'prettyprint lang-r'>s = tag_bad_pcr(guiana.samples.clean$sample,guiana.count.clean)</pre>
<p><img src="index_files/figure-html/unnamed-chunk-70-1.png" width="720" /></p>
<p><img src="index_files/figure-html/unnamed-chunk-71-1.png" width="720" /></p>
<pre class = 'prettyprint lang-r'>guiana.count.clean = guiana.count.clean[s$keep,]
guiana.samples.clean = guiana.samples.clean[s$keep,]</pre>
......@@ -2193,7 +2197,7 @@ guiana.samples.clean = guiana.samples.clean[s$keep,]</pre>
<pre class = 'prettyprint lang-r'>s = tag_bad_pcr(guiana.samples.clean$sample,guiana.count.clean)</pre>
<p><img src="index_files/figure-html/unnamed-chunk-72-1.png" width="720" /></p>
<p><img src="index_files/figure-html/unnamed-chunk-73-1.png" width="720" /></p>
<pre class = 'prettyprint lang-r'>guiana.count.clean = guiana.count.clean[s$keep,]
guiana.samples.clean = guiana.samples.clean[s$keep,]</pre>
......@@ -2260,7 +2264,7 @@ xy = xy[,1:2]
xy.hellinger = decostand(xy,method = &quot;hellinger&quot;)</pre>
<div style="float: left; width: 50%;">
<p><img src="index_files/figure-html/unnamed-chunk-79-1.png" width="384" /></p></div>
<p><img src="index_files/figure-html/unnamed-chunk-80-1.png" width="384" /></p></div>
<div style="float: right; width: 50%;">
<p><img src="figures/euclidean_hellinger.svg" width="400px" /></p></div>
......@@ -2301,17 +2305,17 @@ guiana.jac.50.pcoa = cmdscale(guiana.jac.50.dist,k=3,eig = TRUE)</pre>
</article></slide><slide class=""><hgroup><h2>Principale coordinate analysis (2)</h2></hgroup><article id="principale-coordinate-analysis-2" class="smaller ">
<p><img src="index_files/figure-html/unnamed-chunk-82-1.png" width="720" /></p>
<p><img src="index_files/figure-html/unnamed-chunk-83-1.png" width="720" /></p>
</article></slide><slide class=""><hgroup><h2>Principale composante analysis</h2></hgroup><article id="principale-composante-analysis" class="smaller flexbox vcenter">
<pre class = 'prettyprint lang-r'>guiana.hellinger.pca = prcomp(guiana.hellinger.final,center = TRUE, scale. = FALSE)</pre>
<p><img src="index_files/figure-html/unnamed-chunk-84-1.png" width="1152" /></p>
<p><img src="index_files/figure-html/unnamed-chunk-85-1.png" width="1152" /></p>
</article></slide><slide class=""><hgroup><h2>Comparing diversity of the environments</h2></hgroup><article id="comparing-diversity-of-the-environments" class="smaller ">
<p><img src="index_files/figure-html/unnamed-chunk-86-1.png" width="864" /></p>
<p><img src="index_files/figure-html/unnamed-chunk-87-1.png" width="864" /></p>
</article></slide><slide class=""><hgroup><h2>Bibliography</h2></hgroup><article id="bibliography" class="smaller unnumbered">
......
% 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.
......
% 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}
......
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