diff --git a/inst/gitbook/_book/dispRity_manual.pdf b/inst/gitbook/_book/dispRity_manual.pdf index fade8c91..6915fce8 100644 Binary files a/inst/gitbook/_book/dispRity_manual.pdf and b/inst/gitbook/_book/dispRity_manual.pdf differ diff --git a/inst/gitbook/_book/dispRity_manual.tex b/inst/gitbook/_book/dispRity_manual.tex index e0ab7532..7907a96c 100644 --- a/inst/gitbook/_book/dispRity_manual.tex +++ b/inst/gitbook/_book/dispRity_manual.tex @@ -4,18 +4,21 @@ % \documentclass[ ]{book} -\usepackage{lmodern} -\usepackage{amssymb,amsmath} -\usepackage{ifxetex,ifluatex} -\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex +\usepackage{amsmath,amssymb} +\usepackage{iftex} +\ifPDFTeX \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{textcomp} % provide euro and other symbols \else % if luatex or xetex - \usepackage{unicode-math} + \usepackage{unicode-math} % this also loads fontspec \defaultfontfeatures{Scale=MatchLowercase} \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1} \fi +\usepackage{lmodern} +\ifPDFTeX\else + % xetex/luatex font selection +\fi % Use upquote if available, for straight quotes in verbatim environments \IfFileExists{upquote.sty}{\usepackage{upquote}}{} \IfFileExists{microtype.sty}{% use microtype if available @@ -33,14 +36,6 @@ \KOMAoptions{parskip=half}} \makeatother \usepackage{xcolor} -\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available -\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}} -\hypersetup{ - pdftitle={dispRity R package manual}, - pdfauthor={Thomas Guillerme (guillert@tcd.ie)}, - hidelinks, - pdfcreator={LaTeX via pandoc}} -\urlstyle{same} % disable monospaced font for URLs \usepackage{color} \usepackage{fancyvrb} \newcommand{\VerbBar}{|} @@ -52,13 +47,13 @@ \newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}} \newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}} \newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}} -\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.77,0.63,0.00}{#1}} +\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}} \newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}} \newcommand{\BuiltInTok}[1]{#1} \newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}} \newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}} \newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}} -\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}} +\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}} \newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}} \newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}} \newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}} @@ -66,7 +61,7 @@ \newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}} \newcommand{\ExtensionTok}[1]{#1} \newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}} -\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}} +\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}} \newcommand{\ImportTok}[1]{#1} \newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}} \newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}} @@ -75,13 +70,14 @@ \newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}} \newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}} \newcommand{\RegionMarkerTok}[1]{#1} -\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}} +\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}} \newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}} \newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}} \newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}} \newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}} \newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}} -\usepackage{longtable,booktabs} +\usepackage{longtable,booktabs,array} +\usepackage{calc} % for calculating minipage widths % Correct order of tables after \paragraph or \subparagraph \usepackage{etoolbox} \makeatletter @@ -108,12 +104,23 @@ \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}} \setcounter{secnumdepth}{5} \usepackage{booktabs} +\ifLuaTeX + \usepackage{selnolig} % disable illegal ligatures +\fi \usepackage[]{natbib} \bibliographystyle{plainnat} +\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}} +\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available +\urlstyle{same} +\hypersetup{ + pdftitle={dispRity R package manual}, + pdfauthor={Thomas Guillerme (guillert@tcd.ie)}, + hidelinks, + pdfcreator={LaTeX via pandoc}} \title{dispRity R package manual} \author{Thomas Guillerme (\href{mailto:guillert@tcd.ie}{\nolinkurl{guillert@tcd.ie}})} -\date{2024-03-08} +\date{2024-11-12} \begin{document} \maketitle @@ -153,7 +160,7 @@ \section{Installing and running the package}\label{installing-and-running-the-pa \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{install.packages}\NormalTok{(}\StringTok{"dispRity"}\NormalTok{)} +\FunctionTok{install.packages}\NormalTok{(}\StringTok{"dispRity"}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -161,11 +168,11 @@ \section{Installing and running the package}\label{installing-and-running-the-pa \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Checking if devtools is already installed} -\ControlFlowTok{if}\NormalTok{(}\OperatorTok{!}\KeywordTok{require}\NormalTok{(devtools)) }\KeywordTok{install.packages}\NormalTok{(}\StringTok{"devtools"}\NormalTok{)} +\DocumentationTok{\#\# Checking if devtools is already installed} +\ControlFlowTok{if}\NormalTok{(}\SpecialCharTok{!}\FunctionTok{require}\NormalTok{(devtools)) }\FunctionTok{install.packages}\NormalTok{(}\StringTok{"devtools"}\NormalTok{)} -\CommentTok{\#\# Installing the latest released version directly from GitHub} -\KeywordTok{install\_github}\NormalTok{(}\StringTok{"TGuillerme/dispRity"}\NormalTok{, }\DataTypeTok{ref =} \StringTok{"release"}\NormalTok{)} +\DocumentationTok{\#\# Installing the latest released version directly from GitHub} +\FunctionTok{install\_github}\NormalTok{(}\StringTok{"TGuillerme/dispRity"}\NormalTok{, }\AttributeTok{ref =} \StringTok{"release"}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -223,8 +230,8 @@ \section{\texorpdfstring{\texttt{dispRity} is always changing, how do I know it' \begin{Shaded} \begin{Highlighting}[] -\NormalTok{testthat}\OperatorTok{::}\KeywordTok{expect\_equal}\NormalTok{(}\DataTypeTok{object =} \KeywordTok{mean}\NormalTok{(}\KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{,}\DecValTok{3}\NormalTok{)),} - \DataTypeTok{expected =} \DecValTok{2}\NormalTok{)} +\NormalTok{testthat}\SpecialCharTok{::}\FunctionTok{expect\_equal}\NormalTok{(}\AttributeTok{object =} \FunctionTok{mean}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{,}\DecValTok{3}\NormalTok{)),} + \AttributeTok{expected =} \DecValTok{2}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -317,65 +324,30 @@ \chapter{Glossary}\label{glossary}} \hypertarget{glossary-equivalences-in-palaeobiology-and-ecology}{% \section{Glossary equivalences in palaeobiology and ecology}\label{glossary-equivalences-in-palaeobiology-and-ecology}} -\begin{longtable}[]{@{}llll@{}} -\toprule -\begin{minipage}[b]{0.22\columnwidth}\raggedright -In this manual\strut -\end{minipage} & \begin{minipage}[b]{0.22\columnwidth}\raggedright -In \texttt{dispRity}\strut -\end{minipage} & \begin{minipage}[b]{0.26\columnwidth}\raggedright -E.g. in palaeobiology\strut -\end{minipage} & \begin{minipage}[b]{0.19\columnwidth}\raggedright -E.g. in ecology\strut -\end{minipage}\tabularnewline -\midrule +\begin{longtable}[]{@{} + >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.2459}} + >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.2459}} + >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.2951}} + >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.2131}}@{}} +\toprule\noalign{} +\begin{minipage}[b]{\linewidth}\raggedright +In this manual +\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright +In \texttt{dispRity} +\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright +E.g. in palaeobiology +\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright +E.g. in ecology +\end{minipage} \\ +\midrule\noalign{} \endhead -\begin{minipage}[t]{0.22\columnwidth}\raggedright -the multidimensional space\strut -\end{minipage} & \begin{minipage}[t]{0.22\columnwidth}\raggedright -a \texttt{matrix} object (\(n\times d\))\strut -\end{minipage} & \begin{minipage}[t]{0.26\columnwidth}\raggedright -a morphospace\strut -\end{minipage} & \begin{minipage}[t]{0.19\columnwidth}\raggedright -a function-space\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.22\columnwidth}\raggedright -elements\strut -\end{minipage} & \begin{minipage}[t]{0.22\columnwidth}\raggedright -rows (\(n\))\strut -\end{minipage} & \begin{minipage}[t]{0.26\columnwidth}\raggedright -taxa\strut -\end{minipage} & \begin{minipage}[t]{0.19\columnwidth}\raggedright -field experiments\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.22\columnwidth}\raggedright -dimensions\strut -\end{minipage} & \begin{minipage}[t]{0.22\columnwidth}\raggedright -columns (\(d\))\strut -\end{minipage} & \begin{minipage}[t]{0.26\columnwidth}\raggedright -morphological characters\strut -\end{minipage} & \begin{minipage}[t]{0.19\columnwidth}\raggedright -communities' compositions\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.22\columnwidth}\raggedright -subsets\strut -\end{minipage} & \begin{minipage}[t]{0.22\columnwidth}\raggedright -a \texttt{matrix} (\(m \times d\), with \(m \leq n\))\strut -\end{minipage} & \begin{minipage}[t]{0.26\columnwidth}\raggedright -time series\strut -\end{minipage} & \begin{minipage}[t]{0.19\columnwidth}\raggedright -experimental treatments\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.22\columnwidth}\raggedright -disparity\strut -\end{minipage} & \begin{minipage}[t]{0.22\columnwidth}\raggedright -a \texttt{function}\strut -\end{minipage} & \begin{minipage}[t]{0.26\columnwidth}\raggedright -sum of variances\strut -\end{minipage} & \begin{minipage}[t]{0.19\columnwidth}\raggedright -ellipsoid volume\strut -\end{minipage}\tabularnewline -\bottomrule +\bottomrule\noalign{} +\endlastfoot +the multidimensional space & a \texttt{matrix} object (\(n\times d\)) & a morphospace & a function-space \\ +elements & rows (\(n\)) & taxa & field experiments \\ +dimensions & columns (\(d\)) & morphological characters & communities' compositions \\ +subsets & a \texttt{matrix} (\(m \times d\), with \(m \leq n\)) & time series & experimental treatments \\ +disparity & a \texttt{function} & sum of variances & ellipsoid volume \\ \end{longtable} \hypertarget{getting-started-with-disprity}{% @@ -408,17 +380,17 @@ \subsection{\texorpdfstring{Ordination matrices from \texttt{geomorph}}{Ordinati \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{require}\NormalTok{(geomorph)} +\FunctionTok{require}\NormalTok{(geomorph)} -\CommentTok{\#\# Loading the plethodon dataset} -\KeywordTok{data}\NormalTok{(plethodon)} +\DocumentationTok{\#\# Loading the plethodon dataset} +\FunctionTok{data}\NormalTok{(plethodon)} -\CommentTok{\#\# Performing a Procrustes transform on the landmarks} -\NormalTok{procrustes \textless{}{-}}\StringTok{ }\KeywordTok{gpagen}\NormalTok{(plethodon}\OperatorTok{$}\NormalTok{land, }\DataTypeTok{PrinAxes =} \OtherTok{FALSE}\NormalTok{,} - \DataTypeTok{print.progress =} \OtherTok{FALSE}\NormalTok{)} +\DocumentationTok{\#\# Performing a Procrustes transform on the landmarks} +\NormalTok{procrustes }\OtherTok{\textless{}{-}} \FunctionTok{gpagen}\NormalTok{(plethodon}\SpecialCharTok{$}\NormalTok{land, }\AttributeTok{PrinAxes =} \ConstantTok{FALSE}\NormalTok{,} + \AttributeTok{print.progress =} \ConstantTok{FALSE}\NormalTok{)} -\CommentTok{\#\# Ordinating this data} -\KeywordTok{geomorph.ordination}\NormalTok{(procrustes)[}\DecValTok{1}\OperatorTok{:}\DecValTok{5}\NormalTok{,}\DecValTok{1}\OperatorTok{:}\DecValTok{5}\NormalTok{]} +\DocumentationTok{\#\# Ordinating this data} +\FunctionTok{geomorph.ordination}\NormalTok{(procrustes)[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{,}\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{]} \end{Highlighting} \end{Shaded} @@ -437,12 +409,12 @@ \subsection{\texorpdfstring{Ordination matrices from \texttt{geomorph}}{Ordinati \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Using a geomorph.data.frame} -\NormalTok{geomorph\_df \textless{}{-}}\StringTok{ }\KeywordTok{geomorph.data.frame}\NormalTok{(procrustes,} - \DataTypeTok{species =}\NormalTok{ plethodon}\OperatorTok{$}\NormalTok{species, }\DataTypeTok{site =}\NormalTok{ plethodon}\OperatorTok{$}\NormalTok{site)} +\DocumentationTok{\#\# Using a geomorph.data.frame} +\NormalTok{geomorph\_df }\OtherTok{\textless{}{-}} \FunctionTok{geomorph.data.frame}\NormalTok{(procrustes,} + \AttributeTok{species =}\NormalTok{ plethodon}\SpecialCharTok{$}\NormalTok{species, }\AttributeTok{site =}\NormalTok{ plethodon}\SpecialCharTok{$}\NormalTok{site)} -\CommentTok{\#\# Ordinating this data and making a dispRity object} -\KeywordTok{geomorph.ordination}\NormalTok{(geomorph\_df)} +\DocumentationTok{\#\# Ordinating this data and making a dispRity object} +\FunctionTok{geomorph.ordination}\NormalTok{(geomorph\_df)} \end{Highlighting} \end{Shaded} @@ -462,10 +434,10 @@ \subsection{\texorpdfstring{Ordination matrices from \texttt{Claddis}}{Ordinatio \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{require}\NormalTok{(Claddis)} +\FunctionTok{require}\NormalTok{(Claddis)} -\CommentTok{\#\# Ordinating the example data from Claddis} -\KeywordTok{Claddis.ordination}\NormalTok{(michaux\_}\DecValTok{1989}\NormalTok{)} +\DocumentationTok{\#\# Ordinating the example data from Claddis} +\FunctionTok{Claddis.ordination}\NormalTok{(michaux\_1989)} \end{Highlighting} \end{Shaded} @@ -495,8 +467,8 @@ \subsection{Other kinds of ordination matrices}\label{other-kinds-of-ordination- \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# A multivariate matrix} -\KeywordTok{head}\NormalTok{(USArrests)} +\DocumentationTok{\#\# A multivariate matrix} +\FunctionTok{head}\NormalTok{(USArrests)} \end{Highlighting} \end{Shaded} @@ -512,12 +484,12 @@ \subsection{Other kinds of ordination matrices}\label{other-kinds-of-ordination- \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Ordinating the matrix using \textasciigrave{}prcomp\textasciigrave{} } -\NormalTok{ordination \textless{}{-}}\StringTok{ }\KeywordTok{prcomp}\NormalTok{(USArrests)} +\DocumentationTok{\#\# Ordinating the matrix using \textasciigrave{}prcomp\textasciigrave{} } +\NormalTok{ordination }\OtherTok{\textless{}{-}} \FunctionTok{prcomp}\NormalTok{(USArrests)} -\CommentTok{\#\# Selecting the ordinated matrix} -\NormalTok{ordinated\_matrix \textless{}{-}}\StringTok{ }\NormalTok{ordination}\OperatorTok{$}\NormalTok{x} -\KeywordTok{head}\NormalTok{(ordinated\_matrix)} +\DocumentationTok{\#\# Selecting the ordinated matrix} +\NormalTok{ordinated\_matrix }\OtherTok{\textless{}{-}}\NormalTok{ ordination}\SpecialCharTok{$}\NormalTok{x} +\FunctionTok{head}\NormalTok{(ordinated\_matrix)} \end{Highlighting} \end{Shaded} @@ -541,8 +513,8 @@ \subsection{Other kinds of ordination matrices}\label{other-kinds-of-ordination- \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# A matrix of distances between cities} -\KeywordTok{str}\NormalTok{(eurodist)} +\DocumentationTok{\#\# A matrix of distances between cities} +\FunctionTok{str}\NormalTok{(eurodist)} \end{Highlighting} \end{Shaded} @@ -554,9 +526,9 @@ \subsection{Other kinds of ordination matrices}\label{other-kinds-of-ordination- \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Ordinating the matrix using cmdscale() with k = 5 dimensions } -\NormalTok{ordinated\_matrix \textless{}{-}}\StringTok{ }\KeywordTok{cmdscale}\NormalTok{(eurodist, }\DataTypeTok{k =} \DecValTok{5}\NormalTok{)} -\KeywordTok{head}\NormalTok{(ordinated\_matrix)} +\DocumentationTok{\#\# Ordinating the matrix using cmdscale() with k = 5 dimensions } +\NormalTok{ordinated\_matrix }\OtherTok{\textless{}{-}} \FunctionTok{cmdscale}\NormalTok{(eurodist, }\AttributeTok{k =} \DecValTok{5}\NormalTok{)} +\FunctionTok{head}\NormalTok{(ordinated\_matrix)} \end{Highlighting} \end{Shaded} @@ -602,45 +574,45 @@ \subsection{Example data}\label{example-data}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Loading the ordinated matrices} -\KeywordTok{data}\NormalTok{(BeckLee\_mat50)} -\KeywordTok{data}\NormalTok{(BeckLee\_mat99)} +\DocumentationTok{\#\# Loading the ordinated matrices} +\FunctionTok{data}\NormalTok{(BeckLee\_mat50)} +\FunctionTok{data}\NormalTok{(BeckLee\_mat99)} -\CommentTok{\#\# The first five taxa and dimensions of the 50 taxa matrix} -\KeywordTok{head}\NormalTok{(BeckLee\_mat50[, }\DecValTok{1}\OperatorTok{:}\DecValTok{5}\NormalTok{])} +\DocumentationTok{\#\# The first five taxa and dimensions of the 50 taxa matrix} +\FunctionTok{head}\NormalTok{(BeckLee\_mat50[, }\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{])} \end{Highlighting} \end{Shaded} \begin{verbatim} -## [,1] [,2] [,3] [,4] [,5] -## Cimolestes -0.5613001 0.06006259 0.08414761 -0.2313084 -0.18825039 -## Maelestes -0.4186019 -0.12186005 0.25556379 0.2737995 -0.28510479 -## Batodon -0.8337640 0.28718501 -0.10594610 -0.2381511 -0.07132646 -## Bulaklestes -0.7708261 -0.07629583 0.04549285 -0.4951160 -0.39962626 -## Daulestes -0.8320466 -0.09559563 0.04336661 -0.5792351 -0.37385914 -## Uchkudukodon -0.5074468 -0.34273248 0.40410310 -0.1223782 -0.34857351 +## [,1] [,2] [,3] [,4] [,5] +## Cimolestes -0.5613001 0.06006259 0.08414761 -0.2313084 0.18825039 +## Maelestes -0.4186019 -0.12186005 0.25556379 0.2737995 0.28510479 +## Batodon -0.8337640 0.28718501 -0.10594610 -0.2381511 0.07132646 +## Bulaklestes -0.7708261 -0.07629583 0.04549285 -0.4951160 0.39962626 +## Daulestes -0.8320466 -0.09559563 0.04336661 -0.5792351 0.37385914 +## Uchkudukodon -0.5074468 -0.34273248 0.40410310 -0.1223782 0.34857351 \end{verbatim} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The first five taxa and dimensions of the 99 taxa + ancestors matrix} -\NormalTok{BeckLee\_mat99[}\KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{98}\NormalTok{, }\DecValTok{99}\NormalTok{), }\DecValTok{1}\OperatorTok{:}\DecValTok{5}\NormalTok{]} +\DocumentationTok{\#\# The first five taxa and dimensions of the 99 taxa + ancestors matrix} +\NormalTok{BeckLee\_mat99[}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{98}\NormalTok{, }\DecValTok{99}\NormalTok{), }\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{]} \end{Highlighting} \end{Shaded} \begin{verbatim} -## [,1] [,2] [,3] [,4] [,5] -## Cimolestes -0.6794737 0.15658591 0.04918307 0.22509831 -0.38139436 -## Maelestes -0.5797289 0.04223105 -0.20329542 -0.15453876 -0.06993258 -## n48 0.2614394 0.01712426 0.21997583 -0.05383777 0.07919679 -## n49 0.3881123 0.13771446 0.11966941 0.01856597 -0.15263921 +## [,1] [,2] [,3] [,4] [,5] +## Cimolestes -0.6662114 0.152778203 0.04859246 -0.34158286 0.26817202 +## Maelestes -0.5719365 0.051636855 -0.19877079 -0.08318416 -0.14166592 +## n48 0.2511551 -0.002014967 0.22408002 0.06857018 -0.05660113 +## n49 0.3860798 0.131742956 0.12604056 -0.14738050 0.05095751 \end{verbatim} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Loading a list of first and last occurrence dates for the fossils} -\KeywordTok{data}\NormalTok{(BeckLee\_ages)} -\KeywordTok{head}\NormalTok{(BeckLee\_ages)} +\DocumentationTok{\#\# Loading a list of first and last occurrence dates for the fossils} +\FunctionTok{data}\NormalTok{(BeckLee\_ages)} +\FunctionTok{head}\NormalTok{(BeckLee\_ages)} \end{Highlighting} \end{Shaded} @@ -656,11 +628,11 @@ \subsection{Example data}\label{example-data}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Loading and plotting the phylogeny} -\KeywordTok{data}\NormalTok{(BeckLee\_tree)} -\KeywordTok{plot}\NormalTok{(BeckLee\_tree, }\DataTypeTok{cex =} \FloatTok{0.8}\NormalTok{) } -\KeywordTok{axisPhylo}\NormalTok{(}\DataTypeTok{root =} \DecValTok{140}\NormalTok{)} -\KeywordTok{nodelabels}\NormalTok{(}\DataTypeTok{cex =} \FloatTok{0.5}\NormalTok{)} +\DocumentationTok{\#\# Loading and plotting the phylogeny} +\FunctionTok{data}\NormalTok{(BeckLee\_tree)} +\FunctionTok{plot}\NormalTok{(BeckLee\_tree, }\AttributeTok{cex =} \FloatTok{0.8}\NormalTok{) } +\FunctionTok{axisPhylo}\NormalTok{(}\AttributeTok{root =} \DecValTok{140}\NormalTok{)} +\FunctionTok{nodelabels}\NormalTok{(}\AttributeTok{cex =} \FloatTok{0.5}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -693,10 +665,10 @@ \subsection{Disparity through time}\label{disparity-through-time}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Measuring disparity through time} -\NormalTok{disparity\_data \textless{}{-}}\StringTok{ }\KeywordTok{dispRity.through.time}\NormalTok{(BeckLee\_mat50, BeckLee\_tree,} - \DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, variances),} - \DataTypeTok{time =} \DecValTok{3}\NormalTok{)} +\DocumentationTok{\#\# Measuring disparity through time} +\NormalTok{disparity\_data }\OtherTok{\textless{}{-}} \FunctionTok{dispRity.through.time}\NormalTok{(BeckLee\_mat50, BeckLee\_tree,} + \AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, variances),} + \AttributeTok{time =} \DecValTok{3}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -705,7 +677,7 @@ \subsection{Disparity through time}\label{disparity-through-time}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Print the disparity\_data object} +\DocumentationTok{\#\# Print the disparity\_data object} \NormalTok{disparity\_data} \end{Highlighting} \end{Shaded} @@ -714,7 +686,7 @@ \subsection{Disparity through time}\label{disparity-through-time}} ## ---- dispRity object ---- ## 3 discrete time subsets for 50 elements in one matrix with 48 dimensions with 1 phylogenetic tree ## 133.51 - 89.01, 89.01 - 44.5, 44.5 - 0. -## Data was bootstrapped 100 times (method:"full"). +## Rows were bootstrapped 100 times (method:"full"). ## Disparity was calculated as: metric. \end{verbatim} @@ -724,8 +696,8 @@ \subsection{Disparity through time}\label{disparity-through-time}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Summarising disparity through time} -\KeywordTok{summary}\NormalTok{(disparity\_data)} +\DocumentationTok{\#\# Summarising disparity through time} +\FunctionTok{summary}\NormalTok{(disparity\_data)} \end{Highlighting} \end{Shaded} @@ -738,8 +710,8 @@ \subsection{Disparity through time}\label{disparity-through-time}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Plotting the results} -\KeywordTok{plot}\NormalTok{(disparity\_data, }\DataTypeTok{type =} \StringTok{"continuous"}\NormalTok{)} +\DocumentationTok{\#\# Plotting the results} +\FunctionTok{plot}\NormalTok{(disparity\_data, }\AttributeTok{type =} \StringTok{"continuous"}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -747,10 +719,10 @@ \subsection{Disparity through time}\label{disparity-through-time}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Testing for an difference among the time bins} -\NormalTok{disp\_lm \textless{}{-}}\StringTok{ }\KeywordTok{test.dispRity}\NormalTok{(disparity\_data, }\DataTypeTok{test =}\NormalTok{ lm,} - \DataTypeTok{comparisons =} \StringTok{"all"}\NormalTok{)} -\KeywordTok{summary}\NormalTok{(disp\_lm)} +\DocumentationTok{\#\# Testing for an difference among the time bins} +\NormalTok{disp\_lm }\OtherTok{\textless{}{-}} \FunctionTok{test.dispRity}\NormalTok{(disparity\_data, }\AttributeTok{test =}\NormalTok{ lm,} + \AttributeTok{comparisons =} \StringTok{"all"}\NormalTok{)} +\FunctionTok{summary}\NormalTok{(disp\_lm)} \end{Highlighting} \end{Shaded} @@ -801,13 +773,13 @@ \subsection{Disparity among groups}\label{disparity-among-groups}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Creating the two groups (crown versus stem) as a list} -\NormalTok{mammal\_groups \textless{}{-}}\StringTok{ }\KeywordTok{crown.stem}\NormalTok{(BeckLee\_tree, }\DataTypeTok{inc.nodes =} \OtherTok{FALSE}\NormalTok{)} +\DocumentationTok{\#\# Creating the two groups (crown versus stem) as a list} +\NormalTok{mammal\_groups }\OtherTok{\textless{}{-}} \FunctionTok{crown.stem}\NormalTok{(BeckLee\_tree, }\AttributeTok{inc.nodes =} \ConstantTok{FALSE}\NormalTok{)} -\CommentTok{\#\# Measuring disparity for each group} -\NormalTok{disparity\_data \textless{}{-}}\StringTok{ }\KeywordTok{dispRity.per.group}\NormalTok{(BeckLee\_mat50,} - \DataTypeTok{group =}\NormalTok{ mammal\_groups,} - \DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, variances))} +\DocumentationTok{\#\# Measuring disparity for each group} +\NormalTok{disparity\_data }\OtherTok{\textless{}{-}} \FunctionTok{dispRity.per.group}\NormalTok{(BeckLee\_mat50,} + \AttributeTok{group =}\NormalTok{ mammal\_groups,} + \AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, variances))} \end{Highlighting} \end{Shaded} @@ -815,7 +787,7 @@ \subsection{Disparity among groups}\label{disparity-among-groups}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Print the disparity\_data object} +\DocumentationTok{\#\# Print the disparity\_data object} \NormalTok{disparity\_data} \end{Highlighting} \end{Shaded} @@ -824,14 +796,14 @@ \subsection{Disparity among groups}\label{disparity-among-groups}} ## ---- dispRity object ---- ## 2 customised subsets for 50 elements in one matrix with 48 dimensions: ## crown, stem. -## Data was bootstrapped 100 times (method:"full"). +## Rows were bootstrapped 100 times (method:"full"). ## Disparity was calculated as: metric. \end{verbatim} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Summarising disparity in the different groups} -\KeywordTok{summary}\NormalTok{(disparity\_data)} +\DocumentationTok{\#\# Summarising disparity in the different groups} +\FunctionTok{summary}\NormalTok{(disparity\_data)} \end{Highlighting} \end{Shaded} @@ -843,8 +815,8 @@ \subsection{Disparity among groups}\label{disparity-among-groups}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Plotting the results} -\KeywordTok{plot}\NormalTok{(disparity\_data)} +\DocumentationTok{\#\# Plotting the results} +\FunctionTok{plot}\NormalTok{(disparity\_data)} \end{Highlighting} \end{Shaded} @@ -852,8 +824,8 @@ \subsection{Disparity among groups}\label{disparity-among-groups}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Testing for a difference between the groups} -\KeywordTok{test.dispRity}\NormalTok{(disparity\_data, }\DataTypeTok{test =}\NormalTok{ wilcox.test, }\DataTypeTok{details =} \OtherTok{TRUE}\NormalTok{)} +\DocumentationTok{\#\# Testing for a difference between the groups} +\FunctionTok{test.dispRity}\NormalTok{(disparity\_data, }\AttributeTok{test =}\NormalTok{ wilcox.test, }\AttributeTok{details =} \ConstantTok{TRUE}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -879,11 +851,11 @@ \chapter{Details of specific functions}\label{details-of-specific-functions}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Loading the data} -\KeywordTok{data}\NormalTok{(BeckLee\_mat50)} -\KeywordTok{data}\NormalTok{(BeckLee\_mat99)} -\KeywordTok{data}\NormalTok{(BeckLee\_tree)} -\KeywordTok{data}\NormalTok{(BeckLee\_ages)} +\DocumentationTok{\#\# Loading the data} +\FunctionTok{data}\NormalTok{(BeckLee\_mat50)} +\FunctionTok{data}\NormalTok{(BeckLee\_mat99)} +\FunctionTok{data}\NormalTok{(BeckLee\_tree)} +\FunctionTok{data}\NormalTok{(BeckLee\_ages)} \end{Highlighting} \end{Shaded} @@ -924,10 +896,10 @@ \subsection{Time-binning}\label{time-binning}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Generating three time bins containing the taxa present every 40 Ma} -\KeywordTok{chrono.subsets}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_mat50, }\DataTypeTok{tree =}\NormalTok{ BeckLee\_tree,} - \DataTypeTok{method =} \StringTok{"discrete"}\NormalTok{,} - \DataTypeTok{time =} \KeywordTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{40}\NormalTok{, }\DecValTok{0}\NormalTok{))} +\DocumentationTok{\#\# Generating three time bins containing the taxa present every 40 Ma} +\FunctionTok{chrono.subsets}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_mat50, }\AttributeTok{tree =}\NormalTok{ BeckLee\_tree,} + \AttributeTok{method =} \StringTok{"discrete"}\NormalTok{,} + \AttributeTok{time =} \FunctionTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{40}\NormalTok{, }\DecValTok{0}\NormalTok{))} \end{Highlighting} \end{Shaded} @@ -941,10 +913,10 @@ \subsection{Time-binning}\label{time-binning}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Automatically generate three equal length bins:} -\KeywordTok{chrono.subsets}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_mat50, }\DataTypeTok{tree =}\NormalTok{ BeckLee\_tree,} - \DataTypeTok{method =} \StringTok{"discrete"}\NormalTok{,} - \DataTypeTok{time =} \DecValTok{3}\NormalTok{)} +\DocumentationTok{\#\# Automatically generate three equal length bins:} +\FunctionTok{chrono.subsets}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_mat50, }\AttributeTok{tree =}\NormalTok{ BeckLee\_tree,} + \AttributeTok{method =} \StringTok{"discrete"}\NormalTok{,} + \AttributeTok{time =} \DecValTok{3}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -962,9 +934,9 @@ \subsection{Time-binning}\label{time-binning}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Displaying the table of first and last occurrence dates} -\CommentTok{\#\# for each taxa} -\KeywordTok{head}\NormalTok{(BeckLee\_ages)} +\DocumentationTok{\#\# Displaying the table of first and last occurrence dates} +\DocumentationTok{\#\# for each taxa} +\FunctionTok{head}\NormalTok{(BeckLee\_ages)} \end{Highlighting} \end{Shaded} @@ -980,10 +952,10 @@ \subsection{Time-binning}\label{time-binning}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Generating time bins including taxa that might span between them} -\KeywordTok{chrono.subsets}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_mat50, }\DataTypeTok{tree =}\NormalTok{ BeckLee\_tree,} - \DataTypeTok{method =} \StringTok{"discrete"}\NormalTok{,} - \DataTypeTok{time =} \KeywordTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{40}\NormalTok{, }\DecValTok{0}\NormalTok{), }\DataTypeTok{FADLAD =}\NormalTok{ BeckLee\_ages)} +\DocumentationTok{\#\# Generating time bins including taxa that might span between them} +\FunctionTok{chrono.subsets}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_mat50, }\AttributeTok{tree =}\NormalTok{ BeckLee\_tree,} + \AttributeTok{method =} \StringTok{"discrete"}\NormalTok{,} + \AttributeTok{time =} \FunctionTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{40}\NormalTok{, }\DecValTok{0}\NormalTok{), }\AttributeTok{FADLAD =}\NormalTok{ BeckLee\_ages)} \end{Highlighting} \end{Shaded} @@ -1046,12 +1018,12 @@ \subsection{Time-slicing}\label{time-slicing}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Generating four time slices every 40 million years} -\CommentTok{\#\# under a model of proximity evolution} -\KeywordTok{chrono.subsets}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_mat99, }\DataTypeTok{tree =}\NormalTok{ BeckLee\_tree, } - \DataTypeTok{method =} \StringTok{"continuous"}\NormalTok{, }\DataTypeTok{model =} \StringTok{"proximity"}\NormalTok{,} - \DataTypeTok{time =} \KeywordTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{40}\NormalTok{, }\DecValTok{0}\NormalTok{),} - \DataTypeTok{FADLAD =}\NormalTok{ BeckLee\_ages)} +\DocumentationTok{\#\# Generating four time slices every 40 million years} +\DocumentationTok{\#\# under a model of proximity evolution} +\FunctionTok{chrono.subsets}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_mat99, }\AttributeTok{tree =}\NormalTok{ BeckLee\_tree, } + \AttributeTok{method =} \StringTok{"continuous"}\NormalTok{, }\AttributeTok{model =} \StringTok{"proximity"}\NormalTok{,} + \AttributeTok{time =} \FunctionTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{40}\NormalTok{, }\DecValTok{0}\NormalTok{),} + \AttributeTok{FADLAD =}\NormalTok{ BeckLee\_ages)} \end{Highlighting} \end{Shaded} @@ -1063,10 +1035,10 @@ \subsection{Time-slicing}\label{time-slicing}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Generating four time slices automatically} -\KeywordTok{chrono.subsets}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_mat99, }\DataTypeTok{tree =}\NormalTok{ BeckLee\_tree,} - \DataTypeTok{method =} \StringTok{"continuous"}\NormalTok{, }\DataTypeTok{model =} \StringTok{"proximity"}\NormalTok{,} - \DataTypeTok{time =} \DecValTok{4}\NormalTok{, }\DataTypeTok{FADLAD =}\NormalTok{ BeckLee\_ages)} +\DocumentationTok{\#\# Generating four time slices automatically} +\FunctionTok{chrono.subsets}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_mat99, }\AttributeTok{tree =}\NormalTok{ BeckLee\_tree,} + \AttributeTok{method =} \StringTok{"continuous"}\NormalTok{, }\AttributeTok{model =} \StringTok{"proximity"}\NormalTok{,} + \AttributeTok{time =} \DecValTok{4}\NormalTok{, }\AttributeTok{FADLAD =}\NormalTok{ BeckLee\_ages)} \end{Highlighting} \end{Shaded} @@ -1084,11 +1056,11 @@ \section{Customised subsets}\label{custom-subsets}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Creating the two groups (crown and stems)} -\NormalTok{mammal\_groups \textless{}{-}}\StringTok{ }\KeywordTok{crown.stem}\NormalTok{(BeckLee\_tree, }\DataTypeTok{inc.nodes =} \OtherTok{FALSE}\NormalTok{)} +\DocumentationTok{\#\# Creating the two groups (crown and stems)} +\NormalTok{mammal\_groups }\OtherTok{\textless{}{-}} \FunctionTok{crown.stem}\NormalTok{(BeckLee\_tree, }\AttributeTok{inc.nodes =} \ConstantTok{FALSE}\NormalTok{)} -\CommentTok{\#\# Separating the dataset into two different groups} -\KeywordTok{custom.subsets}\NormalTok{(BeckLee\_mat50, }\DataTypeTok{group =}\NormalTok{ mammal\_groups)} +\DocumentationTok{\#\# Separating the dataset into two different groups} +\FunctionTok{custom.subsets}\NormalTok{(BeckLee\_mat50, }\AttributeTok{group =}\NormalTok{ mammal\_groups)} \end{Highlighting} \end{Shaded} @@ -1103,10 +1075,10 @@ \section{Customised subsets}\label{custom-subsets}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Creating the three groups as a list} -\NormalTok{weird\_groups \textless{}{-}}\StringTok{ }\KeywordTok{list}\NormalTok{(}\StringTok{"even"}\NormalTok{ =}\StringTok{ }\KeywordTok{seq}\NormalTok{(}\DataTypeTok{from =} \DecValTok{1}\NormalTok{, }\DataTypeTok{to =} \DecValTok{49}\NormalTok{, }\DataTypeTok{by =} \DecValTok{2}\NormalTok{),} - \StringTok{"odd"}\NormalTok{ =}\StringTok{ }\KeywordTok{seq}\NormalTok{(}\DataTypeTok{from =} \DecValTok{2}\NormalTok{, }\DataTypeTok{to =} \DecValTok{50}\NormalTok{, }\DataTypeTok{by =} \DecValTok{2}\NormalTok{),} - \StringTok{"all"}\NormalTok{ =}\StringTok{ }\KeywordTok{c}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{50}\NormalTok{))} +\DocumentationTok{\#\# Creating the three groups as a list} +\NormalTok{weird\_groups }\OtherTok{\textless{}{-}} \FunctionTok{list}\NormalTok{(}\StringTok{"even"} \OtherTok{=} \FunctionTok{seq}\NormalTok{(}\AttributeTok{from =} \DecValTok{1}\NormalTok{, }\AttributeTok{to =} \DecValTok{49}\NormalTok{, }\AttributeTok{by =} \DecValTok{2}\NormalTok{),} + \StringTok{"odd"} \OtherTok{=} \FunctionTok{seq}\NormalTok{(}\AttributeTok{from =} \DecValTok{2}\NormalTok{, }\AttributeTok{to =} \DecValTok{50}\NormalTok{, }\AttributeTok{by =} \DecValTok{2}\NormalTok{),} + \StringTok{"all"} \OtherTok{=} \FunctionTok{c}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{50}\NormalTok{))} \end{Highlighting} \end{Shaded} @@ -1114,8 +1086,8 @@ \section{Customised subsets}\label{custom-subsets}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Creating groups as clades} -\KeywordTok{custom.subsets}\NormalTok{(BeckLee\_mat50, }\DataTypeTok{group =}\NormalTok{ BeckLee\_tree)} +\DocumentationTok{\#\# Creating groups as clades} +\FunctionTok{custom.subsets}\NormalTok{(BeckLee\_mat50, }\AttributeTok{group =}\NormalTok{ BeckLee\_tree)} \end{Highlighting} \end{Shaded} @@ -1130,15 +1102,15 @@ \section{Bootstraps and rarefactions}\label{bootstraps-and-rarefactions}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Default bootstrapping} -\KeywordTok{boot.matrix}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_mat50)} +\DocumentationTok{\#\# Default bootstrapping} +\FunctionTok{boot.matrix}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_mat50)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## ---- dispRity object ---- ## 50 elements in one matrix with 48 dimensions. -## Data was bootstrapped 100 times (method:"full"). +## Rows were bootstrapped 100 times (method:"full"). \end{verbatim} The number of bootstrap replicates can be defined using the \texttt{bootstraps} option. @@ -1157,15 +1129,15 @@ \section{Bootstraps and rarefactions}\label{bootstraps-and-rarefactions}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Bootstrapping with the single bootstrap method} -\KeywordTok{boot.matrix}\NormalTok{(BeckLee\_mat50, }\DataTypeTok{boot.type =} \StringTok{"single"}\NormalTok{)} +\DocumentationTok{\#\# Bootstrapping with the single bootstrap method} +\FunctionTok{boot.matrix}\NormalTok{(BeckLee\_mat50, }\AttributeTok{boot.type =} \StringTok{"single"}\NormalTok{)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## ---- dispRity object ---- ## 50 elements in one matrix with 48 dimensions. -## Data was bootstrapped 100 times (method:"single"). +## Rows were bootstrapped 100 times (method:"single"). \end{verbatim} This function also allows users to rarefy the data using the \texttt{rarefaction} argument. @@ -1178,65 +1150,79 @@ \section{Bootstraps and rarefactions}\label{bootstraps-and-rarefactions}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Bootstrapping with the full rarefaction} -\KeywordTok{boot.matrix}\NormalTok{(BeckLee\_mat50, }\DataTypeTok{bootstraps =} \DecValTok{20}\NormalTok{,} - \DataTypeTok{rarefaction =} \OtherTok{TRUE}\NormalTok{)} +\DocumentationTok{\#\# Bootstrapping with the full rarefaction} +\FunctionTok{boot.matrix}\NormalTok{(BeckLee\_mat50, }\AttributeTok{bootstraps =} \DecValTok{20}\NormalTok{,} + \AttributeTok{rarefaction =} \ConstantTok{TRUE}\NormalTok{)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## ---- dispRity object ---- ## 50 elements in one matrix with 48 dimensions. -## Data was bootstrapped 20 times (method:"full") and fully rarefied. +## Rows were bootstrapped 20 times (method:"full") and fully rarefied. \end{verbatim} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Or with a set number of rarefaction levels} -\KeywordTok{boot.matrix}\NormalTok{(BeckLee\_mat50, }\DataTypeTok{bootstraps =} \DecValTok{20}\NormalTok{,} - \DataTypeTok{rarefaction =} \KeywordTok{c}\NormalTok{(}\DecValTok{6}\OperatorTok{:}\DecValTok{8}\NormalTok{, }\DecValTok{3}\NormalTok{))} +\DocumentationTok{\#\# Or with a set number of rarefaction levels} +\FunctionTok{boot.matrix}\NormalTok{(BeckLee\_mat50, }\AttributeTok{bootstraps =} \DecValTok{20}\NormalTok{,} + \AttributeTok{rarefaction =} \FunctionTok{c}\NormalTok{(}\DecValTok{6}\SpecialCharTok{:}\DecValTok{8}\NormalTok{, }\DecValTok{3}\NormalTok{))} \end{Highlighting} \end{Shaded} \begin{verbatim} ## ---- dispRity object ---- ## 50 elements in one matrix with 48 dimensions. -## Data was bootstrapped 20 times (method:"full") and rarefied to 6, 7, 8, 3 elements. +## Rows were bootstrapped 20 times (method:"full") and rarefied to 6, 7, 8, 3 elements. \end{verbatim} \begin{quote} Note that using the \texttt{rarefaction} argument also bootstraps the data. In these examples, the function bootstraps the data (without rarefaction) AND also bootstraps the data with the different rarefaction levels. \end{quote} -One other argument is \texttt{dimensions} that specifies how many dimensions from the matrix should be used for further analysis. -When missing, all dimensions from the ordinated matrix are used. - \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Using the first 50\% of the dimensions} -\KeywordTok{boot.matrix}\NormalTok{(BeckLee\_mat50, }\DataTypeTok{dimensions =} \FloatTok{0.5}\NormalTok{)} +\DocumentationTok{\#\# Creating subsets of crown and stem mammals} +\NormalTok{crown\_stem }\OtherTok{\textless{}{-}} \FunctionTok{custom.subsets}\NormalTok{(BeckLee\_mat50,} + \AttributeTok{group =} \FunctionTok{crown.stem}\NormalTok{(BeckLee\_tree,} + \AttributeTok{inc.nodes =} \ConstantTok{FALSE}\NormalTok{))} +\DocumentationTok{\#\# Bootstrapping and rarefying these groups} +\FunctionTok{boot.matrix}\NormalTok{(crown\_stem, }\AttributeTok{bootstraps =} \DecValTok{200}\NormalTok{, }\AttributeTok{rarefaction =} \ConstantTok{TRUE}\NormalTok{)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## ---- dispRity object ---- -## 50 elements in one matrix with 24 dimensions. -## Data was bootstrapped 100 times (method:"full"). +## 2 customised subsets for 50 elements in one matrix with 48 dimensions: +## crown, stem. +## Rows were bootstrapped 200 times (method:"full") and fully rarefied. \end{verbatim} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Using the first 10 dimensions} -\KeywordTok{boot.matrix}\NormalTok{(BeckLee\_mat50, }\DataTypeTok{dimensions =} \DecValTok{10}\NormalTok{)} +\DocumentationTok{\#\# Creating time slice subsets} +\NormalTok{time\_slices }\OtherTok{\textless{}{-}} \FunctionTok{chrono.subsets}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_mat99,} + \AttributeTok{tree =}\NormalTok{ BeckLee\_tree, } + \AttributeTok{method =} \StringTok{"continuous"}\NormalTok{,} + \AttributeTok{model =} \StringTok{"proximity"}\NormalTok{, } + \AttributeTok{time =} \FunctionTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{40}\NormalTok{, }\DecValTok{0}\NormalTok{),} + \AttributeTok{FADLAD =}\NormalTok{ BeckLee\_ages)} + +\DocumentationTok{\#\# Bootstrapping the time slice subsets} +\FunctionTok{boot.matrix}\NormalTok{(time\_slices, }\AttributeTok{bootstraps =} \DecValTok{100}\NormalTok{)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## ---- dispRity object ---- -## 50 elements in one matrix with 1 dimensions. -## Data was bootstrapped 100 times (method:"full"). +## 4 continuous (proximity) time subsets for 99 elements in one matrix with 97 dimensions with 1 phylogenetic tree +## 120, 80, 40, 0. +## Rows were bootstrapped 100 times (method:"full"). \end{verbatim} +\hypertarget{bootstrapping-with-probabilities}{% +\subsection{Bootstrapping with probabilities}\label{bootstrapping-with-probabilities}} + It is also possible to specify the sampling probability in the bootstrap for each elements. This can be useful for weighting analysis for example (i.e.~giving more importance to specific elements). These probabilities can be passed to the \texttt{prob} argument individually with a vector with the elements names or with a matrix with the rownames as elements names. @@ -1244,60 +1230,69 @@ \section{Bootstraps and rarefactions}\label{bootstraps-and-rarefactions}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Attributing a weight of 0 to Cimolestes and 10 to Maelestes} -\KeywordTok{boot.matrix}\NormalTok{(BeckLee\_mat50,} - \DataTypeTok{prob =} \KeywordTok{c}\NormalTok{(}\StringTok{"Cimolestes"}\NormalTok{ =}\StringTok{ }\DecValTok{0}\NormalTok{, }\StringTok{"Maelestes"}\NormalTok{ =}\StringTok{ }\DecValTok{10}\NormalTok{))} +\DocumentationTok{\#\# Attributing a weight of 0 to Cimolestes and 10 to Maelestes} +\FunctionTok{boot.matrix}\NormalTok{(BeckLee\_mat50,} + \AttributeTok{prob =} \FunctionTok{c}\NormalTok{(}\StringTok{"Cimolestes"} \OtherTok{=} \DecValTok{0}\NormalTok{, }\StringTok{"Maelestes"} \OtherTok{=} \DecValTok{10}\NormalTok{))} \end{Highlighting} \end{Shaded} \begin{verbatim} ## ---- dispRity object ---- ## 50 elements in one matrix with 48 dimensions. -## Data was bootstrapped 100 times (method:"full"). +## Rows were bootstrapped 100 times (method:"full"). \end{verbatim} -Of course, one could directly supply the subsets generated above (using \texttt{chrono.subsets} or \texttt{custom.subsets}) to this function. +\hypertarget{bootstrapping-dimensions}{% +\subsection{Bootstrapping dimensions}\label{bootstrapping-dimensions}} + +In some cases, you might also be interested in bootstrapping dimensions rather than observations. +I.e. bootstrapping the columns of a matrix rather than the rows. + +It's pretty easy! By default, \texttt{boot.matrix} uses the option \texttt{boot.by\ =\ "rows"} which you can toggle to \texttt{boot.by\ =\ "columns"} + +\begin{Shaded} +\begin{Highlighting}[] +\DocumentationTok{\#\# Bootstrapping the observations (default)} +\FunctionTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)} +\NormalTok{boot\_obs }\OtherTok{\textless{}{-}} \FunctionTok{boot.matrix}\NormalTok{(}\AttributeTok{data =}\NormalTok{ crown\_stem, }\AttributeTok{boot.by =} \StringTok{"rows"}\NormalTok{)} + +\DocumentationTok{\#\# Bootstrapping the columns rather than the rows} +\FunctionTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)} +\NormalTok{boot\_dim }\OtherTok{\textless{}{-}} \FunctionTok{boot.matrix}\NormalTok{(}\AttributeTok{data =}\NormalTok{ crown\_stem, }\AttributeTok{boot.by =} \StringTok{"columns"}\NormalTok{)} +\end{Highlighting} +\end{Shaded} + +In these two examples, the first one \texttt{boot\_obs} bootstraps the rows as showed before (default behaviour). +But the second one, \texttt{boot\_dim} bootstraps the dimensions. +That means that for each bootstrap sample, the value calculated is actually obtained by reshuffling the dimensions (columns) rather than the observations (rows). \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Creating subsets of crown and stem mammals} -\NormalTok{crown\_stem \textless{}{-}}\StringTok{ }\KeywordTok{custom.subsets}\NormalTok{(BeckLee\_mat50,} - \DataTypeTok{group =} \KeywordTok{crown.stem}\NormalTok{(BeckLee\_tree,} - \DataTypeTok{inc.nodes =} \OtherTok{FALSE}\NormalTok{))} -\CommentTok{\#\# Bootstrapping and rarefying these groups} -\KeywordTok{boot.matrix}\NormalTok{(crown\_stem, }\DataTypeTok{bootstraps =} \DecValTok{200}\NormalTok{, }\DataTypeTok{rarefaction =} \OtherTok{TRUE}\NormalTok{)} +\DocumentationTok{\#\# Measuring disparity and summarising} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(boot\_obs, }\AttributeTok{metric =}\NormalTok{ sum))} \end{Highlighting} \end{Shaded} \begin{verbatim} -## ---- dispRity object ---- -## 2 customised subsets for 50 elements in one matrix with 48 dimensions: -## crown, stem. -## Data was bootstrapped 200 times (method:"full") and fully rarefied. +## subsets n obs bs.median 2.5% 25% 75% 97.5% +## 1 crown 30 -1.1 -2.04 -19.4 -7.56 3.621 14.64 +## 2 stem 20 1.1 1.52 -10.8 -1.99 6.712 13.97 \end{verbatim} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Creating time slice subsets} -\NormalTok{time\_slices \textless{}{-}}\StringTok{ }\KeywordTok{chrono.subsets}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_mat99,} - \DataTypeTok{tree =}\NormalTok{ BeckLee\_tree, } - \DataTypeTok{method =} \StringTok{"continuous"}\NormalTok{,} - \DataTypeTok{model =} \StringTok{"proximity"}\NormalTok{, } - \DataTypeTok{time =} \KeywordTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{40}\NormalTok{, }\DecValTok{0}\NormalTok{),} - \DataTypeTok{FADLAD =}\NormalTok{ BeckLee\_ages)} - -\CommentTok{\#\# Bootstrapping the time slice subsets} -\KeywordTok{boot.matrix}\NormalTok{(time\_slices, }\DataTypeTok{bootstraps =} \DecValTok{100}\NormalTok{)} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(boot\_dim, }\AttributeTok{metric =}\NormalTok{ sum))} \end{Highlighting} \end{Shaded} \begin{verbatim} -## ---- dispRity object ---- -## 4 continuous (proximity) time subsets for 99 elements in one matrix with 97 dimensions with 1 phylogenetic tree -## 120, 80, 40, 0. -## Data was bootstrapped 100 times (method:"full"). +## subsets n obs bs.median 2.5% 25% 75% 97.5% +## 1 crown 30 -1.1 -2.04 -18.5 -8.84 5.440 19.80 +## 2 stem 20 1.1 1.31 -16.7 -2.99 6.338 14.99 \end{verbatim} +Note here how the observed sum is the same (no bootstrapping) but the bootstrapping distributions are quiet different even though the same seed was used. + \hypertarget{disparity-metrics}{% \section{Disparity metrics}\label{disparity-metrics}} @@ -1344,26 +1339,26 @@ \subsubsection{Dimension-level 1 functions}\label{dimension-level-1-functions}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Creating a dummy matrix} -\NormalTok{dummy\_matrix \textless{}{-}}\StringTok{ }\KeywordTok{matrix}\NormalTok{(}\KeywordTok{rnorm}\NormalTok{(}\DecValTok{12}\NormalTok{), }\DecValTok{4}\NormalTok{, }\DecValTok{3}\NormalTok{)} +\DocumentationTok{\#\# Creating a dummy matrix} +\NormalTok{dummy\_matrix }\OtherTok{\textless{}{-}} \FunctionTok{matrix}\NormalTok{(}\FunctionTok{rnorm}\NormalTok{(}\DecValTok{12}\NormalTok{), }\DecValTok{4}\NormalTok{, }\DecValTok{3}\NormalTok{)} -\CommentTok{\#\# Example of dimension{-}level 1 functions} -\KeywordTok{mean}\NormalTok{(dummy\_matrix)} +\DocumentationTok{\#\# Example of dimension{-}level 1 functions} +\FunctionTok{mean}\NormalTok{(dummy\_matrix)} \end{Highlighting} \end{Shaded} \begin{verbatim} -## [1] 0.1012674 +## [1] -0.183358 \end{verbatim} \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{median}\NormalTok{(dummy\_matrix)} +\FunctionTok{median}\NormalTok{(dummy\_matrix)} \end{Highlighting} \end{Shaded} \begin{verbatim} -## [1] 0.3345108 +## [1] -0.3909538 \end{verbatim} Any summary metric such as mean or median are good examples of dimension-level 1 functions as they reduce the matrix to a single dimension (i.e.~one value). @@ -1375,16 +1370,16 @@ \subsubsection{Dimension-level 2 functions}\label{dimension-level-2-functions}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Defining the function as the product of rows} -\NormalTok{prod.rows \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(matrix) }\KeywordTok{apply}\NormalTok{(matrix, }\DecValTok{1}\NormalTok{, prod)} +\DocumentationTok{\#\# Defining the function as the product of rows} +\NormalTok{prod.rows }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(matrix) }\FunctionTok{apply}\NormalTok{(matrix, }\DecValTok{1}\NormalTok{, prod)} -\CommentTok{\#\# A dimension{-}level 2 metric} -\KeywordTok{prod.rows}\NormalTok{(dummy\_matrix)} +\DocumentationTok{\#\# A dimension{-}level 2 metric} +\FunctionTok{prod.rows}\NormalTok{(dummy\_matrix)} \end{Highlighting} \end{Shaded} \begin{verbatim} -## [1] 0.72217818 2.48612354 -0.08986575 0.58266449 +## [1] 0.63727584 -0.09516528 -1.24477435 -0.10958022 \end{verbatim} Several dimension-level 2 functions are implemented in \texttt{dispRity} (see \texttt{?dispRity.metric}) such as the \texttt{variances} or \texttt{ranges} functions that calculate the variance or the range of each dimension of the ordinated matrix respectively. @@ -1397,31 +1392,31 @@ \subsubsection{Dimension-level 3 functions}\label{dimension-level-3-functions}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# A dimension{-}level 3 metric} -\KeywordTok{var}\NormalTok{(dummy\_matrix)} +\DocumentationTok{\#\# A dimension{-}level 3 metric} +\FunctionTok{var}\NormalTok{(dummy\_matrix)} \end{Highlighting} \end{Shaded} \begin{verbatim} -## [,1] [,2] [,3] -## [1,] 1.8570383 0.7417569 -0.5131686 -## [2,] 0.7417569 1.3194330 -1.5344429 -## [3,] -0.5131686 -1.5344429 2.8070556 +## [,1] [,2] [,3] +## [1,] 0.6356714 -0.2017617 0.2095042 +## [2,] -0.2017617 1.3656124 1.0850900 +## [3,] 0.2095042 1.0850900 1.0879400 \end{verbatim} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# A dimension{-}level 3 metric with a forced matrix output} -\KeywordTok{as.matrix}\NormalTok{(}\KeywordTok{dist}\NormalTok{(dummy\_matrix))} +\DocumentationTok{\#\# A dimension{-}level 3 metric with a forced matrix output} +\FunctionTok{as.matrix}\NormalTok{(}\FunctionTok{dist}\NormalTok{(dummy\_matrix))} \end{Highlighting} \end{Shaded} \begin{verbatim} ## 1 2 3 4 -## 1 0.000000 4.794738 3.382990 3.297110 -## 2 4.794738 0.000000 2.400321 3.993864 -## 3 3.382990 2.400321 0.000000 2.187412 -## 4 3.297110 3.993864 2.187412 0.000000 +## 1 0.000000 1.390687 2.156388 2.984951 +## 2 1.390687 0.000000 2.557670 1.602143 +## 3 2.156388 2.557670 0.000000 3.531033 +## 4 2.984951 1.602143 3.531033 0.000000 \end{verbatim} \hypertarget{betweengroupmetricsexplain}{% @@ -1435,9 +1430,9 @@ \subsection{Between groups metrics}\label{betweengroupmetricsexplain}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# A simple example} -\NormalTok{mean.difference \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(matrix, matrix2) \{} - \KeywordTok{mean}\NormalTok{(matrix) }\OperatorTok{{-}}\StringTok{ }\KeywordTok{mean}\NormalTok{(matrix2)} +\DocumentationTok{\#\# A simple example} +\NormalTok{mean.difference }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(matrix, matrix2) \{} + \FunctionTok{mean}\NormalTok{(matrix) }\SpecialCharTok{{-}} \FunctionTok{mean}\NormalTok{(matrix2)} \NormalTok{\}} \end{Highlighting} \end{Shaded} @@ -1448,16 +1443,16 @@ \subsection{Between groups metrics}\label{betweengroupmetricsexplain}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# A second matrix} -\NormalTok{dummy\_matrix2 \textless{}{-}}\StringTok{ }\KeywordTok{matrix}\NormalTok{(}\KeywordTok{runif}\NormalTok{(}\DecValTok{12}\NormalTok{), }\DecValTok{4}\NormalTok{, }\DecValTok{3}\NormalTok{)} +\DocumentationTok{\#\# A second matrix} +\NormalTok{dummy\_matrix2 }\OtherTok{\textless{}{-}} \FunctionTok{matrix}\NormalTok{(}\FunctionTok{runif}\NormalTok{(}\DecValTok{12}\NormalTok{), }\DecValTok{4}\NormalTok{, }\DecValTok{3}\NormalTok{)} -\CommentTok{\#\# The difference between groups} -\KeywordTok{mean.difference}\NormalTok{(dummy\_matrix, dummy\_matrix2)} +\DocumentationTok{\#\# The difference between groups} +\FunctionTok{mean.difference}\NormalTok{(dummy\_matrix, dummy\_matrix2)} \end{Highlighting} \end{Shaded} \begin{verbatim} -## [1] -0.3194556 +## [1] -0.5620336 \end{verbatim} Beyond this super simple example, it might probably be interesting to use this metric on \texttt{dispRity} objects, especially the ones from \protect\hyperlink{custom-subsets}{\texttt{custom.subsets}} and \protect\hyperlink{chrono-subsets}{\texttt{chrono.subsets}}. @@ -1466,18 +1461,18 @@ \subsection{Between groups metrics}\label{betweengroupmetricsexplain}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Combining both matrices} -\NormalTok{big\_matrix \textless{}{-}}\StringTok{ }\KeywordTok{rbind}\NormalTok{(dummy\_matrix, dummy\_matrix2)} -\KeywordTok{rownames}\NormalTok{(big\_matrix) \textless{}{-}}\StringTok{ }\DecValTok{1}\OperatorTok{:}\DecValTok{8} +\DocumentationTok{\#\# Combining both matrices} +\NormalTok{big\_matrix }\OtherTok{\textless{}{-}} \FunctionTok{rbind}\NormalTok{(dummy\_matrix, dummy\_matrix2)} +\FunctionTok{rownames}\NormalTok{(big\_matrix) }\OtherTok{\textless{}{-}} \DecValTok{1}\SpecialCharTok{:}\DecValTok{8} -\CommentTok{\#\# Making a dispRity object with both groups} -\NormalTok{grouped\_matrix \textless{}{-}}\StringTok{ }\KeywordTok{custom.subsets}\NormalTok{(big\_matrix,} - \DataTypeTok{group =} \KeywordTok{c}\NormalTok{(}\KeywordTok{list}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{4}\NormalTok{), }\KeywordTok{list}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{4}\NormalTok{)))} +\DocumentationTok{\#\# Making a dispRity object with both groups} +\NormalTok{grouped\_matrix }\OtherTok{\textless{}{-}} \FunctionTok{custom.subsets}\NormalTok{(big\_matrix,} + \AttributeTok{group =} \FunctionTok{c}\NormalTok{(}\FunctionTok{list}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{4}\NormalTok{), }\FunctionTok{list}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{4}\NormalTok{)))} -\CommentTok{\#\# Calculating the mean difference between groups} -\NormalTok{(mean\_differences \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(grouped\_matrix,} - \DataTypeTok{metric =}\NormalTok{ mean.difference,} - \DataTypeTok{between.groups =} \OtherTok{TRUE}\NormalTok{))} +\DocumentationTok{\#\# Calculating the mean difference between groups} +\NormalTok{(mean\_differences }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(grouped\_matrix,} + \AttributeTok{metric =}\NormalTok{ mean.difference,} + \AttributeTok{between.groups =} \ConstantTok{TRUE}\NormalTok{))} \end{Highlighting} \end{Shaded} @@ -1490,8 +1485,8 @@ \subsection{Between groups metrics}\label{betweengroupmetricsexplain}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Summarising the object} -\KeywordTok{summary}\NormalTok{(mean\_differences)} +\DocumentationTok{\#\# Summarising the object} +\FunctionTok{summary}\NormalTok{(mean\_differences)} \end{Highlighting} \end{Shaded} @@ -1502,8 +1497,8 @@ \subsection{Between groups metrics}\label{betweengroupmetricsexplain}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Note how the summary table now indicates} -\CommentTok{\#\# the number of elements for each group} +\DocumentationTok{\#\# Note how the summary table now indicates} +\DocumentationTok{\#\# the number of elements for each group} \end{Highlighting} \end{Shaded} @@ -1512,27 +1507,27 @@ \subsection{Between groups metrics}\label{betweengroupmetricsexplain}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# A dispRity object with multiple groups} -\NormalTok{grouped\_matrix \textless{}{-}}\StringTok{ }\KeywordTok{custom.subsets}\NormalTok{(big\_matrix,} - \DataTypeTok{group =} \KeywordTok{c}\NormalTok{(}\StringTok{"A"}\NormalTok{ =}\StringTok{ }\KeywordTok{list}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{4}\NormalTok{),} - \StringTok{"B"}\NormalTok{ =}\StringTok{ }\KeywordTok{list}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{4}\NormalTok{),} - \StringTok{"C"}\NormalTok{ =}\StringTok{ }\KeywordTok{list}\NormalTok{(}\DecValTok{2}\OperatorTok{:}\DecValTok{6}\NormalTok{), } - \StringTok{"D"}\NormalTok{ =}\StringTok{ }\KeywordTok{list}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{8}\NormalTok{)))} +\DocumentationTok{\#\# A dispRity object with multiple groups} +\NormalTok{grouped\_matrix }\OtherTok{\textless{}{-}} \FunctionTok{custom.subsets}\NormalTok{(big\_matrix,} + \AttributeTok{group =} \FunctionTok{c}\NormalTok{(}\StringTok{"A"} \OtherTok{=} \FunctionTok{list}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{4}\NormalTok{),} + \StringTok{"B"} \OtherTok{=} \FunctionTok{list}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{4}\NormalTok{),} + \StringTok{"C"} \OtherTok{=} \FunctionTok{list}\NormalTok{(}\DecValTok{2}\SpecialCharTok{:}\DecValTok{6}\NormalTok{), } + \StringTok{"D"} \OtherTok{=} \FunctionTok{list}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{8}\NormalTok{)))} -\CommentTok{\#\# Measuring disparity between all groups} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(grouped\_matrix, }\DataTypeTok{metric =}\NormalTok{ mean.difference,} - \DataTypeTok{between.groups =} \OtherTok{TRUE}\NormalTok{))} +\DocumentationTok{\#\# Measuring disparity between all groups} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(grouped\_matrix, }\AttributeTok{metric =}\NormalTok{ mean.difference,} + \AttributeTok{between.groups =} \ConstantTok{TRUE}\NormalTok{))} \end{Highlighting} \end{Shaded} \begin{verbatim} ## subsets n_1 n_2 obs ## 1 A:B 4 4 0.000 -## 2 A:C 4 5 -0.172 -## 3 A:D 4 8 -0.160 -## 4 B:C 4 5 -0.172 -## 5 B:D 4 8 -0.160 -## 6 C:D 5 8 0.012 +## 2 A:C 4 5 -0.269 +## 3 A:D 4 8 -0.281 +## 4 B:C 4 5 -0.269 +## 5 B:D 4 8 -0.281 +## 6 C:D 5 8 -0.012 \end{verbatim} For \texttt{dispRity} objects generated by \texttt{chrono.subsets} (not shown here), the \texttt{dispRity} function will by default apply the metric on the groups in a serial way (group 1 vs.~group 2, group 2 vs.~group 3, group 3 vs.~group 4, etc\ldots). @@ -1540,17 +1535,17 @@ \subsection{Between groups metrics}\label{betweengroupmetricsexplain}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Measuring disparity between specific groups} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(grouped\_matrix, }\DataTypeTok{metric =}\NormalTok{ mean.difference,} - \DataTypeTok{between.groups =} \KeywordTok{list}\NormalTok{(}\KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{3}\NormalTok{), }\KeywordTok{c}\NormalTok{(}\DecValTok{3}\NormalTok{,}\DecValTok{1}\NormalTok{), }\KeywordTok{c}\NormalTok{(}\DecValTok{4}\NormalTok{,}\DecValTok{1}\NormalTok{))))} +\DocumentationTok{\#\# Measuring disparity between specific groups} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(grouped\_matrix, }\AttributeTok{metric =}\NormalTok{ mean.difference,} + \AttributeTok{between.groups =} \FunctionTok{list}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{3}\NormalTok{), }\FunctionTok{c}\NormalTok{(}\DecValTok{3}\NormalTok{,}\DecValTok{1}\NormalTok{), }\FunctionTok{c}\NormalTok{(}\DecValTok{4}\NormalTok{,}\DecValTok{1}\NormalTok{))))} \end{Highlighting} \end{Shaded} \begin{verbatim} ## subsets n_1 n_2 obs -## 1 A:C 4 5 -0.172 -## 2 C:A 5 4 0.172 -## 3 D:A 8 4 0.160 +## 1 A:C 4 5 -0.269 +## 2 C:A 5 4 0.269 +## 3 D:A 8 4 0.281 \end{verbatim} Note that in any case, the order of the comparison can matter. @@ -1578,9 +1573,9 @@ \subsection{\texorpdfstring{\texttt{make.metric}}{make.metric}}\label{makemetric \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Which dimension{-}level is the mean function?} -\CommentTok{\#\# And can it be used in dispRity?} -\KeywordTok{make.metric}\NormalTok{(mean)} +\DocumentationTok{\#\# Which dimension{-}level is the mean function?} +\DocumentationTok{\#\# And can it be used in dispRity?} +\FunctionTok{make.metric}\NormalTok{(mean)} \end{Highlighting} \end{Shaded} @@ -1591,9 +1586,9 @@ \subsection{\texorpdfstring{\texttt{make.metric}}{make.metric}}\label{makemetric \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Which dimension{-}level is the prod.rows function?} -\CommentTok{\#\# And can it be used in dispRity?} -\KeywordTok{make.metric}\NormalTok{(prod.rows)} +\DocumentationTok{\#\# Which dimension{-}level is the prod.rows function?} +\DocumentationTok{\#\# And can it be used in dispRity?} +\FunctionTok{make.metric}\NormalTok{(prod.rows)} \end{Highlighting} \end{Shaded} @@ -1604,9 +1599,9 @@ \subsection{\texorpdfstring{\texttt{make.metric}}{make.metric}}\label{makemetric \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Which dimension{-}level is the var function?} -\CommentTok{\#\# And can it be used in dispRity?} -\KeywordTok{make.metric}\NormalTok{(var)} +\DocumentationTok{\#\# Which dimension{-}level is the var function?} +\DocumentationTok{\#\# And can it be used in dispRity?} +\FunctionTok{make.metric}\NormalTok{(var)} \end{Highlighting} \end{Shaded} @@ -1621,13 +1616,13 @@ \subsection{\texorpdfstring{\texttt{make.metric}}{make.metric}}\label{makemetric \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Testing whether mean is dimension{-}level 1} -\ControlFlowTok{if}\NormalTok{(}\KeywordTok{make.metric}\NormalTok{(mean, }\DataTypeTok{silent =} \OtherTok{TRUE}\NormalTok{)}\OperatorTok{$}\NormalTok{type }\OperatorTok{!=}\StringTok{ "level1"}\NormalTok{) \{} - \KeywordTok{message}\NormalTok{(}\StringTok{"The metric is not dimension{-}level 1."}\NormalTok{)} +\DocumentationTok{\#\# Testing whether mean is dimension{-}level 1} +\ControlFlowTok{if}\NormalTok{(}\FunctionTok{make.metric}\NormalTok{(mean, }\AttributeTok{silent =} \ConstantTok{TRUE}\NormalTok{)}\SpecialCharTok{$}\NormalTok{type }\SpecialCharTok{!=} \StringTok{"level1"}\NormalTok{) \{} + \FunctionTok{message}\NormalTok{(}\StringTok{"The metric is not dimension{-}level 1."}\NormalTok{)} \NormalTok{\}} -\CommentTok{\#\# Testing whether var is dimension{-}level 1} -\ControlFlowTok{if}\NormalTok{(}\KeywordTok{make.metric}\NormalTok{(var, }\DataTypeTok{silent =} \OtherTok{TRUE}\NormalTok{)}\OperatorTok{$}\NormalTok{type }\OperatorTok{!=}\StringTok{ "level1"}\NormalTok{) \{} - \KeywordTok{message}\NormalTok{(}\StringTok{"The metric is not dimension{-}level 1."}\NormalTok{)} +\DocumentationTok{\#\# Testing whether var is dimension{-}level 1} +\ControlFlowTok{if}\NormalTok{(}\FunctionTok{make.metric}\NormalTok{(var, }\AttributeTok{silent =} \ConstantTok{TRUE}\NormalTok{)}\SpecialCharTok{$}\NormalTok{type }\SpecialCharTok{!=} \StringTok{"level1"}\NormalTok{) \{} + \FunctionTok{message}\NormalTok{(}\StringTok{"The metric is not dimension{-}level 1."}\NormalTok{)} \NormalTok{\}} \end{Highlighting} \end{Shaded} @@ -1643,10 +1638,10 @@ \subsection{\texorpdfstring{Metrics in the \texttt{dispRity} function}{Metrics i \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Measuring disparity as the standard deviation} -\CommentTok{\#\# of all the values of the} -\CommentTok{\#\# ordinated matrix (dimension{-}level 1 function).} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(BeckLee\_mat50, }\DataTypeTok{metric =}\NormalTok{ sd))} +\DocumentationTok{\#\# Measuring disparity as the standard deviation} +\DocumentationTok{\#\# of all the values of the} +\DocumentationTok{\#\# ordinated matrix (dimension{-}level 1 function).} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(BeckLee\_mat50, }\AttributeTok{metric =}\NormalTok{ sd))} \end{Highlighting} \end{Shaded} @@ -1657,10 +1652,10 @@ \subsection{\texorpdfstring{Metrics in the \texttt{dispRity} function}{Metrics i \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Measuring disparity as the standard deviation} -\CommentTok{\#\# of the variance of each axis of} -\CommentTok{\#\# the ordinated matrix (dimension{-}level 1 and 2 functions).} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(BeckLee\_mat50, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sd, variances)))} +\DocumentationTok{\#\# Measuring disparity as the standard deviation} +\DocumentationTok{\#\# of the variance of each axis of} +\DocumentationTok{\#\# the ordinated matrix (dimension{-}level 1 and 2 functions).} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(BeckLee\_mat50, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sd, variances)))} \end{Highlighting} \end{Shaded} @@ -1671,10 +1666,10 @@ \subsection{\texorpdfstring{Metrics in the \texttt{dispRity} function}{Metrics i \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Measuring disparity as the standard deviation} -\CommentTok{\#\# of the variance of each axis of} -\CommentTok{\#\# the variance covariance matrix (dimension{-}level 1, 2 and 3 functions).} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(BeckLee\_mat50, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sd, variances, var)), }\DataTypeTok{round =} \DecValTok{10}\NormalTok{)} +\DocumentationTok{\#\# Measuring disparity as the standard deviation} +\DocumentationTok{\#\# of the variance of each axis of} +\DocumentationTok{\#\# the variance covariance matrix (dimension{-}level 1, 2 and 3 functions).} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(BeckLee\_mat50, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sd, variances, var)), }\AttributeTok{round =} \DecValTok{10}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -1687,19 +1682,19 @@ \subsection{\texorpdfstring{Metrics in the \texttt{dispRity} function}{Metrics i \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Disparity as the standard deviation of the variance of each axis of the} -\CommentTok{\#\# variance covariance matrix:} -\NormalTok{disparity1 \textless{}{-}}\StringTok{ }\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(BeckLee\_mat50,} - \DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sd, variances, var)),} - \DataTypeTok{round =} \DecValTok{10}\NormalTok{)} +\DocumentationTok{\#\# Disparity as the standard deviation of the variance of each axis of the} +\DocumentationTok{\#\# variance covariance matrix:} +\NormalTok{disparity1 }\OtherTok{\textless{}{-}} \FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(BeckLee\_mat50,} + \AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sd, variances, var)),} + \AttributeTok{round =} \DecValTok{10}\NormalTok{)} -\CommentTok{\#\# Same as above but using a different function order for the metric argument} -\NormalTok{disparity2 \textless{}{-}}\StringTok{ }\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(BeckLee\_mat50,} - \DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(variances, sd, var)),} - \DataTypeTok{round =} \DecValTok{10}\NormalTok{)} +\DocumentationTok{\#\# Same as above but using a different function order for the metric argument} +\NormalTok{disparity2 }\OtherTok{\textless{}{-}} \FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(BeckLee\_mat50,} + \AttributeTok{metric =} \FunctionTok{c}\NormalTok{(variances, sd, var)),} + \AttributeTok{round =} \DecValTok{10}\NormalTok{)} -\CommentTok{\#\# Both ways output the same disparity values:} -\NormalTok{disparity1 }\OperatorTok{==}\StringTok{ }\NormalTok{disparity2} +\DocumentationTok{\#\# Both ways output the same disparity values:} +\NormalTok{disparity1 }\SpecialCharTok{==}\NormalTok{ disparity2} \end{Highlighting} \end{Shaded} @@ -1718,272 +1713,54 @@ \subsection{\texorpdfstring{Metrics implemented in \texttt{dispRity}}{Metrics im Several disparity metrics are implemented in the \texttt{dispRity} package. The detailed list can be found in \texttt{?dispRity.metric} along with some description of each metric. -\begin{longtable}[]{@{}llll@{}} -\toprule -\begin{minipage}[b]{0.07\columnwidth}\raggedright -Level\strut -\end{minipage} & \begin{minipage}[b]{0.07\columnwidth}\raggedright -Name\strut -\end{minipage} & \begin{minipage}[b]{0.64\columnwidth}\raggedright -Description\strut -\end{minipage} & \begin{minipage}[b]{0.10\columnwidth}\raggedright -Source\strut -\end{minipage}\tabularnewline -\midrule +\begin{longtable}[]{@{} + >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.0845}} + >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.0845}} + >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.7183}} + >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1127}}@{}} +\toprule\noalign{} +\begin{minipage}[b]{\linewidth}\raggedright +Level +\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright +Name +\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright +Description +\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright +Source +\end{minipage} \\ +\midrule\noalign{} \endhead -\begin{minipage}[t]{0.07\columnwidth}\raggedright -2\strut -\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright -\texttt{ancestral.dist}\strut -\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright -The distance between an element and its ancestor\strut -\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright -\texttt{dispRity}\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.07\columnwidth}\raggedright -2\strut -\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright -\texttt{angles}\strut -\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright -The angle of main variation of each dimensions\strut -\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright -\texttt{dispRity}\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.07\columnwidth}\raggedright -2\strut -\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright -\texttt{centroids}1\strut -\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright -The distance between each element and the centroid of the ordinated space\strut -\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright -\texttt{dispRity}\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.07\columnwidth}\raggedright -1\strut -\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright -\texttt{convhull.surface}\strut -\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright -The surface of the convex hull formed by all the elements\strut -\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright -\href{https://cran.r-project.org/web/packages/geometry/index.html}{\texttt{geometry}}\texttt{::convhulln\$area}\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.07\columnwidth}\raggedright -1\strut -\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright -\texttt{convhull.volume}\strut -\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright -The volume of the convex hull formed by all the elements\strut -\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright -\href{https://cran.r-project.org/web/packages/geometry/index.html}{\texttt{geometry}}\texttt{::convhulln\$vol}\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.07\columnwidth}\raggedright -2\strut -\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright -\texttt{deviations}\strut -\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright -The minimal distance between each element and a hyperplane\strut -\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright -\texttt{dispRity}\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.07\columnwidth}\raggedright -1\strut -\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright -\texttt{diagonal}\strut -\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright -The longest distance in the ordinated space (like the diagonal in two dimensions)\strut -\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright -\texttt{dispRity}\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.07\columnwidth}\raggedright -1\strut -\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright -\texttt{disalignment}\strut -\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright -The rejection of the centroid of a matrix from the major axis of another (typically an \texttt{"as.covar"} metric)\strut -\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright -\texttt{dispRity}\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.07\columnwidth}\raggedright -2\strut -\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright -\texttt{displacements}\strut -\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright -The ratio between the distance from a reference and the distance from the centroid\strut -\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright -\texttt{dispRity}\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.07\columnwidth}\raggedright -1\strut -\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright -\texttt{edge.length.tree}\strut -\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright -The edge lengths of the elements on a tree\strut -\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright -\texttt{ape}\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.07\columnwidth}\raggedright -1\strut -\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright -\texttt{ellipsoid.volume}1\strut -\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright -The volume of the ellipsoid of the space\strut -\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright -Donohue \emph{et al.} (2013)\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.07\columnwidth}\raggedright -1\strut -\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright -\texttt{func.div}\strut -\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright -The functional divergence (the ratio of deviation from the centroid)\strut -\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright -\texttt{dispRity} (similar to \href{https://cran.r-project.org/web/packages/FD/index.html}{\texttt{FD}}\texttt{::dbFD\$FDiv} but without abundance)\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.07\columnwidth}\raggedright -1\strut -\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright -\texttt{func.eve}\strut -\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright -The functional evenness (the minimal spanning tree distances evenness)\strut -\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright -\texttt{dispRity} (similar to \href{https://cran.r-project.org/web/packages/FD/index.html}{\texttt{FD}}\texttt{::dbFD\$FEve} but without abundance)\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.07\columnwidth}\raggedright -1\strut -\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright -\texttt{group.dist}\strut -\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright -The distance between two groups\strut -\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright -\texttt{dispRity}\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.07\columnwidth}\raggedright -1\strut -\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright -\texttt{mode.val}\strut -\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright -The modal value\strut -\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright -\texttt{dispRity}\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.07\columnwidth}\raggedright -1\strut -\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright -\texttt{n.ball.volume}\strut -\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright -The hyper-spherical (\emph{n}-ball) volume\strut -\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright -\texttt{dispRity}\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.07\columnwidth}\raggedright -2\strut -\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright -\texttt{neighbours}\strut -\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright -The distance to specific neighbours (e.g.~the nearest neighbours - by default)\strut -\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright -\texttt{dispRity}\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.07\columnwidth}\raggedright -2\strut -\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright -\texttt{pairwise.dist}\strut -\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright -The pairwise distances between elements\strut -\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright -\href{https://cran.r-project.org/web/packages/vegan/index.html}{\texttt{vegan}}\texttt{::vegist}\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.07\columnwidth}\raggedright -2\strut -\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright -\texttt{point.dist}\strut -\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright -The distance between one group and the point of another group\strut -\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright -\texttt{dispRity}\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.07\columnwidth}\raggedright -2\strut -\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright -\texttt{projections}\strut -\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright -The distance \emph{on} (projection) or \emph{from} (rejection) an arbitrary vector\strut -\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright -\texttt{dispRity}\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.07\columnwidth}\raggedright -1\strut -\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright -\texttt{projections.between}\strut -\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright -\texttt{projections} metric applied between groups\strut -\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright -\texttt{dispRity}\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.07\columnwidth}\raggedright -2\strut -\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright -\texttt{projections.tree}\strut -\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright -The \texttt{projections} metric but where the vector can be based on a tree\strut -\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright -\texttt{dispRity}\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.07\columnwidth}\raggedright -2\strut -\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright -\texttt{quantiles}\strut -\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright -The \emph{n}th quantile range per axis\strut -\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright -\texttt{dispRity}\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.07\columnwidth}\raggedright -2\strut -\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright -\texttt{radius}\strut -\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright -The radius of each dimensions\strut -\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright -\texttt{dispRity}\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.07\columnwidth}\raggedright -2\strut -\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright -\texttt{ranges}\strut -\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright -The range of each dimension\strut -\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright -\texttt{dispRity}\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.07\columnwidth}\raggedright -1\strut -\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright -\texttt{roundness}\strut -\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright -The integral of the ranked scaled eigenvalues of a variance-covariance matrix\strut -\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright -\texttt{dispRity}\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.07\columnwidth}\raggedright -2\strut -\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright -\texttt{span.tree.length}\strut -\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright -The minimal spanning tree length\strut -\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright -\href{https://cran.r-project.org/web/packages/vegan/index.html}{\texttt{vegan}}\texttt{::spantree}\strut -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.07\columnwidth}\raggedright -2\strut -\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright -\texttt{variances}\strut -\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright -The variance of each dimension\strut -\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright -\texttt{dispRity}\strut -\end{minipage}\tabularnewline -\bottomrule +\bottomrule\noalign{} +\endlastfoot +2 & \texttt{ancestral.dist} & The distance between an element and its ancestor & \texttt{dispRity} \\ +2 & \texttt{angles} & The angle of main variation of each dimensions & \texttt{dispRity} \\ +2 & \texttt{centroids}1 & The distance between each element and the centroid of the ordinated space & \texttt{dispRity} \\ +1 & \texttt{convhull.surface} & The surface of the convex hull formed by all the elements & \href{https://cran.r-project.org/web/packages/geometry/index.html}{\texttt{geometry}}\texttt{::convhulln\$area} \\ +1 & \texttt{convhull.volume} & The volume of the convex hull formed by all the elements & \href{https://cran.r-project.org/web/packages/geometry/index.html}{\texttt{geometry}}\texttt{::convhulln\$vol} \\ +2 & \texttt{count.neighbours} & The number of neigbhours to each element in a specified radius & \texttt{dispRity} \\ +2 & \texttt{deviations} & The minimal distance between each element and a hyperplane & \texttt{dispRity} \\ +1 & \texttt{diagonal} & The longest distance in the ordinated space (like the diagonal in two dimensions) & \texttt{dispRity} \\ +1 & \texttt{disalignment} & The rejection of the centroid of a matrix from the major axis of another (typically an \texttt{"as.covar"} metric) & \texttt{dispRity} \\ +2 & \texttt{displacements} & The ratio between the distance from a reference and the distance from the centroid & \texttt{dispRity} \\ +1 & \texttt{edge.length.tree} & The edge lengths of the elements on a tree & \texttt{ape} \\ +1 & \texttt{ellipsoid.volume}1 & The volume of the ellipsoid of the space & Donohue \emph{et al.} (2013) \\ +1 & \texttt{func.div} & The functional divergence (the ratio of deviation from the centroid) & \texttt{dispRity} (similar to \href{https://cran.r-project.org/web/packages/FD/index.html}{\texttt{FD}}\texttt{::dbFD\$FDiv} but without abundance) \\ +1 & \texttt{func.eve} & The functional evenness (the minimal spanning tree distances evenness) & \texttt{dispRity} (similar to \href{https://cran.r-project.org/web/packages/FD/index.html}{\texttt{FD}}\texttt{::dbFD\$FEve} but without abundance) \\ +1 & \texttt{group.dist} & The distance between two groups & \texttt{dispRity} \\ +1 & \texttt{mode.val} & The modal value & \texttt{dispRity} \\ +1 & \texttt{n.ball.volume} & The hyper-spherical (\emph{n}-ball) volume & \texttt{dispRity} \\ +2 & \texttt{neighbours} & The distance to specific neighbours (e.g.~the nearest neighbours - by default) & \texttt{dispRity} \\ +2 & \texttt{pairwise.dist} & The pairwise distances between elements & \href{https://cran.r-project.org/web/packages/vegan/index.html}{\texttt{vegan}}\texttt{::vegist} \\ +2 & \texttt{point.dist} & The distance between one group and the point of another group & \texttt{dispRity} \\ +2 & \texttt{projections} & The distance \emph{on} (projection) or \emph{from} (rejection) an arbitrary vector & \texttt{dispRity} \\ +1 & \texttt{projections.between} & \texttt{projections} metric applied between groups & \texttt{dispRity} \\ +2 & \texttt{projections.tree} & The \texttt{projections} metric but where the vector can be based on a tree & \texttt{dispRity} \\ +2 & \texttt{quantiles} & The \emph{n}th quantile range per axis & \texttt{dispRity} \\ +2 & \texttt{radius} & The radius of each dimensions & \texttt{dispRity} \\ +2 & \texttt{ranges} & The range of each dimension & \texttt{dispRity} \\ +1 & \texttt{roundness} & The integral of the ranked scaled eigenvalues of a variance-covariance matrix & \texttt{dispRity} \\ +2 & \texttt{span.tree.length} & The minimal spanning tree length & \href{https://cran.r-project.org/web/packages/vegan/index.html}{\texttt{vegan}}\texttt{::spantree} \\ +2 & \texttt{variances} & The variance of each dimension & \texttt{dispRity} \\ \end{longtable} 1: Note that by default, the centroid is the centroid of the elements. @@ -2074,10 +1851,10 @@ \subsection{Using the different disparity metrics}\label{using-the-different-dis \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Creating a 10*5 normal space} -\KeywordTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)} -\NormalTok{dummy\_space \textless{}{-}}\StringTok{ }\KeywordTok{space.maker}\NormalTok{(}\DecValTok{10}\NormalTok{, }\DecValTok{5}\NormalTok{, rnorm)} -\KeywordTok{rownames}\NormalTok{(dummy\_space) \textless{}{-}}\StringTok{ }\DecValTok{1}\OperatorTok{:}\DecValTok{10} +\DocumentationTok{\#\# Creating a 10*5 normal space} +\FunctionTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)} +\NormalTok{dummy\_space }\OtherTok{\textless{}{-}} \FunctionTok{space.maker}\NormalTok{(}\DecValTok{10}\NormalTok{, }\DecValTok{5}\NormalTok{, rnorm)} +\FunctionTok{rownames}\NormalTok{(dummy\_space) }\OtherTok{\textless{}{-}} \DecValTok{1}\SpecialCharTok{:}\DecValTok{10} \end{Highlighting} \end{Shaded} @@ -2092,8 +1869,8 @@ \subsubsection{Volumes and surface metrics}\label{volumes-and-surface-metrics}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Calculating the ellipsoid volume} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ ellipsoid.volume))} +\DocumentationTok{\#\# Calculating the ellipsoid volume} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ ellipsoid.volume))} \end{Highlighting} \end{Shaded} @@ -2108,8 +1885,8 @@ \subsubsection{Volumes and surface metrics}\label{volumes-and-surface-metrics}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Calculating the convex hull surface} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ convhull.surface))} +\DocumentationTok{\#\# Calculating the convex hull surface} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ convhull.surface))} \end{Highlighting} \end{Shaded} @@ -2120,8 +1897,8 @@ \subsubsection{Volumes and surface metrics}\label{volumes-and-surface-metrics}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Calculating the convex hull volume} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ convhull.volume))} +\DocumentationTok{\#\# Calculating the convex hull volume} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ convhull.volume))} \end{Highlighting} \end{Shaded} @@ -2132,8 +1909,8 @@ \subsubsection{Volumes and surface metrics}\label{volumes-and-surface-metrics}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Calculating the convex hull volume} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ n.ball.volume))} +\DocumentationTok{\#\# Calculating the convex hull volume} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ n.ball.volume))} \end{Highlighting} \end{Shaded} @@ -2149,8 +1926,8 @@ \subsubsection{Volumes and surface metrics}\label{volumes-and-surface-metrics}} Cautionary note: measuring volumes in a high number of dimensions can be strongly affected by the \href{https://en.wikipedia.org/wiki/Curse_of_dimensionality}{curse of dimensionality} that often results in near 0 disparity values. I strongly recommend reading \href{https://beta.observablehq.com/@tophtucker/theres-plenty-of-room-in-the-corners}{this really intuitive explanation} from \href{https://github.com/tophtucker}{Toph Tucker}. \end{quote} -\hypertarget{ranges-variances-quantiles-radius-pairwise-distance-neighbours-modal-value-and-diagonal}{% -\subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbours, modal value and diagonal}\label{ranges-variances-quantiles-radius-pairwise-distance-neighbours-modal-value-and-diagonal}} +\hypertarget{ranges-variances-quantiles-radius-pairwise-distance-neighbours-and-counting-them-modal-value-and-diagonal}{% +\subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbours (and counting them), modal value and diagonal}\label{ranges-variances-quantiles-radius-pairwise-distance-neighbours-and-counting-them-modal-value-and-diagonal}} The functions \texttt{ranges}, \texttt{variances} \texttt{radius}, \texttt{pairwise.dist}, \texttt{mode.val} and \texttt{diagonal} all measure properties of the ordinated space based on its dimensional properties (they are also less affected by the ``curse of dimensionality''): @@ -2158,8 +1935,8 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Calculating the ranges of each dimension in the ordinated space} -\KeywordTok{ranges}\NormalTok{(dummy\_space)} +\DocumentationTok{\#\# Calculating the ranges of each dimension in the ordinated space} +\FunctionTok{ranges}\NormalTok{(dummy\_space)} \end{Highlighting} \end{Shaded} @@ -2169,8 +1946,8 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Calculating disparity as the distribution of these ranges} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ ranges))} +\DocumentationTok{\#\# Calculating disparity as the distribution of these ranges} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ ranges))} \end{Highlighting} \end{Shaded} @@ -2181,8 +1958,8 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Calculating disparity as the sum and the product of these ranges} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, ranges)))} +\DocumentationTok{\#\# Calculating disparity as the sum and the product of these ranges} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, ranges)))} \end{Highlighting} \end{Shaded} @@ -2193,7 +1970,7 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(prod, ranges)))} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(prod, ranges)))} \end{Highlighting} \end{Shaded} @@ -2204,9 +1981,9 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Calculating the variances of each dimension in the} -\CommentTok{\#\# ordinated space} -\KeywordTok{variances}\NormalTok{(dummy\_space)} +\DocumentationTok{\#\# Calculating the variances of each dimension in the} +\DocumentationTok{\#\# ordinated space} +\FunctionTok{variances}\NormalTok{(dummy\_space)} \end{Highlighting} \end{Shaded} @@ -2216,8 +1993,8 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Calculating disparity as the distribution of these variances} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ variances))} +\DocumentationTok{\#\# Calculating disparity as the distribution of these variances} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ variances))} \end{Highlighting} \end{Shaded} @@ -2228,9 +2005,9 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Calculating disparity as the sum and} -\CommentTok{\#\# the product of these variances} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, variances)))} +\DocumentationTok{\#\# Calculating disparity as the sum and} +\DocumentationTok{\#\# the product of these variances} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, variances)))} \end{Highlighting} \end{Shaded} @@ -2241,7 +2018,7 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(prod, variances)))} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(prod, variances)))} \end{Highlighting} \end{Shaded} @@ -2252,9 +2029,9 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Calculating the quantiles of each dimension} -\CommentTok{\#\# in the ordinated space} -\KeywordTok{quantiles}\NormalTok{(dummy\_space)} +\DocumentationTok{\#\# Calculating the quantiles of each dimension} +\DocumentationTok{\#\# in the ordinated space} +\FunctionTok{quantiles}\NormalTok{(dummy\_space)} \end{Highlighting} \end{Shaded} @@ -2264,8 +2041,8 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Calculating disparity as the distribution of these variances} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ quantiles))} +\DocumentationTok{\#\# Calculating disparity as the distribution of these variances} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ quantiles))} \end{Highlighting} \end{Shaded} @@ -2276,10 +2053,10 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# By default, the quantile calculated is the 95\%} -\CommentTok{\#\# (i.e. 95\% of the data on each axis)} -\CommentTok{\#\# this can be changed using the option quantile:} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ quantiles, }\DataTypeTok{quantile =} \DecValTok{50}\NormalTok{))} +\DocumentationTok{\#\# By default, the quantile calculated is the 95\%} +\DocumentationTok{\#\# (i.e. 95\% of the data on each axis)} +\DocumentationTok{\#\# this can be changed using the option quantile:} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ quantiles, }\AttributeTok{quantile =} \DecValTok{50}\NormalTok{))} \end{Highlighting} \end{Shaded} @@ -2290,8 +2067,8 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Calculating the radius of each dimension in the ordinated space} -\KeywordTok{radius}\NormalTok{(dummy\_space)} +\DocumentationTok{\#\# Calculating the radius of each dimension in the ordinated space} +\FunctionTok{radius}\NormalTok{(dummy\_space)} \end{Highlighting} \end{Shaded} @@ -2301,9 +2078,9 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# By default the radius is the maximum distance from the centre of} -\CommentTok{\#\# the dimension. It can however be changed to any function:} -\KeywordTok{radius}\NormalTok{(dummy\_space, }\DataTypeTok{type =}\NormalTok{ min)} +\DocumentationTok{\#\# By default the radius is the maximum distance from the centre of} +\DocumentationTok{\#\# the dimension. It can however be changed to any function:} +\FunctionTok{radius}\NormalTok{(dummy\_space, }\AttributeTok{type =}\NormalTok{ min)} \end{Highlighting} \end{Shaded} @@ -2313,7 +2090,7 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{radius}\NormalTok{(dummy\_space, }\DataTypeTok{type =}\NormalTok{ mean)} +\FunctionTok{radius}\NormalTok{(dummy\_space, }\AttributeTok{type =}\NormalTok{ mean)} \end{Highlighting} \end{Shaded} @@ -2323,10 +2100,10 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Calculating disparity as the mean average radius} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space,} - \DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(mean, radius),} - \DataTypeTok{type =}\NormalTok{ mean))} +\DocumentationTok{\#\# Calculating disparity as the mean average radius} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space,} + \AttributeTok{metric =} \FunctionTok{c}\NormalTok{(mean, radius),} + \AttributeTok{type =}\NormalTok{ mean))} \end{Highlighting} \end{Shaded} @@ -2339,8 +2116,8 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The average pairwise euclidean distance} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(mean, pairwise.dist)))} +\DocumentationTok{\#\# The average pairwise euclidean distance} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(mean, pairwise.dist)))} \end{Highlighting} \end{Shaded} @@ -2351,9 +2128,9 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The distribution of the Manhattan distances} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ pairwise.dist,} - \DataTypeTok{method =} \StringTok{"manhattan"}\NormalTok{))} +\DocumentationTok{\#\# The distribution of the Manhattan distances} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ pairwise.dist,} + \AttributeTok{method =} \StringTok{"manhattan"}\NormalTok{))} \end{Highlighting} \end{Shaded} @@ -2364,8 +2141,8 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The average nearest neighbour distances} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ neighbours))} +\DocumentationTok{\#\# The average nearest neighbour distances} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ neighbours))} \end{Highlighting} \end{Shaded} @@ -2376,9 +2153,9 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The average furthest neighbour manhattan distances} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ neighbours,} - \DataTypeTok{which =}\NormalTok{ max, }\DataTypeTok{method =} \StringTok{"manhattan"}\NormalTok{))} +\DocumentationTok{\#\# The average furthest neighbour manhattan distances} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ neighbours,} + \AttributeTok{which =}\NormalTok{ max, }\AttributeTok{method =} \StringTok{"manhattan"}\NormalTok{))} \end{Highlighting} \end{Shaded} @@ -2387,6 +2164,34 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou ## 1 1 10 7.895 6.15 6.852 9.402 10.99 \end{verbatim} +\begin{Shaded} +\begin{Highlighting}[] +\DocumentationTok{\#\# The overall number of neighbours per point} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ count.neighbours,} + \AttributeTok{relative =} \ConstantTok{FALSE}\NormalTok{))} +\end{Highlighting} +\end{Shaded} + +\begin{verbatim} +## subsets n obs.median 2.5% 25% 75% 97.5% +## 1 1 10 6.5 0.675 4.25 7 7.775 +\end{verbatim} + +\begin{Shaded} +\begin{Highlighting}[] +\DocumentationTok{\#\# The relative number of neigbhours} +\DocumentationTok{\#\# two standard deviations of each element} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ count.neighbours,} + \AttributeTok{radius =} \ControlFlowTok{function}\NormalTok{(x)(}\FunctionTok{sd}\NormalTok{(x)}\SpecialCharTok{*}\DecValTok{2}\NormalTok{),} + \AttributeTok{relative =} \ConstantTok{TRUE}\NormalTok{))} +\end{Highlighting} +\end{Shaded} + +\begin{verbatim} +## subsets n obs.median 2.5% 25% 75% 97.5% +## 1 1 10 0.55 0.068 0.3 0.7 0.7 +\end{verbatim} + Note that this function is a direct call to \texttt{vegan::vegdist(matrix,\ method\ =\ method,\ diag\ =\ FALSE,\ upper\ =\ FALSE,\ ...)}. The \texttt{diagonal} function measures the multidimensional diagonal of the whole space (i.e.~in our case the longest Euclidean distance in our five dimensional space). @@ -2394,8 +2199,8 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Calculating the ordinated space\textquotesingle{}s diagonal} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ diagonal))} +\DocumentationTok{\#\# Calculating the ordinated space\textquotesingle{}s diagonal} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ diagonal))} \end{Highlighting} \end{Shaded} @@ -2406,8 +2211,8 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Calculating the modal value of the matrix} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ mode.val))} +\DocumentationTok{\#\# Calculating the modal value of the matrix} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ mode.val))} \end{Highlighting} \end{Shaded} @@ -2428,8 +2233,8 @@ \subsubsection{Centroids, displacements and ancestral distances metrics}\label{c \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The distribution of the distances between each element and their centroid} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ centroids))} +\DocumentationTok{\#\# The distribution of the distances between each element and their centroid} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ centroids))} \end{Highlighting} \end{Shaded} @@ -2440,8 +2245,8 @@ \subsubsection{Centroids, displacements and ancestral distances metrics}\label{c \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Disparity as the median value of these distances} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(median, centroids)))} +\DocumentationTok{\#\# Disparity as the median value of these distances} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(median, centroids)))} \end{Highlighting} \end{Shaded} @@ -2454,9 +2259,9 @@ \subsubsection{Centroids, displacements and ancestral distances metrics}\label{c \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The distance between each element and the origin} -\CommentTok{\#\# of the ordinated space} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ centroids, }\DataTypeTok{centroid =} \DecValTok{0}\NormalTok{))} +\DocumentationTok{\#\# The distance between each element and the origin} +\DocumentationTok{\#\# of the ordinated space} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ centroids, }\AttributeTok{centroid =} \DecValTok{0}\NormalTok{))} \end{Highlighting} \end{Shaded} @@ -2467,10 +2272,10 @@ \subsubsection{Centroids, displacements and ancestral distances metrics}\label{c \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Disparity as the distance between each element} -\CommentTok{\#\# and a specific point in space} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ centroids,} - \DataTypeTok{centroid =} \KeywordTok{c}\NormalTok{(}\DecValTok{0}\NormalTok{,}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{,}\DecValTok{3}\NormalTok{,}\DecValTok{4}\NormalTok{)))} +\DocumentationTok{\#\# Disparity as the distance between each element} +\DocumentationTok{\#\# and a specific point in space} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ centroids,} + \AttributeTok{centroid =} \FunctionTok{c}\NormalTok{(}\DecValTok{0}\NormalTok{,}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{,}\DecValTok{3}\NormalTok{,}\DecValTok{4}\NormalTok{)))} \end{Highlighting} \end{Shaded} @@ -2484,12 +2289,12 @@ \subsubsection{Centroids, displacements and ancestral distances metrics}\label{c \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Create a custom subsets object} -\NormalTok{dummy\_groups \textless{}{-}}\StringTok{ }\KeywordTok{custom.subsets}\NormalTok{(dummy\_space,} - \DataTypeTok{group =} \KeywordTok{list}\NormalTok{(}\StringTok{"group1"}\NormalTok{ =}\StringTok{ }\DecValTok{1}\OperatorTok{:}\DecValTok{5}\NormalTok{,} - \StringTok{"group2"}\NormalTok{ =}\StringTok{ }\DecValTok{6}\OperatorTok{:}\DecValTok{10}\NormalTok{))} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_groups, }\DataTypeTok{metric =}\NormalTok{ centroids,} - \DataTypeTok{centroid =} \KeywordTok{colMeans}\NormalTok{(}\KeywordTok{get.matrix}\NormalTok{(dummy\_groups, }\StringTok{"group1"}\NormalTok{))))} +\DocumentationTok{\#\# Create a custom subsets object} +\NormalTok{dummy\_groups }\OtherTok{\textless{}{-}} \FunctionTok{custom.subsets}\NormalTok{(dummy\_space,} + \AttributeTok{group =} \FunctionTok{list}\NormalTok{(}\StringTok{"group1"} \OtherTok{=} \DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{,} + \StringTok{"group2"} \OtherTok{=} \DecValTok{6}\SpecialCharTok{:}\DecValTok{10}\NormalTok{))} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_groups, }\AttributeTok{metric =}\NormalTok{ centroids,} + \AttributeTok{centroid =} \FunctionTok{colMeans}\NormalTok{(}\FunctionTok{get.matrix}\NormalTok{(dummy\_groups, }\StringTok{"group1"}\NormalTok{))))} \end{Highlighting} \end{Shaded} @@ -2505,8 +2310,8 @@ \subsubsection{Centroids, displacements and ancestral distances metrics}\label{c \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The relative displacement of the group in space to the centre} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ displacements))} +\DocumentationTok{\#\# The relative displacement of the group in space to the centre} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ displacements))} \end{Highlighting} \end{Shaded} @@ -2517,9 +2322,9 @@ \subsubsection{Centroids, displacements and ancestral distances metrics}\label{c \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The relative displacement of the group to an arbitrary point} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ displacements,} - \DataTypeTok{reference =} \KeywordTok{c}\NormalTok{(}\DecValTok{0}\NormalTok{,}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{,}\DecValTok{3}\NormalTok{,}\DecValTok{4}\NormalTok{)))} +\DocumentationTok{\#\# The relative displacement of the group to an arbitrary point} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ displacements,} + \AttributeTok{reference =} \FunctionTok{c}\NormalTok{(}\DecValTok{0}\NormalTok{,}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{,}\DecValTok{3}\NormalTok{,}\DecValTok{4}\NormalTok{)))} \end{Highlighting} \end{Shaded} @@ -2533,37 +2338,37 @@ \subsubsection{Centroids, displacements and ancestral distances metrics}\label{c \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# A generating a random tree with node labels} -\NormalTok{my\_tree \textless{}{-}}\StringTok{ }\KeywordTok{makeNodeLabel}\NormalTok{(}\KeywordTok{rtree}\NormalTok{(}\DecValTok{5}\NormalTok{), }\DataTypeTok{prefix =} \StringTok{"n"}\NormalTok{)} -\CommentTok{\#\# Adding the tip and node names to the matrix} -\NormalTok{dummy\_space2 \textless{}{-}}\StringTok{ }\NormalTok{dummy\_space[}\OperatorTok{{-}}\DecValTok{1}\NormalTok{,]} -\KeywordTok{rownames}\NormalTok{(dummy\_space2) \textless{}{-}}\StringTok{ }\KeywordTok{c}\NormalTok{(my\_tree}\OperatorTok{$}\NormalTok{tip.label,} -\NormalTok{ my\_tree}\OperatorTok{$}\NormalTok{node.label)} +\DocumentationTok{\#\# A generating a random tree with node labels} +\NormalTok{my\_tree }\OtherTok{\textless{}{-}} \FunctionTok{makeNodeLabel}\NormalTok{(}\FunctionTok{rtree}\NormalTok{(}\DecValTok{5}\NormalTok{), }\AttributeTok{prefix =} \StringTok{"n"}\NormalTok{)} +\DocumentationTok{\#\# Adding the tip and node names to the matrix} +\NormalTok{dummy\_space2 }\OtherTok{\textless{}{-}}\NormalTok{ dummy\_space[}\SpecialCharTok{{-}}\DecValTok{1}\NormalTok{,]} +\FunctionTok{rownames}\NormalTok{(dummy\_space2) }\OtherTok{\textless{}{-}} \FunctionTok{c}\NormalTok{(my\_tree}\SpecialCharTok{$}\NormalTok{tip.label,} +\NormalTok{ my\_tree}\SpecialCharTok{$}\NormalTok{node.label)} -\CommentTok{\#\# Calculating the distances from the ancestral nodes} -\NormalTok{ancestral\_dist \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(dummy\_space2, }\DataTypeTok{metric =}\NormalTok{ ancestral.dist,} - \DataTypeTok{tree =}\NormalTok{ my\_tree)} +\DocumentationTok{\#\# Calculating the distances from the ancestral nodes} +\NormalTok{ancestral\_dist }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(dummy\_space2, }\AttributeTok{metric =}\NormalTok{ ancestral.dist,} + \AttributeTok{tree =}\NormalTok{ my\_tree)} -\CommentTok{\#\# The ancestral distances distributions} -\KeywordTok{summary}\NormalTok{(ancestral\_dist)} +\DocumentationTok{\#\# The ancestral distances distributions} +\FunctionTok{summary}\NormalTok{(ancestral\_dist)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## subsets n obs.median 2.5% 25% 75% 97.5% -## 1 1 9 1.729 0.286 1.653 1.843 3.981 +## 1 1 9 2.193 0.343 1.729 2.595 3.585 \end{verbatim} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Calculating disparity as the sum of the distances from all the ancestral nodes} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(ancestral\_dist, }\DataTypeTok{metric =}\NormalTok{ sum))} +\DocumentationTok{\#\# Calculating disparity as the sum of the distances from all the ancestral nodes} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(ancestral\_dist, }\AttributeTok{metric =}\NormalTok{ sum))} \end{Highlighting} \end{Shaded} \begin{verbatim} ## subsets n obs -## 1 1 9 17.28 +## 1 1 9 18.93 \end{verbatim} \hypertarget{minimal-spanning-tree-length}{% @@ -2573,8 +2378,8 @@ \subsubsection{Minimal spanning tree length}\label{minimal-spanning-tree-length} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The length of the minimal spanning tree} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, span.tree.length)))} +\DocumentationTok{\#\# The length of the minimal spanning tree} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, span.tree.length)))} \end{Highlighting} \end{Shaded} @@ -2594,8 +2399,8 @@ \subsubsection{Functional divergence and evenness}\label{functional-divergence-a \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The ratio of deviation from the centroid } -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ func.div))} +\DocumentationTok{\#\# The ratio of deviation from the centroid } +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ func.div))} \end{Highlighting} \end{Shaded} @@ -2606,8 +2411,8 @@ \subsubsection{Functional divergence and evenness}\label{functional-divergence-a \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The minimal spanning tree distances evenness} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ func.eve))} +\DocumentationTok{\#\# The minimal spanning tree distances evenness} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ func.eve))} \end{Highlighting} \end{Shaded} @@ -2618,9 +2423,9 @@ \subsubsection{Functional divergence and evenness}\label{functional-divergence-a \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The minimal spanning tree manhanttan distances evenness} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ func.eve,} - \DataTypeTok{method =} \StringTok{"manhattan"}\NormalTok{))} +\DocumentationTok{\#\# The minimal spanning tree manhanttan distances evenness} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ func.eve,} + \AttributeTok{method =} \StringTok{"manhattan"}\NormalTok{))} \end{Highlighting} \end{Shaded} @@ -2637,9 +2442,9 @@ \subsubsection{Orientation: angles and deviations}\label{orientation-angles-and- \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The distribution of each angles in degrees for each} -\CommentTok{\#\# main axis in the matrix} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ angles))} +\DocumentationTok{\#\# The distribution of each angles in degrees for each} +\DocumentationTok{\#\# main axis in the matrix} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ angles))} \end{Highlighting} \end{Shaded} @@ -2650,9 +2455,9 @@ \subsubsection{Orientation: angles and deviations}\label{orientation-angles-and- \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The distribution of slopes deviating from the 1:1 slope:} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ angles, }\DataTypeTok{unit =} \StringTok{"slope"}\NormalTok{,} - \DataTypeTok{base =} \DecValTok{1}\NormalTok{))} +\DocumentationTok{\#\# The distribution of slopes deviating from the 1:1 slope:} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ angles, }\AttributeTok{unit =} \StringTok{"slope"}\NormalTok{,} + \AttributeTok{base =} \DecValTok{1}\NormalTok{))} \end{Highlighting} \end{Shaded} @@ -2667,9 +2472,9 @@ \subsubsection{Orientation: angles and deviations}\label{orientation-angles-and- \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The distribution of the deviation of each point} -\CommentTok{\#\# from the least square hyperplane} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ deviations))} +\DocumentationTok{\#\# The distribution of the deviation of each point} +\DocumentationTok{\#\# from the least square hyperplane} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ deviations))} \end{Highlighting} \end{Shaded} @@ -2682,10 +2487,10 @@ \subsubsection{Orientation: angles and deviations}\label{orientation-angles-and- \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The distribution of the deviation of each point} -\CommentTok{\#\# from a slope (with only the two first dimensions)} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space[, }\KeywordTok{c}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{2}\NormalTok{)], }\DataTypeTok{metric =}\NormalTok{ deviations,} - \DataTypeTok{hyperplane =} \KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{{-}1}\NormalTok{)))} +\DocumentationTok{\#\# The distribution of the deviation of each point} +\DocumentationTok{\#\# from a slope (with only the two first dimensions)} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space[, }\FunctionTok{c}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{2}\NormalTok{)], }\AttributeTok{metric =}\NormalTok{ deviations,} + \AttributeTok{hyperplane =} \FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\SpecialCharTok{{-}}\DecValTok{1}\NormalTok{)))} \end{Highlighting} \end{Shaded} @@ -2708,11 +2513,11 @@ \subsubsection{Projections and phylo projections: elaboration and exploration}\l \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The elaboration on the axis defined by the first and} -\CommentTok{\#\# second row in the dummy\_space} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ projections,} - \DataTypeTok{point1 =}\NormalTok{ dummy\_space[}\DecValTok{1}\NormalTok{,],} - \DataTypeTok{point2 =}\NormalTok{ dummy\_space[}\DecValTok{2}\NormalTok{,]))} +\DocumentationTok{\#\# The elaboration on the axis defined by the first and} +\DocumentationTok{\#\# second row in the dummy\_space} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ projections,} + \AttributeTok{point1 =}\NormalTok{ dummy\_space[}\DecValTok{1}\NormalTok{,],} + \AttributeTok{point2 =}\NormalTok{ dummy\_space[}\DecValTok{2}\NormalTok{,]))} \end{Highlighting} \end{Shaded} @@ -2723,11 +2528,11 @@ \subsubsection{Projections and phylo projections: elaboration and exploration}\l \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The exploration on the same axis} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ projections,} - \DataTypeTok{point1 =}\NormalTok{ dummy\_space[}\DecValTok{1}\NormalTok{,],} - \DataTypeTok{point2 =}\NormalTok{ dummy\_space[}\DecValTok{2}\NormalTok{,],} - \DataTypeTok{measure =} \StringTok{"distance"}\NormalTok{))} +\DocumentationTok{\#\# The exploration on the same axis} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ projections,} + \AttributeTok{point1 =}\NormalTok{ dummy\_space[}\DecValTok{1}\NormalTok{,],} + \AttributeTok{point2 =}\NormalTok{ dummy\_space[}\DecValTok{2}\NormalTok{,],} + \AttributeTok{measure =} \StringTok{"distance"}\NormalTok{))} \end{Highlighting} \end{Shaded} @@ -2741,12 +2546,12 @@ \subsubsection{Projections and phylo projections: elaboration and exploration}\l \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The elaboration on the same axis using the dummy\_space\textquotesingle{}s} -\CommentTok{\#\# unit vector} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ projections,} - \DataTypeTok{point1 =}\NormalTok{ dummy\_space[}\DecValTok{1}\NormalTok{,],} - \DataTypeTok{point2 =}\NormalTok{ dummy\_space[}\DecValTok{2}\NormalTok{,],} - \DataTypeTok{scale =} \OtherTok{FALSE}\NormalTok{))} +\DocumentationTok{\#\# The elaboration on the same axis using the dummy\_space\textquotesingle{}s} +\DocumentationTok{\#\# unit vector} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ projections,} + \AttributeTok{point1 =}\NormalTok{ dummy\_space[}\DecValTok{1}\NormalTok{,],} + \AttributeTok{point2 =}\NormalTok{ dummy\_space[}\DecValTok{2}\NormalTok{,],} + \AttributeTok{scale =} \ConstantTok{FALSE}\NormalTok{))} \end{Highlighting} \end{Shaded} @@ -2784,57 +2589,56 @@ \subsubsection{Projections and phylo projections: elaboration and exploration}\l \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Adding a extra row to dummy matrix (to match dummy\_tree)} -\NormalTok{tree\_space \textless{}{-}}\StringTok{ }\KeywordTok{rbind}\NormalTok{(dummy\_space, }\DataTypeTok{root =} \KeywordTok{rnorm}\NormalTok{(}\DecValTok{5}\NormalTok{))} -\CommentTok{\#\# Creating a random dummy tree (with labels matching the ones from tree\_space)} -\NormalTok{dummy\_tree \textless{}{-}}\StringTok{ }\KeywordTok{rtree}\NormalTok{(}\DecValTok{6}\NormalTok{)} -\NormalTok{dummy\_tree}\OperatorTok{$}\NormalTok{tip.label \textless{}{-}}\StringTok{ }\KeywordTok{rownames}\NormalTok{(tree\_space)[}\DecValTok{1}\OperatorTok{:}\DecValTok{6}\NormalTok{]} -\NormalTok{dummy\_tree}\OperatorTok{$}\NormalTok{node.label \textless{}{-}}\StringTok{ }\KeywordTok{rownames}\NormalTok{(tree\_space)[}\KeywordTok{rev}\NormalTok{(}\DecValTok{7}\OperatorTok{:}\DecValTok{11}\NormalTok{)]} +\DocumentationTok{\#\# Adding a extra row to dummy matrix (to match dummy\_tree)} +\NormalTok{tree\_space }\OtherTok{\textless{}{-}} \FunctionTok{rbind}\NormalTok{(dummy\_space, }\AttributeTok{root =} \FunctionTok{rnorm}\NormalTok{(}\DecValTok{5}\NormalTok{))} +\DocumentationTok{\#\# Creating a random dummy tree (with labels matching the ones from tree\_space)} +\NormalTok{dummy\_tree }\OtherTok{\textless{}{-}} \FunctionTok{rtree}\NormalTok{(}\DecValTok{6}\NormalTok{)} +\NormalTok{dummy\_tree}\SpecialCharTok{$}\NormalTok{tip.label }\OtherTok{\textless{}{-}} \FunctionTok{rownames}\NormalTok{(tree\_space)[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{6}\NormalTok{]} +\NormalTok{dummy\_tree}\SpecialCharTok{$}\NormalTok{node.label }\OtherTok{\textless{}{-}} \FunctionTok{rownames}\NormalTok{(tree\_space)[}\FunctionTok{rev}\NormalTok{(}\DecValTok{7}\SpecialCharTok{:}\DecValTok{11}\NormalTok{)]} -\CommentTok{\#\# Measuring the disparity as the projection of each element} -\CommentTok{\#\# on its root{-}ancestor vector} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(tree\_space, }\DataTypeTok{metric =}\NormalTok{ projections.tree,} - \DataTypeTok{tree =}\NormalTok{ dummy\_tree,} - \DataTypeTok{type =} \KeywordTok{c}\NormalTok{(}\StringTok{"root"}\NormalTok{, }\StringTok{"ancestor"}\NormalTok{)))} +\DocumentationTok{\#\# Measuring the disparity as the projection of each element} +\DocumentationTok{\#\# on its root{-}ancestor vector} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(tree\_space, }\AttributeTok{metric =}\NormalTok{ projections.tree,} + \AttributeTok{tree =}\NormalTok{ dummy\_tree,} + \AttributeTok{type =} \FunctionTok{c}\NormalTok{(}\StringTok{"root"}\NormalTok{, }\StringTok{"ancestor"}\NormalTok{)))} \end{Highlighting} \end{Shaded} \begin{verbatim} ## Warning in max(nchar(round(column)), na.rm = TRUE): no non-missing arguments to ## max; returning -Inf - ## Warning in max(nchar(round(column)), na.rm = TRUE): no non-missing arguments to ## max; returning -Inf \end{verbatim} \begin{verbatim} -## subsets n obs.median 2.5% 25% 75% 97.5% -## 1 1 11 NA 0.229 0.416 0.712 1.016 +## subsets n obs.median 2.5% 25% 75% 97.5% +## 1 1 11 NA -0.7 -0.196 0.908 1.774 \end{verbatim} Of course you can also use any other options from the projections function: \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# A user defined function that\textquotesingle{}s returns the centroid of} -\CommentTok{\#\# the first three nodes} -\NormalTok{fun.root \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(matrix, tree, }\DataTypeTok{row =} \OtherTok{NULL}\NormalTok{) \{} - \KeywordTok{return}\NormalTok{(}\KeywordTok{colMeans}\NormalTok{(matrix[tree}\OperatorTok{$}\NormalTok{node.label[}\DecValTok{1}\OperatorTok{:}\DecValTok{3}\NormalTok{], ]))} +\DocumentationTok{\#\# A user defined function that\textquotesingle{}s returns the centroid of} +\DocumentationTok{\#\# the first three nodes} +\NormalTok{fun.root }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(matrix, tree, }\AttributeTok{row =} \ConstantTok{NULL}\NormalTok{) \{} + \FunctionTok{return}\NormalTok{(}\FunctionTok{colMeans}\NormalTok{(matrix[tree}\SpecialCharTok{$}\NormalTok{node.label[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{3}\NormalTok{], ]))} \NormalTok{\}} -\CommentTok{\#\# Measuring the unscaled rejection from the vector from the} -\CommentTok{\#\# centroid of the three first nodes} -\CommentTok{\#\# to the coordinates of the first tip} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(tree\_space, }\DataTypeTok{metric =}\NormalTok{ projections.tree,} - \DataTypeTok{tree =}\NormalTok{ dummy\_tree,} - \DataTypeTok{measure =} \StringTok{"distance"}\NormalTok{,} - \DataTypeTok{type =} \KeywordTok{list}\NormalTok{(fun.root,} +\DocumentationTok{\#\# Measuring the unscaled rejection from the vector from the} +\DocumentationTok{\#\# centroid of the three first nodes} +\DocumentationTok{\#\# to the coordinates of the first tip} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(tree\_space, }\AttributeTok{metric =}\NormalTok{ projections.tree,} + \AttributeTok{tree =}\NormalTok{ dummy\_tree,} + \AttributeTok{measure =} \StringTok{"distance"}\NormalTok{,} + \AttributeTok{type =} \FunctionTok{list}\NormalTok{(fun.root,} \NormalTok{ tree\_space[}\DecValTok{1}\NormalTok{, ])))} \end{Highlighting} \end{Shaded} \begin{verbatim} -## subsets n obs.median 2.5% 25% 75% 97.5% -## 1 1 11 0.606 0.064 0.462 0.733 0.999 +## subsets n obs.median 2.5% 25% 75% 97.5% +## 1 1 11 0.763 0.07 0.459 0.873 1.371 \end{verbatim} \hypertarget{roundness}{% @@ -2855,7 +2659,7 @@ \subsubsection{Roundness}\label{roundness}} ## snapshots \end{verbatim} -\includegraphics[width=4in]{../../../../../../tmp/Rtmp1snN3p/file17f44d79dfdf} +\includegraphics[width=4in]{../../../../../../tmp/RtmpNRJYtO/filedc8b70fa877c} \begin{verbatim} ## Warning in snapshot3d(scene = x, width = width, height = height): webshot = @@ -2868,7 +2672,7 @@ \subsubsection{Roundness}\label{roundness}} ## snapshots \end{verbatim} -\includegraphics[width=4in]{../../../../../../tmp/Rtmp1snN3p/file17f43605eec1} +\includegraphics[width=4in]{../../../../../../tmp/RtmpNRJYtO/filedc8b241ab6ff} \begin{verbatim} ## Warning in snapshot3d(scene = x, width = width, height = height): webshot = @@ -2881,8 +2685,8 @@ \subsubsection{Roundness}\label{roundness}} ## snapshots \end{verbatim} -\includegraphics[width=4in]{../../../../../../tmp/Rtmp1snN3p/file17f46de61347} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-69-1.pdf} +\includegraphics[width=4in]{../../../../../../tmp/RtmpNRJYtO/filedc8b6be23fa7} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-70-1.pdf} \hypertarget{betweengroupmetricslist}{% \subsubsection{Between group metrics}\label{betweengroupmetricslist}} @@ -2902,13 +2706,13 @@ \subsubsection{Between group metrics}\label{betweengroupmetricslist}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Creating a dispRity object with two groups} -\NormalTok{grouped\_space \textless{}{-}}\StringTok{ }\KeywordTok{custom.subsets}\NormalTok{(dummy\_space,} - \DataTypeTok{group =} \KeywordTok{list}\NormalTok{(}\KeywordTok{c}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{5}\NormalTok{), }\KeywordTok{c}\NormalTok{(}\DecValTok{6}\OperatorTok{:}\DecValTok{10}\NormalTok{)))} +\DocumentationTok{\#\# Creating a dispRity object with two groups} +\NormalTok{grouped\_space }\OtherTok{\textless{}{-}} \FunctionTok{custom.subsets}\NormalTok{(dummy\_space,} + \AttributeTok{group =} \FunctionTok{list}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{), }\FunctionTok{c}\NormalTok{(}\DecValTok{6}\SpecialCharTok{:}\DecValTok{10}\NormalTok{)))} -\CommentTok{\#\# Measuring the minimum distance between both groups} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(grouped\_space, }\DataTypeTok{metric =}\NormalTok{ group.dist,} - \DataTypeTok{between.groups =} \OtherTok{TRUE}\NormalTok{))} +\DocumentationTok{\#\# Measuring the minimum distance between both groups} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(grouped\_space, }\AttributeTok{metric =}\NormalTok{ group.dist,} + \AttributeTok{between.groups =} \ConstantTok{TRUE}\NormalTok{))} \end{Highlighting} \end{Shaded} @@ -2919,9 +2723,9 @@ \subsubsection{Between group metrics}\label{betweengroupmetricslist}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Measuring the centroid distance between both groups} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(grouped\_space, }\DataTypeTok{metric =}\NormalTok{ group.dist,} - \DataTypeTok{between.groups =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{probs =} \FloatTok{0.5}\NormalTok{))} +\DocumentationTok{\#\# Measuring the centroid distance between both groups} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(grouped\_space, }\AttributeTok{metric =}\NormalTok{ group.dist,} + \AttributeTok{between.groups =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{probs =} \FloatTok{0.5}\NormalTok{))} \end{Highlighting} \end{Shaded} @@ -2932,9 +2736,9 @@ \subsubsection{Between group metrics}\label{betweengroupmetricslist}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Measuring the distance between both group\textquotesingle{}s 75\% CI} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(grouped\_space, }\DataTypeTok{metric =}\NormalTok{ group.dist,} - \DataTypeTok{between.groups =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{probs =} \KeywordTok{c}\NormalTok{(}\FloatTok{0.25}\NormalTok{, }\FloatTok{0.75}\NormalTok{)))} +\DocumentationTok{\#\# Measuring the distance between both group\textquotesingle{}s 75\% CI} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(grouped\_space, }\AttributeTok{metric =}\NormalTok{ group.dist,} + \AttributeTok{between.groups =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{probs =} \FunctionTok{c}\NormalTok{(}\FloatTok{0.25}\NormalTok{, }\FloatTok{0.75}\NormalTok{)))} \end{Highlighting} \end{Shaded} @@ -2953,10 +2757,10 @@ \subsubsection{Between group metrics}\label{betweengroupmetricslist}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Measuring the distance between the elements of the first group} -\CommentTok{\#\# and the centroid of the second group} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(grouped\_space, }\DataTypeTok{metric =}\NormalTok{ point.dist,} - \DataTypeTok{between.groups =} \OtherTok{TRUE}\NormalTok{))} +\DocumentationTok{\#\# Measuring the distance between the elements of the first group} +\DocumentationTok{\#\# and the centroid of the second group} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(grouped\_space, }\AttributeTok{metric =}\NormalTok{ point.dist,} + \AttributeTok{between.groups =} \ConstantTok{TRUE}\NormalTok{))} \end{Highlighting} \end{Shaded} @@ -2967,10 +2771,10 @@ \subsubsection{Between group metrics}\label{betweengroupmetricslist}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Measuring the distance between the elements of the second group} -\CommentTok{\#\# and the centroid of the first group} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(grouped\_space, }\DataTypeTok{metric =}\NormalTok{ point.dist,} - \DataTypeTok{between.groups =} \KeywordTok{list}\NormalTok{(}\KeywordTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{1}\NormalTok{))))} +\DocumentationTok{\#\# Measuring the distance between the elements of the second group} +\DocumentationTok{\#\# and the centroid of the first group} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(grouped\_space, }\AttributeTok{metric =}\NormalTok{ point.dist,} + \AttributeTok{between.groups =} \FunctionTok{list}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{1}\NormalTok{))))} \end{Highlighting} \end{Shaded} @@ -2981,13 +2785,13 @@ \subsubsection{Between group metrics}\label{betweengroupmetricslist}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Measuring the distance between the elements of the first group} -\CommentTok{\#\# a point defined as the standard deviation of each column} -\CommentTok{\#\# in the second group} -\NormalTok{sd.point \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(matrix2) \{}\KeywordTok{apply}\NormalTok{(matrix2, }\DecValTok{2}\NormalTok{, sd)\}} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(grouped\_space, }\DataTypeTok{metric =}\NormalTok{ point.dist,} - \DataTypeTok{point =}\NormalTok{ sd.point, }\DataTypeTok{method =} \StringTok{"manhattan"}\NormalTok{,} - \DataTypeTok{between.groups =} \OtherTok{TRUE}\NormalTok{))} +\DocumentationTok{\#\# Measuring the distance between the elements of the first group} +\DocumentationTok{\#\# a point defined as the standard deviation of each column} +\DocumentationTok{\#\# in the second group} +\NormalTok{sd.point }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(matrix2) \{}\FunctionTok{apply}\NormalTok{(matrix2, }\DecValTok{2}\NormalTok{, sd)\}} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(grouped\_space, }\AttributeTok{metric =}\NormalTok{ point.dist,} + \AttributeTok{point =}\NormalTok{ sd.point, }\AttributeTok{method =} \StringTok{"manhattan"}\NormalTok{,} + \AttributeTok{between.groups =} \ConstantTok{TRUE}\NormalTok{))} \end{Highlighting} \end{Shaded} @@ -3007,16 +2811,16 @@ \subsubsection{Between group metrics}\label{betweengroupmetricslist}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Loading the charadriiformes data} -\KeywordTok{data}\NormalTok{(charadriiformes)} +\DocumentationTok{\#\# Loading the charadriiformes data} +\FunctionTok{data}\NormalTok{(charadriiformes)} -\CommentTok{\#\# Creating the dispRity object (see the \#covar section in the manual for more info)} -\NormalTok{my\_covar \textless{}{-}}\StringTok{ }\KeywordTok{MCMCglmm.subsets}\NormalTok{(}\DataTypeTok{n =} \DecValTok{50}\NormalTok{,} - \DataTypeTok{data =}\NormalTok{ charadriiformes}\OperatorTok{$}\NormalTok{data,} - \DataTypeTok{posteriors =}\NormalTok{ charadriiformes}\OperatorTok{$}\NormalTok{posteriors,} - \DataTypeTok{group =} \KeywordTok{MCMCglmm.levels}\NormalTok{(charadriiformes}\OperatorTok{$}\NormalTok{posteriors)[}\DecValTok{1}\OperatorTok{:}\DecValTok{4}\NormalTok{],} - \DataTypeTok{tree =}\NormalTok{ charadriiformes}\OperatorTok{$}\NormalTok{tree,} - \DataTypeTok{rename.groups =} \KeywordTok{c}\NormalTok{(}\KeywordTok{levels}\NormalTok{(charadriiformes}\OperatorTok{$}\NormalTok{data}\OperatorTok{$}\NormalTok{clade), }\StringTok{"phylogeny"}\NormalTok{))} +\DocumentationTok{\#\# Creating the dispRity object (see the \#covar section in the manual for more info)} +\NormalTok{my\_covar }\OtherTok{\textless{}{-}} \FunctionTok{MCMCglmm.subsets}\NormalTok{(}\AttributeTok{n =} \DecValTok{50}\NormalTok{,} + \AttributeTok{data =}\NormalTok{ charadriiformes}\SpecialCharTok{$}\NormalTok{data,} + \AttributeTok{posteriors =}\NormalTok{ charadriiformes}\SpecialCharTok{$}\NormalTok{posteriors,} + \AttributeTok{group =} \FunctionTok{MCMCglmm.levels}\NormalTok{(charadriiformes}\SpecialCharTok{$}\NormalTok{posteriors)[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{4}\NormalTok{],} + \AttributeTok{tree =}\NormalTok{ charadriiformes}\SpecialCharTok{$}\NormalTok{tree,} + \AttributeTok{rename.groups =} \FunctionTok{c}\NormalTok{(}\FunctionTok{levels}\NormalTok{(charadriiformes}\SpecialCharTok{$}\NormalTok{data}\SpecialCharTok{$}\NormalTok{clade), }\StringTok{"phylogeny"}\NormalTok{))} \end{Highlighting} \end{Shaded} @@ -3025,27 +2829,27 @@ \subsubsection{Between group metrics}\label{betweengroupmetricslist}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Creating the list of groups to compare} -\NormalTok{comparisons\_list \textless{}{-}}\StringTok{ }\KeywordTok{list}\NormalTok{(}\KeywordTok{c}\NormalTok{(}\StringTok{"gulls"}\NormalTok{, }\StringTok{"phylogeny"}\NormalTok{),} - \KeywordTok{c}\NormalTok{(}\StringTok{"plovers"}\NormalTok{, }\StringTok{"phylogeny"}\NormalTok{),} - \KeywordTok{c}\NormalTok{(}\StringTok{"sandpipers"}\NormalTok{, }\StringTok{"phylogeny"}\NormalTok{))} +\DocumentationTok{\#\# Creating the list of groups to compare} +\NormalTok{comparisons\_list }\OtherTok{\textless{}{-}} \FunctionTok{list}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\StringTok{"gulls"}\NormalTok{, }\StringTok{"phylogeny"}\NormalTok{),} + \FunctionTok{c}\NormalTok{(}\StringTok{"plovers"}\NormalTok{, }\StringTok{"phylogeny"}\NormalTok{),} + \FunctionTok{c}\NormalTok{(}\StringTok{"sandpipers"}\NormalTok{, }\StringTok{"phylogeny"}\NormalTok{))} -\CommentTok{\#\# Measuring the angles between each groups} -\CommentTok{\#\# (note that we set the metric as.covar, more on that in the \#covar section below)} -\NormalTok{groups\_angles \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ my\_covar,} - \DataTypeTok{metric =} \KeywordTok{as.covar}\NormalTok{(projections.between),} - \DataTypeTok{between.groups =}\NormalTok{ comparisons\_list,} - \DataTypeTok{measure =} \StringTok{"degree"}\NormalTok{)} -\CommentTok{\#\# And here are the angles in degrees:} -\KeywordTok{summary}\NormalTok{(groups\_angles)} +\DocumentationTok{\#\# Measuring the angles between each groups} +\DocumentationTok{\#\# (note that we set the metric as.covar, more on that in the \#covar section below)} +\NormalTok{groups\_angles }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(}\AttributeTok{data =}\NormalTok{ my\_covar,} + \AttributeTok{metric =} \FunctionTok{as.covar}\NormalTok{(projections.between),} + \AttributeTok{between.groups =}\NormalTok{ comparisons\_list,} + \AttributeTok{measure =} \StringTok{"degree"}\NormalTok{)} +\DocumentationTok{\#\# And here are the angles in degrees:} +\FunctionTok{summary}\NormalTok{(groups\_angles)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## subsets n_1 n_2 obs.median 2.5% 25% 75% 97.5% -## 1 gulls:phylogeny 159 359 8.25 2.101 6.25 14.98 41.8 -## 2 plovers:phylogeny 98 359 33.75 5.700 16.33 75.50 131.5 -## 3 sandpipers:phylogeny 102 359 10.79 3.876 8.10 16.59 95.9 +## 1 gulls:phylogeny 159 359 9.39 2.480 5.95 16.67 43.2 +## 2 plovers:phylogeny 98 359 20.42 4.500 12.36 51.31 129.8 +## 3 sandpipers:phylogeny 102 359 10.82 1.777 7.60 13.89 43.0 \end{verbatim} The second metric, \texttt{disalignment} rejects the centroid of a group (\texttt{matrix}) onto the major axis of another one (\texttt{matrix2}). @@ -3055,20 +2859,20 @@ \subsubsection{Between group metrics}\label{betweengroupmetricslist}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Measuring the disalignement of each group} -\NormalTok{groups\_alignement \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ my\_covar,} - \DataTypeTok{metric =} \KeywordTok{as.covar}\NormalTok{(disalignment),} - \DataTypeTok{between.groups =}\NormalTok{ comparisons\_list)} -\CommentTok{\#\# And here are the groups alignment (0 = aligned)} -\KeywordTok{summary}\NormalTok{(groups\_alignement)} +\DocumentationTok{\#\# Measuring the disalignement of each group} +\NormalTok{groups\_alignement }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(}\AttributeTok{data =}\NormalTok{ my\_covar,} + \AttributeTok{metric =} \FunctionTok{as.covar}\NormalTok{(disalignment),} + \AttributeTok{between.groups =}\NormalTok{ comparisons\_list)} +\DocumentationTok{\#\# And here are the groups alignment (0 = aligned)} +\FunctionTok{summary}\NormalTok{(groups\_alignement)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## subsets n_1 n_2 obs.median 2.5% 25% 75% 97.5% -## 1 gulls:phylogeny 159 359 0.003 0.001 0.002 0.005 0.015 +## 1 gulls:phylogeny 159 359 0.003 0.001 0.002 0.005 0.021 ## 2 plovers:phylogeny 98 359 0.001 0.000 0.001 0.001 0.006 -## 3 sandpipers:phylogeny 102 359 0.002 0.000 0.001 0.003 0.009 +## 3 sandpipers:phylogeny 102 359 0.002 0.000 0.001 0.005 0.018 \end{verbatim} \hypertarget{which-disparity-metric-to-choose}{% @@ -3078,7 +2882,7 @@ \subsection{Which disparity metric to choose?}\label{which-disparity-metric-to-c \begin{Shaded} \begin{Highlighting}[] -\NormalTok{best.metric \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{() }\KeywordTok{return}\NormalTok{(}\DecValTok{42}\NormalTok{)} +\NormalTok{best.metric }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{() }\FunctionTok{return}\NormalTok{(}\DecValTok{42}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -3098,12 +2902,12 @@ \subsubsection{\texorpdfstring{\texttt{test.metric}}{test.metric}}\label{test-me \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Creating a 2D uniform space} -\NormalTok{example\_space \textless{}{-}}\StringTok{ }\KeywordTok{space.maker}\NormalTok{(}\DecValTok{300}\NormalTok{, }\DecValTok{2}\NormalTok{, runif)} +\DocumentationTok{\#\# Creating a 2D uniform space} +\NormalTok{example\_space }\OtherTok{\textless{}{-}} \FunctionTok{space.maker}\NormalTok{(}\DecValTok{300}\NormalTok{, }\DecValTok{2}\NormalTok{, runif)} -\CommentTok{\#\# Testing the product of ranges metric on the example space} -\NormalTok{example\_test \textless{}{-}}\StringTok{ }\KeywordTok{test.metric}\NormalTok{(example\_space, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(prod, ranges),} - \DataTypeTok{shifts =} \KeywordTok{c}\NormalTok{(}\StringTok{"random"}\NormalTok{, }\StringTok{"size"}\NormalTok{)) } +\DocumentationTok{\#\# Testing the product of ranges metric on the example space} +\NormalTok{example\_test }\OtherTok{\textless{}{-}} \FunctionTok{test.metric}\NormalTok{(example\_space, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(prod, ranges),} + \AttributeTok{shifts =} \FunctionTok{c}\NormalTok{(}\StringTok{"random"}\NormalTok{, }\StringTok{"size"}\NormalTok{)) } \end{Highlighting} \end{Shaded} @@ -3117,7 +2921,7 @@ \subsubsection{\texorpdfstring{\texttt{test.metric}}{test.metric}}\label{test-me \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The results as a dispRity object} +\DocumentationTok{\#\# The results as a dispRity object} \NormalTok{example\_test} \end{Highlighting} \end{Shaded} @@ -3132,30 +2936,30 @@ \subsubsection{\texorpdfstring{\texttt{test.metric}}{test.metric}}\label{test-me \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Summarising these results} -\KeywordTok{summary}\NormalTok{(example\_test)} +\DocumentationTok{\#\# Summarising these results} +\FunctionTok{summary}\NormalTok{(example\_test)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% slope -## random 0.84 0.88 0.94 0.95 0.96 0.98 0.97 0.98 0.96 0.98 1.450100e-03 -## size.increase 0.10 0.21 0.31 0.45 0.54 0.70 0.78 0.94 0.96 0.98 1.054925e-02 -## size.hollowness 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 1.453782e-05 +## random 0.94 0.97 0.94 0.97 0.98 0.98 0.99 0.99 0.99 0.99 6.389477e-04 +## size.increase 0.11 0.21 0.38 0.54 0.68 0.79 0.87 0.93 0.98 0.99 1.040938e-02 +## size.hollowness 0.98 0.99 0.99 0.99 0.99 0.99 0.99 0.99 0.99 0.99 1.880225e-05 ## p_value R^2(adj) -## random 2.439179e-06 0.5377136 -## size.increase 4.450564e-25 0.9783976 -## size.hollowness 1.925262e-05 0.4664502 +## random 5.891773e-06 0.5084747 +## size.increase 4.331947e-19 0.9422289 +## size.hollowness 3.073793e-03 0.2467532 \end{verbatim} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Or visualising them} -\KeywordTok{plot}\NormalTok{(example\_test)} +\DocumentationTok{\#\# Or visualising them} +\FunctionTok{plot}\NormalTok{(example\_test)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-77-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-78-1.pdf} \hypertarget{summarising-disprity-data-plots}{% \section{Summarising dispRity data (plots)}\label{summarising-disprity-data-plots}} @@ -3170,42 +2974,42 @@ \subsection{\texorpdfstring{Summarising \texttt{dispRity} data}{Summarising disp \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Example data from previous sections} -\NormalTok{crown\_stem \textless{}{-}}\StringTok{ }\KeywordTok{custom.subsets}\NormalTok{(BeckLee\_mat50,} - \DataTypeTok{group =} \KeywordTok{crown.stem}\NormalTok{(BeckLee\_tree,} - \DataTypeTok{inc.nodes =} \OtherTok{FALSE}\NormalTok{))} -\CommentTok{\#\# Bootstrapping and rarefying these groups} -\NormalTok{boot\_crown\_stem \textless{}{-}}\StringTok{ }\KeywordTok{boot.matrix}\NormalTok{(crown\_stem, }\DataTypeTok{bootstraps =} \DecValTok{100}\NormalTok{,} - \DataTypeTok{rarefaction =} \OtherTok{TRUE}\NormalTok{)} -\CommentTok{\#\# Calculate disparity} -\NormalTok{disparity\_crown\_stem \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(boot\_crown\_stem,} - \DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, variances))} - -\CommentTok{\#\# Creating time slice subsets} -\NormalTok{time\_slices \textless{}{-}}\StringTok{ }\KeywordTok{chrono.subsets}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_mat99,} - \DataTypeTok{tree =}\NormalTok{ BeckLee\_tree,} - \DataTypeTok{method =} \StringTok{"continuous"}\NormalTok{,} - \DataTypeTok{model =} \StringTok{"proximity"}\NormalTok{,} - \DataTypeTok{time =} \KeywordTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{40}\NormalTok{, }\DecValTok{0}\NormalTok{),} - \DataTypeTok{FADLAD =}\NormalTok{ BeckLee\_ages)} -\CommentTok{\#\# Bootstrapping the time slice subsets} -\NormalTok{boot\_time\_slices \textless{}{-}}\StringTok{ }\KeywordTok{boot.matrix}\NormalTok{(time\_slices, }\DataTypeTok{bootstraps =} \DecValTok{100}\NormalTok{)} -\CommentTok{\#\# Calculate disparity} -\NormalTok{disparity\_time\_slices \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(boot\_time\_slices,} - \DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, variances))} - -\CommentTok{\#\# Creating time bin subsets} -\NormalTok{time\_bins \textless{}{-}}\StringTok{ }\KeywordTok{chrono.subsets}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_mat99,} - \DataTypeTok{tree =}\NormalTok{ BeckLee\_tree, } - \DataTypeTok{method =} \StringTok{"discrete"}\NormalTok{,} - \DataTypeTok{time =} \KeywordTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{40}\NormalTok{, }\DecValTok{0}\NormalTok{),} - \DataTypeTok{FADLAD =}\NormalTok{ BeckLee\_ages,} - \DataTypeTok{inc.nodes =} \OtherTok{TRUE}\NormalTok{)} -\CommentTok{\#\# Bootstrapping the time bin subsets} -\NormalTok{boot\_time\_bins \textless{}{-}}\StringTok{ }\KeywordTok{boot.matrix}\NormalTok{(time\_bins, }\DataTypeTok{bootstraps =} \DecValTok{100}\NormalTok{)} -\CommentTok{\#\# Calculate disparity} -\NormalTok{disparity\_time\_bins \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(boot\_time\_bins,} - \DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, variances))} +\DocumentationTok{\#\# Example data from previous sections} +\NormalTok{crown\_stem }\OtherTok{\textless{}{-}} \FunctionTok{custom.subsets}\NormalTok{(BeckLee\_mat50,} + \AttributeTok{group =} \FunctionTok{crown.stem}\NormalTok{(BeckLee\_tree,} + \AttributeTok{inc.nodes =} \ConstantTok{FALSE}\NormalTok{))} +\DocumentationTok{\#\# Bootstrapping and rarefying these groups} +\NormalTok{boot\_crown\_stem }\OtherTok{\textless{}{-}} \FunctionTok{boot.matrix}\NormalTok{(crown\_stem, }\AttributeTok{bootstraps =} \DecValTok{100}\NormalTok{,} + \AttributeTok{rarefaction =} \ConstantTok{TRUE}\NormalTok{)} +\DocumentationTok{\#\# Calculate disparity} +\NormalTok{disparity\_crown\_stem }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(boot\_crown\_stem,} + \AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, variances))} + +\DocumentationTok{\#\# Creating time slice subsets} +\NormalTok{time\_slices }\OtherTok{\textless{}{-}} \FunctionTok{chrono.subsets}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_mat99,} + \AttributeTok{tree =}\NormalTok{ BeckLee\_tree,} + \AttributeTok{method =} \StringTok{"continuous"}\NormalTok{,} + \AttributeTok{model =} \StringTok{"proximity"}\NormalTok{,} + \AttributeTok{time =} \FunctionTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{40}\NormalTok{, }\DecValTok{0}\NormalTok{),} + \AttributeTok{FADLAD =}\NormalTok{ BeckLee\_ages)} +\DocumentationTok{\#\# Bootstrapping the time slice subsets} +\NormalTok{boot\_time\_slices }\OtherTok{\textless{}{-}} \FunctionTok{boot.matrix}\NormalTok{(time\_slices, }\AttributeTok{bootstraps =} \DecValTok{100}\NormalTok{)} +\DocumentationTok{\#\# Calculate disparity} +\NormalTok{disparity\_time\_slices }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(boot\_time\_slices,} + \AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, variances))} + +\DocumentationTok{\#\# Creating time bin subsets} +\NormalTok{time\_bins }\OtherTok{\textless{}{-}} \FunctionTok{chrono.subsets}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_mat99,} + \AttributeTok{tree =}\NormalTok{ BeckLee\_tree, } + \AttributeTok{method =} \StringTok{"discrete"}\NormalTok{,} + \AttributeTok{time =} \FunctionTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{40}\NormalTok{, }\DecValTok{0}\NormalTok{),} + \AttributeTok{FADLAD =}\NormalTok{ BeckLee\_ages,} + \AttributeTok{inc.nodes =} \ConstantTok{TRUE}\NormalTok{)} +\DocumentationTok{\#\# Bootstrapping the time bin subsets} +\NormalTok{boot\_time\_bins }\OtherTok{\textless{}{-}} \FunctionTok{boot.matrix}\NormalTok{(time\_bins, }\AttributeTok{bootstraps =} \DecValTok{100}\NormalTok{)} +\DocumentationTok{\#\# Calculate disparity} +\NormalTok{disparity\_time\_bins }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(boot\_time\_bins,} + \AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, variances))} \end{Highlighting} \end{Shaded} @@ -3213,17 +3017,17 @@ \subsection{\texorpdfstring{Summarising \texttt{dispRity} data}{Summarising disp \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Default summary} -\KeywordTok{summary}\NormalTok{(disparity\_time\_slices)} +\DocumentationTok{\#\# Default summary} +\FunctionTok{summary}\NormalTok{(disparity\_time\_slices)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## subsets n obs bs.median 2.5% 25% 75% 97.5% -## 1 120 5 3.258 2.675 1.264 2.436 2.948 3.085 -## 2 80 19 3.491 3.315 3.128 3.266 3.362 3.453 -## 3 40 15 3.677 3.453 3.157 3.349 3.547 3.681 -## 4 0 10 4.092 3.726 3.293 3.578 3.828 3.950 +## 1 120 5 3.126 2.556 1.446 2.365 2.799 2.975 +## 2 80 19 3.351 3.188 3.019 3.137 3.235 3.291 +## 3 40 15 3.538 3.346 3.052 3.226 3.402 3.538 +## 4 0 10 3.934 3.601 3.219 3.446 3.681 3.819 \end{verbatim} Information about the number of elements in each subset and the observed (i.e.~non-bootstrapped) disparity are also calculated. @@ -3231,18 +3035,18 @@ \subsection{\texorpdfstring{Summarising \texttt{dispRity} data}{Summarising disp \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{head}\NormalTok{(}\KeywordTok{summary}\NormalTok{(disparity\_crown\_stem))} +\FunctionTok{head}\NormalTok{(}\FunctionTok{summary}\NormalTok{(disparity\_crown\_stem))} \end{Highlighting} \end{Shaded} \begin{verbatim} ## subsets n obs bs.median 2.5% 25% 75% 97.5% -## 1 crown 30 2.526 2.441 2.367 2.420 2.466 2.487 -## 2 crown 29 NA 2.449 2.354 2.428 2.468 2.490 -## 3 crown 28 NA 2.441 2.385 2.422 2.457 2.485 -## 4 crown 27 NA 2.442 2.363 2.411 2.465 2.490 -## 5 crown 26 NA 2.438 2.350 2.416 2.458 2.494 -## 6 crown 25 NA 2.447 2.359 2.423 2.471 2.496 +## 1 crown 30 2.526 2.444 2.374 2.420 2.466 2.490 +## 2 crown 29 NA 2.454 2.387 2.427 2.470 2.490 +## 3 crown 28 NA 2.443 2.387 2.423 2.462 2.489 +## 4 crown 27 NA 2.440 2.366 2.417 2.468 2.493 +## 5 crown 26 NA 2.442 2.357 2.408 2.459 2.492 +## 6 crown 25 NA 2.445 2.344 2.425 2.469 2.490 \end{verbatim} The summary functions can also take various options such as: @@ -3263,23 +3067,23 @@ \subsection{\texorpdfstring{Summarising \texttt{dispRity} data}{Summarising disp \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Same as above but using the 88th quantile and the standard deviation as the summary } -\KeywordTok{summary}\NormalTok{(disparity\_time\_slices, }\DataTypeTok{quantiles =} \DecValTok{88}\NormalTok{, }\DataTypeTok{cent.tend =}\NormalTok{ sd)} +\DocumentationTok{\#\# Same as above but using the 88th quantile and the standard deviation as the summary } +\FunctionTok{summary}\NormalTok{(disparity\_time\_slices, }\AttributeTok{quantiles =} \DecValTok{88}\NormalTok{, }\AttributeTok{cent.tend =}\NormalTok{ sd)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## subsets n obs bs.sd 6% 94% -## 1 120 5 3.258 0.426 1.864 3.075 -## 2 80 19 3.491 0.084 3.156 3.435 -## 3 40 15 3.677 0.149 3.231 3.650 -## 4 0 10 4.092 0.195 3.335 3.904 +## 1 120 5 3.126 0.366 2.043 2.947 +## 2 80 19 3.351 0.072 3.048 3.277 +## 3 40 15 3.538 0.133 3.095 3.525 +## 4 0 10 3.934 0.167 3.292 3.776 \end{verbatim} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Printing the details of the object and digits the values to the 5th decimal place} -\KeywordTok{summary}\NormalTok{(disparity\_time\_slices, }\DataTypeTok{recall =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{digits =} \DecValTok{5}\NormalTok{)} +\DocumentationTok{\#\# Printing the details of the object and digits the values to the 5th decimal place} +\FunctionTok{summary}\NormalTok{(disparity\_time\_slices, }\AttributeTok{recall =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{digits =} \DecValTok{5}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -3287,16 +3091,16 @@ \subsection{\texorpdfstring{Summarising \texttt{dispRity} data}{Summarising disp ## ---- dispRity object ---- ## 4 continuous (proximity) time subsets for 99 elements in one matrix with 97 dimensions with 1 phylogenetic tree ## 120, 80, 40, 0. -## Data was bootstrapped 100 times (method:"full"). +## Rows were bootstrapped 100 times (method:"full"). ## Disparity was calculated as: c(sum, variances). \end{verbatim} \begin{verbatim} ## subsets n obs bs.median 2.5% 25% 75% 97.5% -## 1 120 5 3.25815 2.67517 1.26366 2.43637 2.94780 3.08485 -## 2 80 19 3.49145 3.31487 3.12837 3.26601 3.36182 3.45336 -## 3 40 15 3.67702 3.45329 3.15729 3.34867 3.54670 3.68134 -## 4 0 10 4.09234 3.72554 3.29285 3.57797 3.82814 3.95046 +## 1 120 5 3.12580 2.55631 1.44593 2.36454 2.79905 2.97520 +## 2 80 19 3.35072 3.18751 3.01906 3.13720 3.23534 3.29113 +## 3 40 15 3.53811 3.34647 3.05242 3.22616 3.40199 3.53793 +## 4 0 10 3.93353 3.60071 3.21947 3.44555 3.68095 3.81856 \end{verbatim} Note that the summary table is a \texttt{data.frame}, hence it is as easy to modify as any dataframe using \texttt{dplyr}. @@ -3304,10 +3108,10 @@ \subsection{\texorpdfstring{Summarising \texttt{dispRity} data}{Summarising disp \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Loading the xtable package} -\KeywordTok{require}\NormalTok{(xtable)} -\CommentTok{\#\# Converting the table in LaTeX} -\KeywordTok{xtable}\NormalTok{(}\KeywordTok{summary}\NormalTok{(disparity\_time\_slices))} +\DocumentationTok{\#\# Loading the xtable package} +\FunctionTok{require}\NormalTok{(xtable)} +\DocumentationTok{\#\# Converting the table in LaTeX} +\FunctionTok{xtable}\NormalTok{(}\FunctionTok{summary}\NormalTok{(disparity\_time\_slices))} \end{Highlighting} \end{Shaded} @@ -3338,29 +3142,29 @@ \subsection{\texorpdfstring{Plotting \texttt{dispRity} data}{Plotting dispRity d \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Graphical parameters} -\NormalTok{op \textless{}{-}}\StringTok{ }\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =} \KeywordTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{, }\DecValTok{2}\NormalTok{), }\DataTypeTok{bty =} \StringTok{"n"}\NormalTok{)} +\DocumentationTok{\#\# Graphical parameters} +\NormalTok{op }\OtherTok{\textless{}{-}} \FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =} \FunctionTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{, }\DecValTok{2}\NormalTok{), }\AttributeTok{bty =} \StringTok{"n"}\NormalTok{)} -\CommentTok{\#\# Plotting continuous disparity results} -\KeywordTok{plot}\NormalTok{(disparity\_time\_slices, }\DataTypeTok{type =} \StringTok{"continuous"}\NormalTok{)} +\DocumentationTok{\#\# Plotting continuous disparity results} +\FunctionTok{plot}\NormalTok{(disparity\_time\_slices, }\AttributeTok{type =} \StringTok{"continuous"}\NormalTok{)} -\CommentTok{\#\# Plotting discrete disparity results} -\KeywordTok{plot}\NormalTok{(disparity\_crown\_stem, }\DataTypeTok{type =} \StringTok{"box"}\NormalTok{)} +\DocumentationTok{\#\# Plotting discrete disparity results} +\FunctionTok{plot}\NormalTok{(disparity\_crown\_stem, }\AttributeTok{type =} \StringTok{"box"}\NormalTok{)} -\CommentTok{\#\# As above but using lines for the rarefaction level of 20 elements only} -\KeywordTok{plot}\NormalTok{(disparity\_crown\_stem, }\DataTypeTok{type =} \StringTok{"line"}\NormalTok{, }\DataTypeTok{rarefaction =} \DecValTok{20}\NormalTok{)} +\DocumentationTok{\#\# As above but using lines for the rarefaction level of 20 elements only} +\FunctionTok{plot}\NormalTok{(disparity\_crown\_stem, }\AttributeTok{type =} \StringTok{"line"}\NormalTok{, }\AttributeTok{rarefaction =} \DecValTok{20}\NormalTok{)} -\CommentTok{\#\# As above but using polygons while also displaying the number of elements} -\KeywordTok{plot}\NormalTok{(disparity\_crown\_stem, }\DataTypeTok{type =} \StringTok{"polygon"}\NormalTok{, }\DataTypeTok{elements =} \OtherTok{TRUE}\NormalTok{)} +\DocumentationTok{\#\# As above but using polygons while also displaying the number of elements} +\FunctionTok{plot}\NormalTok{(disparity\_crown\_stem, }\AttributeTok{type =} \StringTok{"polygon"}\NormalTok{, }\AttributeTok{elements =} \ConstantTok{TRUE}\NormalTok{)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-83-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-84-1.pdf} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Resetting graphical parameters} -\KeywordTok{par}\NormalTok{(op)} +\DocumentationTok{\#\# Resetting graphical parameters} +\FunctionTok{par}\NormalTok{(op)} \end{Highlighting} \end{Shaded} @@ -3368,28 +3172,28 @@ \subsection{\texorpdfstring{Plotting \texttt{dispRity} data}{Plotting dispRity d \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Graphical options} -\NormalTok{op \textless{}{-}}\StringTok{ }\KeywordTok{par}\NormalTok{(}\DataTypeTok{bty =} \StringTok{"n"}\NormalTok{)} +\DocumentationTok{\#\# Graphical options} +\NormalTok{op }\OtherTok{\textless{}{-}} \FunctionTok{par}\NormalTok{(}\AttributeTok{bty =} \StringTok{"n"}\NormalTok{)} -\CommentTok{\#\# Plotting the results with some classic options from plot} -\KeywordTok{plot}\NormalTok{(disparity\_time\_slices, }\DataTypeTok{col =} \KeywordTok{c}\NormalTok{(}\StringTok{"blue"}\NormalTok{, }\StringTok{"orange"}\NormalTok{, }\StringTok{"green"}\NormalTok{),} - \DataTypeTok{ylab =} \KeywordTok{c}\NormalTok{(}\StringTok{"Some measurement"}\NormalTok{), }\DataTypeTok{xlab =} \StringTok{"Some other measurement"}\NormalTok{,} - \DataTypeTok{main =} \StringTok{"Many options..."}\NormalTok{, }\DataTypeTok{ylim =} \KeywordTok{c}\NormalTok{(}\DecValTok{10}\NormalTok{, }\DecValTok{0}\NormalTok{), }\DataTypeTok{xlim =} \KeywordTok{c}\NormalTok{(}\DecValTok{4}\NormalTok{, }\DecValTok{0}\NormalTok{))} +\DocumentationTok{\#\# Plotting the results with some classic options from plot} +\FunctionTok{plot}\NormalTok{(disparity\_time\_slices, }\AttributeTok{col =} \FunctionTok{c}\NormalTok{(}\StringTok{"blue"}\NormalTok{, }\StringTok{"orange"}\NormalTok{, }\StringTok{"green"}\NormalTok{),} + \AttributeTok{ylab =} \FunctionTok{c}\NormalTok{(}\StringTok{"Some measurement"}\NormalTok{), }\AttributeTok{xlab =} \StringTok{"Some other measurement"}\NormalTok{,} + \AttributeTok{main =} \StringTok{"Many options..."}\NormalTok{, }\AttributeTok{ylim =} \FunctionTok{c}\NormalTok{(}\DecValTok{10}\NormalTok{, }\DecValTok{0}\NormalTok{), }\AttributeTok{xlim =} \FunctionTok{c}\NormalTok{(}\DecValTok{4}\NormalTok{, }\DecValTok{0}\NormalTok{))} -\CommentTok{\#\# Adding a legend} -\KeywordTok{legend}\NormalTok{(}\StringTok{"topleft"}\NormalTok{, }\DataTypeTok{legend =} \KeywordTok{c}\NormalTok{(}\StringTok{"Central tendency"}\NormalTok{,} +\DocumentationTok{\#\# Adding a legend} +\FunctionTok{legend}\NormalTok{(}\StringTok{"topleft"}\NormalTok{, }\AttributeTok{legend =} \FunctionTok{c}\NormalTok{(}\StringTok{"Central tendency"}\NormalTok{,} \StringTok{"Confidence interval 1"}\NormalTok{,} \StringTok{"Confidence interval 2"}\NormalTok{),} - \DataTypeTok{col =} \KeywordTok{c}\NormalTok{(}\StringTok{"blue"}\NormalTok{, }\StringTok{"orange"}\NormalTok{, }\StringTok{"green"}\NormalTok{), }\DataTypeTok{pch =} \DecValTok{19}\NormalTok{)} + \AttributeTok{col =} \FunctionTok{c}\NormalTok{(}\StringTok{"blue"}\NormalTok{, }\StringTok{"orange"}\NormalTok{, }\StringTok{"green"}\NormalTok{), }\AttributeTok{pch =} \DecValTok{19}\NormalTok{)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-84-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-85-1.pdf} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Resetting graphical parameters} -\KeywordTok{par}\NormalTok{(op)} +\DocumentationTok{\#\# Resetting graphical parameters} +\FunctionTok{par}\NormalTok{(op)} \end{Highlighting} \end{Shaded} @@ -3397,27 +3201,27 @@ \subsection{\texorpdfstring{Plotting \texttt{dispRity} data}{Plotting dispRity d \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Graphical options} -\NormalTok{op \textless{}{-}}\StringTok{ }\KeywordTok{par}\NormalTok{(}\DataTypeTok{bty =} \StringTok{"n"}\NormalTok{)} +\DocumentationTok{\#\# Graphical options} +\NormalTok{op }\OtherTok{\textless{}{-}} \FunctionTok{par}\NormalTok{(}\AttributeTok{bty =} \StringTok{"n"}\NormalTok{)} -\CommentTok{\#\# Plotting the results with some plot.dispRity arguments} -\KeywordTok{plot}\NormalTok{(disparity\_time\_slices,} - \DataTypeTok{quantiles =} \KeywordTok{c}\NormalTok{(}\KeywordTok{seq}\NormalTok{(}\DataTypeTok{from =} \DecValTok{10}\NormalTok{, }\DataTypeTok{to =} \DecValTok{100}\NormalTok{, }\DataTypeTok{by =} \DecValTok{10}\NormalTok{)),} - \DataTypeTok{cent.tend =}\NormalTok{ sd, }\DataTypeTok{type =} \StringTok{"c"}\NormalTok{, }\DataTypeTok{elements =} \OtherTok{TRUE}\NormalTok{,} - \DataTypeTok{col =} \KeywordTok{c}\NormalTok{(}\StringTok{"black"}\NormalTok{, }\KeywordTok{rainbow}\NormalTok{(}\DecValTok{10}\NormalTok{)),} - \DataTypeTok{ylab =} \KeywordTok{c}\NormalTok{(}\StringTok{"Disparity"}\NormalTok{, }\StringTok{"Diversity"}\NormalTok{),} - \DataTypeTok{xlab =} \StringTok{"Time (in in units from past to present)"}\NormalTok{,} - \DataTypeTok{observed =} \OtherTok{TRUE}\NormalTok{,} - \DataTypeTok{main =} \StringTok{"Many more options..."}\NormalTok{)} +\DocumentationTok{\#\# Plotting the results with some plot.dispRity arguments} +\FunctionTok{plot}\NormalTok{(disparity\_time\_slices,} + \AttributeTok{quantiles =} \FunctionTok{c}\NormalTok{(}\FunctionTok{seq}\NormalTok{(}\AttributeTok{from =} \DecValTok{10}\NormalTok{, }\AttributeTok{to =} \DecValTok{100}\NormalTok{, }\AttributeTok{by =} \DecValTok{10}\NormalTok{)),} + \AttributeTok{cent.tend =}\NormalTok{ sd, }\AttributeTok{type =} \StringTok{"c"}\NormalTok{, }\AttributeTok{elements =} \ConstantTok{TRUE}\NormalTok{,} + \AttributeTok{col =} \FunctionTok{c}\NormalTok{(}\StringTok{"black"}\NormalTok{, }\FunctionTok{rainbow}\NormalTok{(}\DecValTok{10}\NormalTok{)),} + \AttributeTok{ylab =} \FunctionTok{c}\NormalTok{(}\StringTok{"Disparity"}\NormalTok{, }\StringTok{"Diversity"}\NormalTok{),} + \AttributeTok{xlab =} \StringTok{"Time (in in units from past to present)"}\NormalTok{,} + \AttributeTok{observed =} \ConstantTok{TRUE}\NormalTok{,} + \AttributeTok{main =} \StringTok{"Many more options..."}\NormalTok{)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-85-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-86-1.pdf} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Resetting graphical parameters} -\KeywordTok{par}\NormalTok{(op)} +\DocumentationTok{\#\# Resetting graphical parameters} +\FunctionTok{par}\NormalTok{(op)} \end{Highlighting} \end{Shaded} @@ -3429,23 +3233,23 @@ \subsection{\texorpdfstring{Plotting \texttt{dispRity} data}{Plotting dispRity d \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Graphical options} -\NormalTok{op \textless{}{-}}\StringTok{ }\KeywordTok{par}\NormalTok{(}\DataTypeTok{bty =} \StringTok{"n"}\NormalTok{)} +\DocumentationTok{\#\# Graphical options} +\NormalTok{op }\OtherTok{\textless{}{-}} \FunctionTok{par}\NormalTok{(}\AttributeTok{bty =} \StringTok{"n"}\NormalTok{)} -\CommentTok{\#\# Plotting the continuous disparity with a fixed y axis} -\KeywordTok{plot}\NormalTok{(disparity\_time\_slices, }\DataTypeTok{ylim =} \KeywordTok{c}\NormalTok{(}\DecValTok{3}\NormalTok{, }\DecValTok{9}\NormalTok{))} -\CommentTok{\#\# Adding the discrete data} -\KeywordTok{plot}\NormalTok{(disparity\_time\_bins, }\DataTypeTok{type =} \StringTok{"line"}\NormalTok{, }\DataTypeTok{ylim =} \KeywordTok{c}\NormalTok{(}\DecValTok{3}\NormalTok{, }\DecValTok{9}\NormalTok{),} - \DataTypeTok{xlab =} \StringTok{""}\NormalTok{, }\DataTypeTok{ylab =} \StringTok{""}\NormalTok{, }\DataTypeTok{add =} \OtherTok{TRUE}\NormalTok{)} +\DocumentationTok{\#\# Plotting the continuous disparity with a fixed y axis} +\FunctionTok{plot}\NormalTok{(disparity\_time\_slices, }\AttributeTok{ylim =} \FunctionTok{c}\NormalTok{(}\DecValTok{3}\NormalTok{, }\DecValTok{9}\NormalTok{))} +\DocumentationTok{\#\# Adding the discrete data} +\FunctionTok{plot}\NormalTok{(disparity\_time\_bins, }\AttributeTok{type =} \StringTok{"line"}\NormalTok{, }\AttributeTok{ylim =} \FunctionTok{c}\NormalTok{(}\DecValTok{3}\NormalTok{, }\DecValTok{9}\NormalTok{),} + \AttributeTok{xlab =} \StringTok{""}\NormalTok{, }\AttributeTok{ylab =} \StringTok{""}\NormalTok{, }\AttributeTok{add =} \ConstantTok{TRUE}\NormalTok{)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-86-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-87-1.pdf} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Resetting graphical parameters} -\KeywordTok{par}\NormalTok{(op)} +\DocumentationTok{\#\# Resetting graphical parameters} +\FunctionTok{par}\NormalTok{(op)} \end{Highlighting} \end{Shaded} @@ -3453,20 +3257,20 @@ \subsection{\texorpdfstring{Plotting \texttt{dispRity} data}{Plotting dispRity d \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Graphical options} -\NormalTok{op \textless{}{-}}\StringTok{ }\KeywordTok{par}\NormalTok{(}\DataTypeTok{bty =} \StringTok{"n"}\NormalTok{)} +\DocumentationTok{\#\# Graphical options} +\NormalTok{op }\OtherTok{\textless{}{-}} \FunctionTok{par}\NormalTok{(}\AttributeTok{bty =} \StringTok{"n"}\NormalTok{)} -\CommentTok{\#\# Plotting the rarefaction curves} -\KeywordTok{plot}\NormalTok{(disparity\_crown\_stem, }\DataTypeTok{rarefaction =} \OtherTok{TRUE}\NormalTok{)} +\DocumentationTok{\#\# Plotting the rarefaction curves} +\FunctionTok{plot}\NormalTok{(disparity\_crown\_stem, }\AttributeTok{rarefaction =} \ConstantTok{TRUE}\NormalTok{)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-87-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-88-1.pdf} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Resetting graphical parameters} -\KeywordTok{par}\NormalTok{(op)} +\DocumentationTok{\#\# Resetting graphical parameters} +\FunctionTok{par}\NormalTok{(op)} \end{Highlighting} \end{Shaded} @@ -3482,17 +3286,17 @@ \subsection{\texorpdfstring{\texttt{type\ =\ preview}}{type = preview}}\label{ty \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Making the different subsets} -\NormalTok{cust\_subsets \textless{}{-}}\StringTok{ }\KeywordTok{custom.subsets}\NormalTok{(BeckLee\_mat99,} - \KeywordTok{crown.stem}\NormalTok{(BeckLee\_tree,} - \DataTypeTok{inc.nodes =} \OtherTok{TRUE}\NormalTok{))} -\NormalTok{time\_subsets \textless{}{-}}\StringTok{ }\KeywordTok{chrono.subsets}\NormalTok{(BeckLee\_mat99,} - \DataTypeTok{tree =}\NormalTok{ BeckLee\_tree,} - \DataTypeTok{method =} \StringTok{"discrete"}\NormalTok{,} - \DataTypeTok{time =} \DecValTok{5}\NormalTok{)} +\DocumentationTok{\#\# Making the different subsets} +\NormalTok{cust\_subsets }\OtherTok{\textless{}{-}} \FunctionTok{custom.subsets}\NormalTok{(BeckLee\_mat99,} + \FunctionTok{crown.stem}\NormalTok{(BeckLee\_tree,} + \AttributeTok{inc.nodes =} \ConstantTok{TRUE}\NormalTok{))} +\NormalTok{time\_subsets }\OtherTok{\textless{}{-}} \FunctionTok{chrono.subsets}\NormalTok{(BeckLee\_mat99,} + \AttributeTok{tree =}\NormalTok{ BeckLee\_tree,} + \AttributeTok{method =} \StringTok{"discrete"}\NormalTok{,} + \AttributeTok{time =} \DecValTok{5}\NormalTok{)} -\CommentTok{\#\# Note that no disparity has been calculated here:} -\KeywordTok{is.null}\NormalTok{(cust\_subsets}\OperatorTok{$}\NormalTok{disparity)} +\DocumentationTok{\#\# Note that no disparity has been calculated here:} +\FunctionTok{is.null}\NormalTok{(cust\_subsets}\SpecialCharTok{$}\NormalTok{disparity)} \end{Highlighting} \end{Shaded} @@ -3502,7 +3306,7 @@ \subsection{\texorpdfstring{\texttt{type\ =\ preview}}{type = preview}}\label{ty \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{is.null}\NormalTok{(time\_subsets}\OperatorTok{$}\NormalTok{disparity)} +\FunctionTok{is.null}\NormalTok{(time\_subsets}\SpecialCharTok{$}\NormalTok{disparity)} \end{Highlighting} \end{Shaded} @@ -3512,17 +3316,17 @@ \subsection{\texorpdfstring{\texttt{type\ =\ preview}}{type = preview}}\label{ty \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# But we can still plot both spaces by using the default plot functions} -\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =} \KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{))} -\CommentTok{\#\# Default plotting} -\KeywordTok{plot}\NormalTok{(cust\_subsets)} -\CommentTok{\#\# Plotting with more arguments} -\KeywordTok{plot}\NormalTok{(time\_subsets, }\DataTypeTok{specific.args =} \KeywordTok{list}\NormalTok{(}\DataTypeTok{dimensions =} \KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{)),} - \DataTypeTok{main =} \StringTok{"Some }\CharTok{\textbackslash{}"}\StringTok{low}\CharTok{\textbackslash{}"}\StringTok{ dimensions"}\NormalTok{)} +\DocumentationTok{\#\# But we can still plot both spaces by using the default plot functions} +\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =} \FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{))} +\DocumentationTok{\#\# Default plotting} +\FunctionTok{plot}\NormalTok{(cust\_subsets)} +\DocumentationTok{\#\# Plotting with more arguments} +\FunctionTok{plot}\NormalTok{(time\_subsets, }\AttributeTok{specific.args =} \FunctionTok{list}\NormalTok{(}\AttributeTok{dimensions =} \FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{)),} + \AttributeTok{main =} \StringTok{"Some }\SpecialCharTok{\textbackslash{}"}\StringTok{low}\SpecialCharTok{\textbackslash{}"}\StringTok{ dimensions"}\NormalTok{)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-88-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-89-1.pdf} \begin{quote} DISCLAIMER: This functionality can be handy for exploring the data (e.g.~to visually check whether the subset attribution worked) but it might be misleading on how the data is \emph{actually} distributed in the multidimensional space! @@ -3534,16 +3338,16 @@ \subsection{\texorpdfstring{\texttt{type\ =\ preview}}{type = preview}}\label{ty \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =} \KeywordTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{1}\NormalTok{))} -\CommentTok{\#\# Default plotting} -\KeywordTok{plot}\NormalTok{(disparity\_time\_slices, }\DataTypeTok{main =} \StringTok{"Disparity through time"}\NormalTok{)} -\CommentTok{\#\# Plotting with more arguments} -\KeywordTok{plot}\NormalTok{(disparity\_time\_slices, }\DataTypeTok{type =} \StringTok{"preview"}\NormalTok{,} - \DataTypeTok{main =} \StringTok{"Two first dimensions of the trait space"}\NormalTok{)} +\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =} \FunctionTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{1}\NormalTok{))} +\DocumentationTok{\#\# Default plotting} +\FunctionTok{plot}\NormalTok{(disparity\_time\_slices, }\AttributeTok{main =} \StringTok{"Disparity through time"}\NormalTok{)} +\DocumentationTok{\#\# Plotting with more arguments} +\FunctionTok{plot}\NormalTok{(disparity\_time\_slices, }\AttributeTok{type =} \StringTok{"preview"}\NormalTok{,} + \AttributeTok{main =} \StringTok{"Two first dimensions of the trait space"}\NormalTok{)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-89-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-90-1.pdf} \hypertarget{graphical-options-with-...}{% \subsection{\texorpdfstring{Graphical options with \texttt{...}}{Graphical options with ...}}\label{graphical-options-with-...}} @@ -3558,39 +3362,39 @@ \subsection{\texorpdfstring{Graphical options with \texttt{...}}{Graphical optio \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Loading some demo data:} -\CommentTok{\#\# An ordinated matrix with node and tip labels} -\KeywordTok{data}\NormalTok{(BeckLee\_mat99)} -\CommentTok{\#\# The corresponding tree with tip and node labels} -\KeywordTok{data}\NormalTok{(BeckLee\_tree)} -\CommentTok{\#\# A list of tips ages for the fossil data} -\KeywordTok{data}\NormalTok{(BeckLee\_ages)} +\DocumentationTok{\#\# Loading some demo data:} +\DocumentationTok{\#\# An ordinated matrix with node and tip labels} +\FunctionTok{data}\NormalTok{(BeckLee\_mat99)} +\DocumentationTok{\#\# The corresponding tree with tip and node labels} +\FunctionTok{data}\NormalTok{(BeckLee\_tree)} +\DocumentationTok{\#\# A list of tips ages for the fossil data} +\FunctionTok{data}\NormalTok{(BeckLee\_ages)} -\CommentTok{\#\# Time slicing through the tree using the equal split algorithm} -\NormalTok{time\_slices \textless{}{-}}\StringTok{ }\KeywordTok{chrono.subsets}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_mat99,} - \DataTypeTok{tree =}\NormalTok{ BeckLee\_tree,} - \DataTypeTok{FADLAD =}\NormalTok{ BeckLee\_ages,} - \DataTypeTok{method =} \StringTok{"continuous"}\NormalTok{,} - \DataTypeTok{model =} \StringTok{"acctran"}\NormalTok{,} - \DataTypeTok{time =} \DecValTok{15}\NormalTok{)} +\DocumentationTok{\#\# Time slicing through the tree using the equal split algorithm} +\NormalTok{time\_slices }\OtherTok{\textless{}{-}} \FunctionTok{chrono.subsets}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_mat99,} + \AttributeTok{tree =}\NormalTok{ BeckLee\_tree,} + \AttributeTok{FADLAD =}\NormalTok{ BeckLee\_ages,} + \AttributeTok{method =} \StringTok{"continuous"}\NormalTok{,} + \AttributeTok{model =} \StringTok{"acctran"}\NormalTok{,} + \AttributeTok{time =} \DecValTok{15}\NormalTok{)} -\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =} \KeywordTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{))} -\CommentTok{\#\# The preview plot with the tree using only defaults} -\KeywordTok{plot}\NormalTok{(time\_slices, }\DataTypeTok{type =} \StringTok{"preview"}\NormalTok{, }\DataTypeTok{specific.args =} \KeywordTok{list}\NormalTok{(}\DataTypeTok{tree =} \OtherTok{TRUE}\NormalTok{))} -\CommentTok{\#\# The same plot but by applying general options} -\KeywordTok{plot}\NormalTok{(time\_slices, }\DataTypeTok{type =} \StringTok{"preview"}\NormalTok{, }\DataTypeTok{specific.args =} \KeywordTok{list}\NormalTok{(}\DataTypeTok{tree =} \OtherTok{TRUE}\NormalTok{),} - \DataTypeTok{col =} \StringTok{"blue"}\NormalTok{, }\DataTypeTok{main =} \StringTok{"General options"}\NormalTok{)} -\CommentTok{\#\# The same plot but by applying the colour only to the lines} -\CommentTok{\#\# and change of shape only to the points} -\KeywordTok{plot}\NormalTok{(time\_slices, }\DataTypeTok{type =} \StringTok{"preview"}\NormalTok{, }\DataTypeTok{specific.args =} \KeywordTok{list}\NormalTok{(}\DataTypeTok{tree =} \OtherTok{TRUE}\NormalTok{),} - \DataTypeTok{lines.col =} \StringTok{"blue"}\NormalTok{, }\DataTypeTok{points.pch =} \DecValTok{15}\NormalTok{, }\DataTypeTok{main =} \StringTok{"Specific options"}\NormalTok{)} -\CommentTok{\#\# And now without the legend} -\KeywordTok{plot}\NormalTok{(time\_slices, }\DataTypeTok{type =} \StringTok{"preview"}\NormalTok{, }\DataTypeTok{specific.args =} \KeywordTok{list}\NormalTok{(}\DataTypeTok{tree =} \OtherTok{TRUE}\NormalTok{),} - \DataTypeTok{lines.col =} \StringTok{"blue"}\NormalTok{, }\DataTypeTok{points.pch =} \DecValTok{15}\NormalTok{, }\DataTypeTok{legend =} \OtherTok{FALSE}\NormalTok{)} +\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =} \FunctionTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{))} +\DocumentationTok{\#\# The preview plot with the tree using only defaults} +\FunctionTok{plot}\NormalTok{(time\_slices, }\AttributeTok{type =} \StringTok{"preview"}\NormalTok{, }\AttributeTok{specific.args =} \FunctionTok{list}\NormalTok{(}\AttributeTok{tree =} \ConstantTok{TRUE}\NormalTok{))} +\DocumentationTok{\#\# The same plot but by applying general options} +\FunctionTok{plot}\NormalTok{(time\_slices, }\AttributeTok{type =} \StringTok{"preview"}\NormalTok{, }\AttributeTok{specific.args =} \FunctionTok{list}\NormalTok{(}\AttributeTok{tree =} \ConstantTok{TRUE}\NormalTok{),} + \AttributeTok{col =} \StringTok{"blue"}\NormalTok{, }\AttributeTok{main =} \StringTok{"General options"}\NormalTok{)} +\DocumentationTok{\#\# The same plot but by applying the colour only to the lines} +\DocumentationTok{\#\# and change of shape only to the points} +\FunctionTok{plot}\NormalTok{(time\_slices, }\AttributeTok{type =} \StringTok{"preview"}\NormalTok{, }\AttributeTok{specific.args =} \FunctionTok{list}\NormalTok{(}\AttributeTok{tree =} \ConstantTok{TRUE}\NormalTok{),} + \AttributeTok{lines.col =} \StringTok{"blue"}\NormalTok{, }\AttributeTok{points.pch =} \DecValTok{15}\NormalTok{, }\AttributeTok{main =} \StringTok{"Specific options"}\NormalTok{)} +\DocumentationTok{\#\# And now without the legend} +\FunctionTok{plot}\NormalTok{(time\_slices, }\AttributeTok{type =} \StringTok{"preview"}\NormalTok{, }\AttributeTok{specific.args =} \FunctionTok{list}\NormalTok{(}\AttributeTok{tree =} \ConstantTok{TRUE}\NormalTok{),} + \AttributeTok{lines.col =} \StringTok{"blue"}\NormalTok{, }\AttributeTok{points.pch =} \DecValTok{15}\NormalTok{, }\AttributeTok{legend =} \ConstantTok{FALSE}\NormalTok{)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-90-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-91-1.pdf} \hypertarget{testing-disparity-hypotheses}{% \section{Testing disparity hypotheses}\label{testing-disparity-hypotheses}} @@ -3628,33 +3432,33 @@ \section{Testing disparity hypotheses}\label{testing-disparity-hypotheses}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# T{-}test to test for a difference in disparity between crown and stem mammals} -\KeywordTok{test.dispRity}\NormalTok{(disparity\_crown\_stem, }\DataTypeTok{test =}\NormalTok{ t.test)} +\DocumentationTok{\#\# T{-}test to test for a difference in disparity between crown and stem mammals} +\FunctionTok{test.dispRity}\NormalTok{(disparity\_crown\_stem, }\AttributeTok{test =}\NormalTok{ t.test)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## [[1]] ## statistic: t -## crown : stem 57.38116 +## crown : stem 54.10423 ## ## [[2]] ## parameter: df -## crown : stem 184.8496 +## crown : stem 177.9857 ## ## [[3]] ## p.value -## crown : stem 9.763665e-120 +## crown : stem 1.928983e-112 ## ## [[4]] ## stderr -## crown : stem 0.005417012 +## crown : stem 0.005649615 \end{verbatim} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Performing the same test but with the detailed t.test output} -\KeywordTok{test.dispRity}\NormalTok{(disparity\_crown\_stem, }\DataTypeTok{test =}\NormalTok{ t.test, }\DataTypeTok{details =} \OtherTok{TRUE}\NormalTok{)} +\DocumentationTok{\#\# Performing the same test but with the detailed t.test output} +\FunctionTok{test.dispRity}\NormalTok{(disparity\_crown\_stem, }\AttributeTok{test =}\NormalTok{ t.test, }\AttributeTok{details =} \ConstantTok{TRUE}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -3665,51 +3469,51 @@ \section{Testing disparity hypotheses}\label{testing-disparity-hypotheses}} ## Welch Two Sample t-test ## ## data: dots[[1L]][[1L]] and dots[[2L]][[1L]] -## t = 57.381, df = 184.85, p-value < 2.2e-16 +## t = 54.104, df = 177.99, p-value < 2.2e-16 ## alternative hypothesis: true difference in means is not equal to 0 ## 95 percent confidence interval: -## 0.3001473 0.3215215 +## 0.2945193 0.3168170 ## sample estimates: ## mean of x mean of y -## 2.440611 2.129776 +## 2.440968 2.135299 \end{verbatim} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Wilcoxon test applied to time sliced disparity with sequential comparisons,} -\CommentTok{\#\# with Bonferroni correction} -\KeywordTok{test.dispRity}\NormalTok{(disparity\_time\_slices, }\DataTypeTok{test =}\NormalTok{ wilcox.test,} - \DataTypeTok{comparisons =} \StringTok{"sequential"}\NormalTok{, }\DataTypeTok{correction =} \StringTok{"bonferroni"}\NormalTok{)} +\DocumentationTok{\#\# Wilcoxon test applied to time sliced disparity with sequential comparisons,} +\DocumentationTok{\#\# with Bonferroni correction} +\FunctionTok{test.dispRity}\NormalTok{(disparity\_time\_slices, }\AttributeTok{test =}\NormalTok{ wilcox.test,} + \AttributeTok{comparisons =} \StringTok{"sequential"}\NormalTok{, }\AttributeTok{correction =} \StringTok{"bonferroni"}\NormalTok{)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## [[1]] ## statistic: W -## 120 : 80 42 -## 80 : 40 2065 -## 40 : 0 1485 +## 120 : 80 40 +## 80 : 40 1812 +## 40 : 0 1463 ## ## [[2]] ## p.value -## 120 : 80 2.682431e-33 -## 80 : 40 2.247885e-12 -## 40 : 0 2.671335e-17 +## 120 : 80 2.534081e-33 +## 80 : 40 2.037470e-14 +## 40 : 0 1.671038e-17 \end{verbatim} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Measuring the overlap between distributions in the time bins (using the} -\CommentTok{\#\# implemented Bhattacharyya Coefficient function {-} see ?bhatt.coeff)} -\KeywordTok{test.dispRity}\NormalTok{(disparity\_time\_bins, }\DataTypeTok{test =}\NormalTok{ bhatt.coeff)} +\DocumentationTok{\#\# Measuring the overlap between distributions in the time bins (using the} +\DocumentationTok{\#\# implemented Bhattacharyya Coefficient function {-} see ?bhatt.coeff)} +\FunctionTok{test.dispRity}\NormalTok{(disparity\_time\_bins, }\AttributeTok{test =}\NormalTok{ bhatt.coeff)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## bhatt.coeff -## 120 - 80 : 80 - 40 0.00000000 -## 120 - 80 : 40 - 0 0.02236068 -## 80 - 40 : 40 - 0 0.42018008 +## 120 - 80 : 80 - 40 0.000000 +## 120 - 80 : 40 - 0 0.000000 +## 80 - 40 : 40 - 0 0.450877 \end{verbatim} Because of the modular design of the package, tests can always be made by the user (the same way disparity metrics can be user made). @@ -3719,7 +3523,7 @@ \section{Testing disparity hypotheses}\label{testing-disparity-hypotheses}} \hypertarget{adonis}{% \subsection{\texorpdfstring{NPMANOVA in \texttt{dispRity}}{NPMANOVA in dispRity}}\label{adonis}} -One often useful test to apply to multidimensional data is the permutational multivariate analysis of variance based on distance matrices \texttt{vegan::adonis}. +One often useful test to apply to multidimensional data is the permutational multivariate analysis of variance based on distance matrices \texttt{vegan::adonis2}. This can be done on \texttt{dispRity} objects using the \texttt{adonis.dispRity} wrapper function. Basically, this function takes the exact same arguments as \texttt{adonis} and a \texttt{dispRity} object for data and performs a PERMANOVA based on the distance matrix of the multidimensional space (unless the multidimensional space was already defined as a distance matrix). The \texttt{adonis.dispRity} function uses the information from the \texttt{dispRity} object to generate default formulas: @@ -3727,50 +3531,50 @@ \subsection{\texorpdfstring{NPMANOVA in \texttt{dispRity}}{NPMANOVA in dispRity} \begin{itemize} \tightlist \item - If the object contains customised subsets, it applies the default formula \texttt{matrix\ \textasciitilde{}\ group} testing the effect of \texttt{group} as a predictor on \texttt{matrix} (called from the \texttt{dispRity} object as \texttt{data\$matrix} see \protect\hyperlink{The-dispRity-object-content}{\texttt{dispRitu} object details}) + If the object contains customised subsets, it applies the default formula \texttt{matrix\ \textasciitilde{}\ group} testing the effect of \texttt{group} as a predictor on \texttt{matrix} (called from the \texttt{dispRity} object as \texttt{data\$matrix} see \protect\hyperlink{The-dispRity-object-content}{\texttt{dispRity} object details}) \item If the object contains time subsets, it applies the default formula \texttt{matrix\ \textasciitilde{}\ time} testing the effect of \texttt{time} as a predictor (were the different levels of \texttt{time} are the different time slices/bins) \end{itemize} \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)} -\CommentTok{\#\# Generating a random character matrix} -\NormalTok{character\_matrix \textless{}{-}}\StringTok{ }\KeywordTok{sim.morpho}\NormalTok{(}\KeywordTok{rtree}\NormalTok{(}\DecValTok{20}\NormalTok{), }\DecValTok{50}\NormalTok{,} - \DataTypeTok{rates =} \KeywordTok{c}\NormalTok{(rnorm, }\DecValTok{1}\NormalTok{, }\DecValTok{0}\NormalTok{))} +\FunctionTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)} +\DocumentationTok{\#\# Generating a random character matrix} +\NormalTok{character\_matrix }\OtherTok{\textless{}{-}} \FunctionTok{sim.morpho}\NormalTok{(}\FunctionTok{rtree}\NormalTok{(}\DecValTok{20}\NormalTok{), }\DecValTok{50}\NormalTok{,} + \AttributeTok{rates =} \FunctionTok{c}\NormalTok{(rnorm, }\DecValTok{1}\NormalTok{, }\DecValTok{0}\NormalTok{))} -\CommentTok{\#\# Calculating the distance matrix} -\NormalTok{distance\_matrix \textless{}{-}}\StringTok{ }\KeywordTok{as.matrix}\NormalTok{(}\KeywordTok{dist}\NormalTok{(character\_matrix))} +\DocumentationTok{\#\# Calculating the distance matrix} +\NormalTok{distance\_matrix }\OtherTok{\textless{}{-}} \FunctionTok{as.matrix}\NormalTok{(}\FunctionTok{dist}\NormalTok{(character\_matrix))} -\CommentTok{\#\# Creating two groups} -\NormalTok{random\_groups \textless{}{-}}\StringTok{ }\KeywordTok{list}\NormalTok{(}\StringTok{"group1"}\NormalTok{ =}\StringTok{ }\DecValTok{1}\OperatorTok{:}\DecValTok{10}\NormalTok{, }\StringTok{"group2"}\NormalTok{ =}\StringTok{ }\DecValTok{11}\OperatorTok{:}\DecValTok{20}\NormalTok{)} +\DocumentationTok{\#\# Creating two groups} +\NormalTok{random\_groups }\OtherTok{\textless{}{-}} \FunctionTok{list}\NormalTok{(}\StringTok{"group1"} \OtherTok{=} \DecValTok{1}\SpecialCharTok{:}\DecValTok{10}\NormalTok{, }\StringTok{"group2"} \OtherTok{=} \DecValTok{11}\SpecialCharTok{:}\DecValTok{20}\NormalTok{)} -\CommentTok{\#\# Generating a dispRity object} -\NormalTok{random\_disparity \textless{}{-}}\StringTok{ }\KeywordTok{custom.subsets}\NormalTok{(distance\_matrix, random\_groups)} +\DocumentationTok{\#\# Generating a dispRity object} +\NormalTok{random\_disparity }\OtherTok{\textless{}{-}} \FunctionTok{custom.subsets}\NormalTok{(distance\_matrix, random\_groups)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## Warning: custom.subsets is applied on what seems to be a distance matrix. ## The resulting matrices won't be distance matrices anymore! +## You can use dist.data = TRUE, if you want to keep the data as a distance matrix. \end{verbatim} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Running a default NPMANOVA} -\KeywordTok{adonis.dispRity}\NormalTok{(random\_disparity)} +\DocumentationTok{\#\# Running a default NPMANOVA} +\FunctionTok{adonis.dispRity}\NormalTok{(random\_disparity)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## Permutation test for adonis under reduced model -## Terms added sequentially (first to last) ## Permutation: free ## Number of permutations: 999 ## ## vegan::adonis2(formula = matrix ~ group, method = "euclidean") ## Df SumOfSqs R2 F Pr(>F) -## group 1 14.2 0.06443 1.2396 0.166 +## Model 1 14.2 0.06443 1.2396 0.166 ## Residual 18 206.2 0.93557 ## Total 19 220.4 1.00000 \end{verbatim} @@ -3780,41 +3584,40 @@ \subsection{\texorpdfstring{NPMANOVA in \texttt{dispRity}}{NPMANOVA in dispRity} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Creating two groups with two states each} -\NormalTok{groups \textless{}{-}}\StringTok{ }\KeywordTok{as.data.frame}\NormalTok{(}\KeywordTok{matrix}\NormalTok{(}\DataTypeTok{data =} \KeywordTok{c}\NormalTok{(}\KeywordTok{rep}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{10}\NormalTok{),} - \KeywordTok{rep}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{10}\NormalTok{),} - \KeywordTok{rep}\NormalTok{(}\KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{), }\DecValTok{10}\NormalTok{)),} - \DataTypeTok{nrow =} \DecValTok{20}\NormalTok{, }\DataTypeTok{ncol =} \DecValTok{2}\NormalTok{,} - \DataTypeTok{dimnames =} \KeywordTok{list}\NormalTok{(}\KeywordTok{paste0}\NormalTok{(}\StringTok{"t"}\NormalTok{, }\DecValTok{1}\OperatorTok{:}\DecValTok{20}\NormalTok{),} - \KeywordTok{c}\NormalTok{(}\StringTok{"g1"}\NormalTok{, }\StringTok{"g2"}\NormalTok{))))} +\DocumentationTok{\#\# Creating two groups with two states each} +\NormalTok{groups }\OtherTok{\textless{}{-}} \FunctionTok{as.data.frame}\NormalTok{(}\FunctionTok{matrix}\NormalTok{(}\AttributeTok{data =} \FunctionTok{c}\NormalTok{(}\FunctionTok{rep}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{10}\NormalTok{),} + \FunctionTok{rep}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{10}\NormalTok{),} + \FunctionTok{rep}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{), }\DecValTok{10}\NormalTok{)),} + \AttributeTok{nrow =} \DecValTok{20}\NormalTok{, }\AttributeTok{ncol =} \DecValTok{2}\NormalTok{,} + \AttributeTok{dimnames =} \FunctionTok{list}\NormalTok{(}\FunctionTok{paste0}\NormalTok{(}\StringTok{"t"}\NormalTok{, }\DecValTok{1}\SpecialCharTok{:}\DecValTok{20}\NormalTok{),} + \FunctionTok{c}\NormalTok{(}\StringTok{"g1"}\NormalTok{, }\StringTok{"g2"}\NormalTok{))))} -\CommentTok{\#\# Creating the dispRity object} -\NormalTok{multi\_groups \textless{}{-}}\StringTok{ }\KeywordTok{custom.subsets}\NormalTok{(distance\_matrix, groups)} +\DocumentationTok{\#\# Creating the dispRity object} +\NormalTok{multi\_groups }\OtherTok{\textless{}{-}} \FunctionTok{custom.subsets}\NormalTok{(distance\_matrix, groups)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## Warning: custom.subsets is applied on what seems to be a distance matrix. ## The resulting matrices won't be distance matrices anymore! +## You can use dist.data = TRUE, if you want to keep the data as a distance matrix. \end{verbatim} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Running the NPMANOVA} -\KeywordTok{adonis.dispRity}\NormalTok{(multi\_groups, matrix }\OperatorTok{\textasciitilde{}}\StringTok{ }\NormalTok{g1 }\OperatorTok{+}\StringTok{ }\NormalTok{g2)} +\DocumentationTok{\#\# Running the NPMANOVA} +\FunctionTok{adonis.dispRity}\NormalTok{(multi\_groups, matrix }\SpecialCharTok{\textasciitilde{}}\NormalTok{ g1 }\SpecialCharTok{+}\NormalTok{ g2)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## Permutation test for adonis under reduced model -## Terms added sequentially (first to last) ## Permutation: free ## Number of permutations: 999 ## ## vegan::adonis2(formula = matrix ~ g1 + g2, method = "euclidean") ## Df SumOfSqs R2 F Pr(>F) -## g1 1 11.0 0.04991 0.9359 0.549 -## g2 1 9.6 0.04356 0.8168 0.766 +## Model 2 20.6 0.09347 0.8764 0.746 ## Residual 17 199.8 0.90653 ## Total 19 220.4 1.00000 \end{verbatim} @@ -3824,15 +3627,15 @@ \subsection{\texorpdfstring{NPMANOVA in \texttt{dispRity}}{NPMANOVA in dispRity} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Creating time series} -\NormalTok{time\_subsets \textless{}{-}}\StringTok{ }\KeywordTok{chrono.subsets}\NormalTok{(BeckLee\_mat50, BeckLee\_tree,} - \DataTypeTok{method =} \StringTok{"discrete"}\NormalTok{,} - \DataTypeTok{inc.nodes =} \OtherTok{FALSE}\NormalTok{,} - \DataTypeTok{time =} \KeywordTok{c}\NormalTok{(}\DecValTok{100}\NormalTok{, }\DecValTok{85}\NormalTok{, }\DecValTok{65}\NormalTok{, }\DecValTok{0}\NormalTok{),} - \DataTypeTok{FADLAD =}\NormalTok{ BeckLee\_ages)} +\DocumentationTok{\#\# Creating time series} +\NormalTok{time\_subsets }\OtherTok{\textless{}{-}} \FunctionTok{chrono.subsets}\NormalTok{(BeckLee\_mat50, BeckLee\_tree,} + \AttributeTok{method =} \StringTok{"discrete"}\NormalTok{,} + \AttributeTok{inc.nodes =} \ConstantTok{FALSE}\NormalTok{,} + \AttributeTok{time =} \FunctionTok{c}\NormalTok{(}\DecValTok{100}\NormalTok{, }\DecValTok{85}\NormalTok{, }\DecValTok{65}\NormalTok{, }\DecValTok{0}\NormalTok{),} + \AttributeTok{FADLAD =}\NormalTok{ BeckLee\_ages)} -\CommentTok{\#\# Running the NPMANOVA with time as a predictor} -\KeywordTok{adonis.dispRity}\NormalTok{(time\_subsets)} +\DocumentationTok{\#\# Running the NPMANOVA with time as a predictor} +\FunctionTok{adonis.dispRity}\NormalTok{(time\_subsets)} \end{Highlighting} \end{Shaded} @@ -3844,13 +3647,12 @@ \subsection{\texorpdfstring{NPMANOVA in \texttt{dispRity}}{NPMANOVA in dispRity} \begin{verbatim} ## Permutation test for adonis under reduced model -## Terms added sequentially (first to last) ## Permutation: free ## Number of permutations: 999 ## ## vegan::adonis2(formula = dist(matrix) ~ time, method = "euclidean") ## Df SumOfSqs R2 F Pr(>F) -## time 2 9.593 0.07769 1.9796 0.001 *** +## Model 2 9.593 0.07769 1.9796 0.001 *** ## Residual 47 113.884 0.92231 ## Total 49 123.477 1.00000 ## --- @@ -3864,8 +3666,8 @@ \subsection{\texorpdfstring{NPMANOVA in \texttt{dispRity}}{NPMANOVA in dispRity} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Running the NPMANOVA with each time bin as a predictor} -\KeywordTok{adonis.dispRity}\NormalTok{(time\_subsets, matrix }\OperatorTok{\textasciitilde{}}\StringTok{ }\NormalTok{chrono.subsets)} +\DocumentationTok{\#\# Running the NPMANOVA with each time bin as a predictor} +\FunctionTok{adonis.dispRity}\NormalTok{(time\_subsets, matrix }\SpecialCharTok{\textasciitilde{}}\NormalTok{ chrono.subsets)} \end{Highlighting} \end{Shaded} @@ -3877,14 +3679,12 @@ \subsection{\texorpdfstring{NPMANOVA in \texttt{dispRity}}{NPMANOVA in dispRity} \begin{verbatim} ## Permutation test for adonis under reduced model -## Terms added sequentially (first to last) ## Permutation: free ## Number of permutations: 999 ## ## vegan::adonis2(formula = dist(matrix) ~ chrono.subsets, method = "euclidean") ## Df SumOfSqs R2 F Pr(>F) -## t100to85 1 3.714 0.03008 1.5329 0.006 ** -## t85to65 1 5.879 0.04761 2.4262 0.001 *** +## Model 2 9.593 0.07769 1.9796 0.001 *** ## Residual 47 113.884 0.92231 ## Total 49 123.477 1.00000 ## --- @@ -3900,7 +3700,7 @@ \subsection{\texorpdfstring{\texttt{geiger::dtt} model fitting in \texttt{dispRi \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{require}\NormalTok{(geiger)} +\FunctionTok{require}\NormalTok{(geiger)} \end{Highlighting} \end{Shaded} @@ -3910,13 +3710,13 @@ \subsection{\texorpdfstring{\texttt{geiger::dtt} model fitting in \texttt{dispRi \begin{Shaded} \begin{Highlighting}[] -\NormalTok{geiger\_data \textless{}{-}}\StringTok{ }\KeywordTok{get}\NormalTok{(}\KeywordTok{data}\NormalTok{(geospiza))} +\NormalTok{geiger\_data }\OtherTok{\textless{}{-}} \FunctionTok{get}\NormalTok{(}\FunctionTok{data}\NormalTok{(geospiza))} -\CommentTok{\#\# Calculate the disparity of the dataset using the sum of variance} -\NormalTok{dispRity\_dtt \textless{}{-}}\StringTok{ }\KeywordTok{dtt.dispRity}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ geiger\_data}\OperatorTok{$}\NormalTok{dat,} - \DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, variances),} - \DataTypeTok{tree =}\NormalTok{ geiger\_data}\OperatorTok{$}\NormalTok{phy,} - \DataTypeTok{nsim =} \DecValTok{100}\NormalTok{)} +\DocumentationTok{\#\# Calculate the disparity of the dataset using the sum of variance} +\NormalTok{dispRity\_dtt }\OtherTok{\textless{}{-}} \FunctionTok{dtt.dispRity}\NormalTok{(}\AttributeTok{data =}\NormalTok{ geiger\_data}\SpecialCharTok{$}\NormalTok{dat,} + \AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, variances),} + \AttributeTok{tree =}\NormalTok{ geiger\_data}\SpecialCharTok{$}\NormalTok{phy,} + \AttributeTok{nsim =} \DecValTok{100}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -3927,12 +3727,12 @@ \subsection{\texorpdfstring{\texttt{geiger::dtt} model fitting in \texttt{dispRi \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Plotting the results} -\KeywordTok{plot}\NormalTok{(dispRity\_dtt)} +\DocumentationTok{\#\# Plotting the results} +\FunctionTok{plot}\NormalTok{(dispRity\_dtt)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-96-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-97-1.pdf} Note that, like in the original \texttt{dtt} function, it is possible to change the evolutionary model (see \texttt{?geiger::sim.char} documentation). @@ -3945,13 +3745,13 @@ \subsection{\texorpdfstring{null morphospace testing with \texttt{null.test}}{nu \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{set.seed}\NormalTok{(}\DecValTok{123}\NormalTok{)} -\CommentTok{\#\# A "normal" multidimensional space with 50 dimensions and 10 elements} -\NormalTok{normal\_space \textless{}{-}}\StringTok{ }\KeywordTok{matrix}\NormalTok{(}\KeywordTok{rnorm}\NormalTok{(}\DecValTok{1000}\NormalTok{), }\DataTypeTok{ncol =} \DecValTok{50}\NormalTok{)} +\FunctionTok{set.seed}\NormalTok{(}\DecValTok{123}\NormalTok{)} +\DocumentationTok{\#\# A "normal" multidimensional space with 50 dimensions and 10 elements} +\NormalTok{normal\_space }\OtherTok{\textless{}{-}} \FunctionTok{matrix}\NormalTok{(}\FunctionTok{rnorm}\NormalTok{(}\DecValTok{1000}\NormalTok{), }\AttributeTok{ncol =} \DecValTok{50}\NormalTok{)} -\CommentTok{\#\# Calculating the disparity as the average pairwise distances} -\NormalTok{obs\_disparity \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(normal\_space,} - \DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(mean, pairwise.dist))} +\DocumentationTok{\#\# Calculating the disparity as the average pairwise distances} +\NormalTok{obs\_disparity }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(normal\_space,} + \AttributeTok{metric =} \FunctionTok{c}\NormalTok{(mean, pairwise.dist))} \end{Highlighting} \end{Shaded} @@ -3962,9 +3762,9 @@ \subsection{\texorpdfstring{null morphospace testing with \texttt{null.test}}{nu \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Testing against 100 randomly generated normal spaces} -\NormalTok{(results \textless{}{-}}\StringTok{ }\KeywordTok{null.test}\NormalTok{(obs\_disparity, }\DataTypeTok{replicates =} \DecValTok{100}\NormalTok{,} - \DataTypeTok{null.distrib =}\NormalTok{ rnorm))} +\DocumentationTok{\#\# Testing against 100 randomly generated normal spaces} +\NormalTok{(results }\OtherTok{\textless{}{-}} \FunctionTok{null.test}\NormalTok{(obs\_disparity, }\AttributeTok{replicates =} \DecValTok{100}\NormalTok{,} + \AttributeTok{null.distrib =}\NormalTok{ rnorm))} \end{Highlighting} \end{Shaded} @@ -3989,12 +3789,12 @@ \subsection{\texorpdfstring{null morphospace testing with \texttt{null.test}}{nu \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Plotting the results} -\KeywordTok{plot}\NormalTok{(results, }\DataTypeTok{main =} \StringTok{"Is this space normal?"}\NormalTok{)} +\DocumentationTok{\#\# Plotting the results} +\FunctionTok{plot}\NormalTok{(results, }\AttributeTok{main =} \StringTok{"Is this space normal?"}\NormalTok{)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-98-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-99-1.pdf} For more details on generating spaces see the \protect\hyperlink{Simulating-multidimensional-spaces}{\texttt{space.maker}} function tutorial. @@ -4022,16 +3822,16 @@ \subsubsection{\texorpdfstring{\texttt{model.test}}{model.test}}\label{model.tes \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Loading premade disparity data} -\KeywordTok{data}\NormalTok{(BeckLee\_disparity)} -\NormalTok{disp\_time \textless{}{-}}\StringTok{ }\KeywordTok{model.test}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_disparity, }\DataTypeTok{model =} \StringTok{"Stasis"}\NormalTok{)} +\DocumentationTok{\#\# Loading premade disparity data} +\FunctionTok{data}\NormalTok{(BeckLee\_disparity)} +\NormalTok{disp\_time }\OtherTok{\textless{}{-}} \FunctionTok{model.test}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_disparity, }\AttributeTok{model =} \StringTok{"Stasis"}\NormalTok{)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## Evidence of equal variance (Bartlett's test of equal variances p = 0). ## Variance is not pooled. -## Running Stasis model...Done. Log-likelihood = -18.694 +## Running Stasis model...Done. Log-likelihood = -15.562 \end{verbatim} We can see the standard output from \texttt{model.test}. @@ -4045,30 +3845,30 @@ \subsubsection{\texorpdfstring{\texttt{model.test}}{model.test}}\label{model.tes \begin{Shaded} \begin{Highlighting}[] -\NormalTok{disp\_time\_pooled \textless{}{-}}\StringTok{ }\KeywordTok{model.test}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_disparity,} - \DataTypeTok{model =} \StringTok{"Stasis"}\NormalTok{,} - \DataTypeTok{pool.variance =} \OtherTok{TRUE}\NormalTok{)} +\NormalTok{disp\_time\_pooled }\OtherTok{\textless{}{-}} \FunctionTok{model.test}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_disparity,} + \AttributeTok{model =} \StringTok{"Stasis"}\NormalTok{,} + \AttributeTok{pool.variance =} \ConstantTok{TRUE}\NormalTok{)} \end{Highlighting} \end{Shaded} \begin{verbatim} -## Running Stasis model...Done. Log-likelihood = -16.884 +## Running Stasis model...Done. Log-likelihood = -13.682 \end{verbatim} However, unless you have good reason to choose otherwise it is recommended to use the default of \texttt{pool.variance\ =\ NULL}: \begin{Shaded} \begin{Highlighting}[] -\NormalTok{disp\_time \textless{}{-}}\StringTok{ }\KeywordTok{model.test}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_disparity,} - \DataTypeTok{model =} \StringTok{"Stasis"}\NormalTok{,} - \DataTypeTok{pool.variance =} \OtherTok{NULL}\NormalTok{)} +\NormalTok{disp\_time }\OtherTok{\textless{}{-}} \FunctionTok{model.test}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_disparity,} + \AttributeTok{model =} \StringTok{"Stasis"}\NormalTok{,} + \AttributeTok{pool.variance =} \ConstantTok{NULL}\NormalTok{)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## Evidence of equal variance (Bartlett's test of equal variances p = 0). ## Variance is not pooled. -## Running Stasis model...Done. Log-likelihood = -18.694 +## Running Stasis model...Done. Log-likelihood = -15.562 \end{verbatim} \begin{Shaded} @@ -4082,13 +3882,13 @@ \subsubsection{\texorpdfstring{\texttt{model.test}}{model.test}}\label{model.tes ## Call: model.test(data = BeckLee_disparity, model = "Stasis", pool.variance = NULL) ## ## aicc delta_aicc weight_aicc -## Stasis 41.48967 0 1 +## Stasis 35.22653 0 1 ## ## Use x$full.details for displaying the models details ## or summary(x) for summarising them. \end{verbatim} -The remaining output gives us the log-likelihood of the Stasis model of -18.7 (you may notice this change when we pooled variances above). +The remaining output gives us the log-likelihood of the Stasis model of -15.6 (you may notice this change when we pooled variances above). The output also gives us the small sample Akaike Information Criterion (AICc), the delta AICc (the distance from the best fitting model), and the AICc weights (\textasciitilde the relative support of this model compared to all models, scaled to one). These are all metrics of relative fit, so when we test a single model they are not useful. @@ -4096,17 +3896,17 @@ \subsubsection{\texorpdfstring{\texttt{model.test}}{model.test}}\label{model.tes \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{summary}\NormalTok{(disp\_time)} +\FunctionTok{summary}\NormalTok{(disp\_time)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## aicc delta_aicc weight_aicc log.lik param theta.1 omega -## Stasis 41.5 0 1 -18.7 2 3.6 0.1 +## Stasis 35.2 0 1 -15.6 2 3.5 0.1 \end{verbatim} So we again see the AICc, delta AICc, AICc weight, and the log-likelihood we saw previously. -We now also see the number of parameters from the model (2: theta and omega), and their estimates so the variance (omega = 0.1) and the mean (theta.1 = 3.6). +We now also see the number of parameters from the model (2: theta and omega), and their estimates so the variance (omega = 0.1) and the mean (theta.1 = 3.5). The \texttt{model.test} function is designed to test relative model fit, so we need to test more than one model to make relative comparisons. So let's compare to the fit of the Stasis model to another model with two parameters: the Brownian motion. @@ -4115,16 +3915,16 @@ \subsubsection{\texorpdfstring{\texttt{model.test}}{model.test}}\label{model.tes \begin{Shaded} \begin{Highlighting}[] -\NormalTok{disp\_time \textless{}{-}}\StringTok{ }\KeywordTok{model.test}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_disparity,} - \DataTypeTok{model =} \KeywordTok{c}\NormalTok{(}\StringTok{"Stasis"}\NormalTok{, }\StringTok{"BM"}\NormalTok{))} +\NormalTok{disp\_time }\OtherTok{\textless{}{-}} \FunctionTok{model.test}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_disparity,} + \AttributeTok{model =} \FunctionTok{c}\NormalTok{(}\StringTok{"Stasis"}\NormalTok{, }\StringTok{"BM"}\NormalTok{))} \end{Highlighting} \end{Shaded} \begin{verbatim} ## Evidence of equal variance (Bartlett's test of equal variances p = 0). ## Variance is not pooled. -## Running Stasis model...Done. Log-likelihood = -18.694 -## Running BM model...Done. Log-likelihood = 149.289 +## Running Stasis model...Done. Log-likelihood = -15.562 +## Running BM model...Done. Log-likelihood = 151.637 \end{verbatim} \begin{Shaded} @@ -4138,28 +3938,28 @@ \subsubsection{\texorpdfstring{\texttt{model.test}}{model.test}}\label{model.tes ## Call: model.test(data = BeckLee_disparity, model = c("Stasis", "BM")) ## ## aicc delta_aicc weight_aicc -## Stasis 41.48967 335.9656 1.111708e-73 -## BM -294.47595 0.0000 1.000000e+00 +## Stasis 35.22653 334.3978 2.434618e-73 +## BM -299.17132 0.0000 1.000000e+00 ## ## Use x$full.details for displaying the models details ## or summary(x) for summarising them. \end{verbatim} Et voilà! Here we can see by the log-likelihood, AICc, delta AICc, and AICc weight Brownian motion has a much better relative fit to these data than the Stasis model. -Brownian motion has a relative AICc fit336 units better than Stasis, and has a AICc weight of 1. +Brownian motion has a relative AICc fit334.4 units better than Stasis, and has a AICc weight of 1. We can also all the information about the relative fit of models alongside the maximum likelihood estimates of model parameters using the summary function \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{summary}\NormalTok{(disp\_time)} +\FunctionTok{summary}\NormalTok{(disp\_time)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## aicc delta_aicc weight_aicc log.lik param theta.1 omega ancestral state -## Stasis 41 336 0 -18.7 2 3.629 0.074 NA -## BM -294 0 1 149.3 2 NA NA 3.267 +## Stasis 35 334.4 0 -15.6 2 3.486 0.07 NA +## BM -299 0.0 1 151.6 2 NA NA 3.132 ## sigma squared ## Stasis NA ## BM 0.001 @@ -4171,7 +3971,7 @@ \subsubsection{\texorpdfstring{\texttt{model.test}}{model.test}}\label{model.tes \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{plot}\NormalTok{(disp\_time)} +\FunctionTok{plot}\NormalTok{(disp\_time)} \end{Highlighting} \end{Shaded} @@ -4190,47 +3990,47 @@ \subsubsection{\texorpdfstring{\texttt{model.test}}{model.test}}\label{model.tes \begin{Shaded} \begin{Highlighting}[] -\NormalTok{disp\_time \textless{}{-}}\StringTok{ }\KeywordTok{model.test}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_disparity,} - \DataTypeTok{model =} \KeywordTok{c}\NormalTok{(}\StringTok{"Stasis"}\NormalTok{, }\StringTok{"BM"}\NormalTok{, }\StringTok{"OU"}\NormalTok{, }\StringTok{"Trend"}\NormalTok{, }\StringTok{"EB"}\NormalTok{))} +\NormalTok{disp\_time }\OtherTok{\textless{}{-}} \FunctionTok{model.test}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_disparity,} + \AttributeTok{model =} \FunctionTok{c}\NormalTok{(}\StringTok{"Stasis"}\NormalTok{, }\StringTok{"BM"}\NormalTok{, }\StringTok{"OU"}\NormalTok{, }\StringTok{"Trend"}\NormalTok{, }\StringTok{"EB"}\NormalTok{))} \end{Highlighting} \end{Shaded} \begin{verbatim} ## Evidence of equal variance (Bartlett's test of equal variances p = 0). ## Variance is not pooled. -## Running Stasis model...Done. Log-likelihood = -18.694 -## Running BM model...Done. Log-likelihood = 149.289 -## Running OU model...Done. Log-likelihood = 152.119 -## Running Trend model...Done. Log-likelihood = 152.116 -## Running EB model...Done. Log-likelihood = 126.268 +## Running Stasis model...Done. Log-likelihood = -15.562 +## Running BM model...Done. Log-likelihood = 151.637 +## Running OU model...Done. Log-likelihood = 154.512 +## Running Trend model...Done. Log-likelihood = 154.508 +## Running EB model...Done. Log-likelihood = 128.008 \end{verbatim} \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{summary}\NormalTok{(disp\_time)} +\FunctionTok{summary}\NormalTok{(disp\_time)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## aicc delta_aicc weight_aicc log.lik param theta.1 omega ancestral state -## Stasis 41 339.5 0.000 -18.7 2 3.629 0.074 NA -## BM -294 3.6 0.112 149.3 2 NA NA 3.267 -## OU -296 2.1 0.227 152.1 4 NA NA 3.254 -## Trend -298 0.0 0.661 152.1 3 NA NA 3.255 -## EB -246 51.7 0.000 126.3 3 NA NA 4.092 +## Stasis 35 338.0 0.000 -15.6 2 3.486 0.07 NA +## BM -299 3.6 0.108 151.6 2 NA NA 3.132 +## OU -301 2.1 0.229 154.5 4 NA NA 3.118 +## Trend -303 0.0 0.664 154.5 3 NA NA 3.119 +## EB -250 53.0 0.000 128.0 3 NA NA 3.934 ## sigma squared alpha optima.1 trend eb ## Stasis NA NA NA NA NA ## BM 0.001 NA NA NA NA -## OU 0.001 0.001 12.35 NA NA +## OU 0.001 0.001 10.18 NA NA ## Trend 0.001 NA NA 0.007 NA -## EB 0.000 NA NA NA -0.032 +## EB 0.000 NA NA NA -0.034 \end{verbatim} These models indicate support for a Trend model, and we can plot the relative support of all model AICc weights. \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{plot}\NormalTok{(disp\_time)} +\FunctionTok{plot}\NormalTok{(disp\_time)} \end{Highlighting} \end{Shaded} @@ -4252,15 +4052,15 @@ \subsubsection{\texorpdfstring{\texttt{model.test}}{model.test}}\label{model.tes \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{summary}\NormalTok{(disp\_time)[}\StringTok{"Trend"}\NormalTok{,]} +\FunctionTok{summary}\NormalTok{(disp\_time)[}\StringTok{"Trend"}\NormalTok{,]} \end{Highlighting} \end{Shaded} \begin{verbatim} ## aicc delta_aicc weight_aicc log.lik param -## -298.000 0.000 0.661 152.100 3.000 +## -303.000 0.000 0.664 154.500 3.000 ## theta.1 omega ancestral state sigma squared alpha -## NA NA 3.255 0.001 NA +## NA NA 3.119 0.001 NA ## optima.1 trend eb ## NA 0.007 NA \end{verbatim} @@ -4281,20 +4081,20 @@ \subsubsection{\texorpdfstring{\texttt{model.test.wrapper}}{model.test.wrapper}} \begin{Shaded} \begin{Highlighting}[] -\NormalTok{disp\_time \textless{}{-}}\StringTok{ }\KeywordTok{model.test.wrapper}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_disparity,} - \DataTypeTok{model =} \KeywordTok{c}\NormalTok{(}\StringTok{"Stasis"}\NormalTok{, }\StringTok{"BM"}\NormalTok{, }\StringTok{"OU"}\NormalTok{, }\StringTok{"Trend"}\NormalTok{, }\StringTok{"EB"}\NormalTok{),} - \DataTypeTok{show.p =} \OtherTok{TRUE}\NormalTok{)} +\NormalTok{disp\_time }\OtherTok{\textless{}{-}} \FunctionTok{model.test.wrapper}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_disparity,} + \AttributeTok{model =} \FunctionTok{c}\NormalTok{(}\StringTok{"Stasis"}\NormalTok{, }\StringTok{"BM"}\NormalTok{, }\StringTok{"OU"}\NormalTok{, }\StringTok{"Trend"}\NormalTok{, }\StringTok{"EB"}\NormalTok{),} + \AttributeTok{show.p =} \ConstantTok{TRUE}\NormalTok{)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## Evidence of equal variance (Bartlett's test of equal variances p = 0). ## Variance is not pooled. -## Running Stasis model...Done. Log-likelihood = -18.694 -## Running BM model...Done. Log-likelihood = 149.289 -## Running OU model...Done. Log-likelihood = 152.119 -## Running Trend model...Done. Log-likelihood = 152.116 -## Running EB model...Done. Log-likelihood = 126.268 +## Running Stasis model...Done. Log-likelihood = -15.562 +## Running BM model...Done. Log-likelihood = 151.637 +## Running OU model...Done. Log-likelihood = 154.512 +## Running Trend model...Done. Log-likelihood = 154.508 +## Running EB model...Done. Log-likelihood = 128.008 \end{verbatim} \begin{figure} @@ -4314,22 +4114,22 @@ \subsubsection{\texorpdfstring{\texttt{model.test.wrapper}}{model.test.wrapper}} \begin{verbatim} ## aicc delta_aicc weight_aicc log.lik param theta.1 omega ancestral state -## Trend -298 0.0 0.661 152.1 3 NA NA 3.255 -## OU -296 2.1 0.227 152.1 4 NA NA 3.254 -## BM -294 3.6 0.112 149.3 2 NA NA 3.267 -## EB -246 51.7 0.000 126.3 3 NA NA 4.092 -## Stasis 41 339.5 0.000 -18.7 2 3.629 0.074 NA +## Trend -303 0.0 0.664 154.5 3 NA NA 3.119 +## OU -301 2.1 0.229 154.5 4 NA NA 3.118 +## BM -299 3.6 0.108 151.6 2 NA NA 3.132 +## EB -250 53.0 0.000 128.0 3 NA NA 3.934 +## Stasis 35 338.0 0.000 -15.6 2 3.486 0.07 NA ## sigma squared alpha optima.1 trend eb median p value lower p value -## Trend 0.001 NA NA 0.007 NA 0.978021978 0.9760240 -## OU 0.001 0.001 12.35 NA NA 0.978021978 0.9770230 -## BM 0.001 NA NA NA NA 0.143856144 0.1368631 -## EB 0.000 NA NA NA -0.032 0.000999001 0.0000000 +## Trend 0.001 NA NA 0.007 NA 0.986013986 0.9850150 +## OU 0.001 0.001 10.18 NA NA 0.979020979 0.9770230 +## BM 0.001 NA NA NA NA 0.107892108 0.0969031 +## EB 0.000 NA NA NA -0.034 0.000999001 0.0000000 ## Stasis NA NA NA NA NA 1.000000000 0.9990010 ## upper p value -## Trend 0.9780220 -## OU 0.9780220 -## BM 0.1878122 -## EB 0.1368631 +## Trend 0.9860140 +## OU 0.9800200 +## BM 0.1388611 +## EB 0.1378621 ## Stasis 1.0000000 \end{verbatim} @@ -4337,26 +4137,26 @@ \subsubsection{\texorpdfstring{\texttt{model.test.wrapper}}{model.test.wrapper}} There is no significant differences between the empirical data and simulated data, except for the Early Burst model. Trend is the best-fitting model but the plot suggests the OU model also follows a trend-like pattern. -This is because the optima for the OU model (12.35) is different to the ancestral state (3.254) and outside the observed value. +This is because the optima for the OU model (10.18) is different to the ancestral state (3.118) and outside the observed value. This is potentially unrealistic, and one way to alleviate this issue is to set the optima of the OU model to equal the ancestral estimate - this is the normal practice for OU models in comparative phylogenetics. To set the optima to the ancestral value we change the argument \texttt{fixed.optima\ =\ TRUE}: \begin{Shaded} \begin{Highlighting}[] -\NormalTok{disp\_time \textless{}{-}}\StringTok{ }\KeywordTok{model.test.wrapper}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_disparity,} - \DataTypeTok{model =} \KeywordTok{c}\NormalTok{(}\StringTok{"Stasis"}\NormalTok{, }\StringTok{"BM"}\NormalTok{, }\StringTok{"OU"}\NormalTok{, }\StringTok{"Trend"}\NormalTok{, }\StringTok{"EB"}\NormalTok{),} - \DataTypeTok{show.p =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{fixed.optima =} \OtherTok{TRUE}\NormalTok{)} +\NormalTok{disp\_time }\OtherTok{\textless{}{-}} \FunctionTok{model.test.wrapper}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_disparity,} + \AttributeTok{model =} \FunctionTok{c}\NormalTok{(}\StringTok{"Stasis"}\NormalTok{, }\StringTok{"BM"}\NormalTok{, }\StringTok{"OU"}\NormalTok{, }\StringTok{"Trend"}\NormalTok{, }\StringTok{"EB"}\NormalTok{),} + \AttributeTok{show.p =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{fixed.optima =} \ConstantTok{TRUE}\NormalTok{)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## Evidence of equal variance (Bartlett's test of equal variances p = 0). ## Variance is not pooled. -## Running Stasis model...Done. Log-likelihood = -18.694 -## Running BM model...Done. Log-likelihood = 149.289 -## Running OU model...Done. Log-likelihood = 149.289 -## Running Trend model...Done. Log-likelihood = 152.116 -## Running EB model...Done. Log-likelihood = 126.268 +## Running Stasis model...Done. Log-likelihood = -15.562 +## Running BM model...Done. Log-likelihood = 151.637 +## Running OU model...Done. Log-likelihood = 151.637 +## Running Trend model...Done. Log-likelihood = 154.508 +## Running EB model...Done. Log-likelihood = 128.008 \end{verbatim} \begin{figure} @@ -4376,21 +4176,21 @@ \subsubsection{\texorpdfstring{\texttt{model.test.wrapper}}{model.test.wrapper}} \begin{verbatim} ## aicc delta_aicc weight_aicc log.lik param theta.1 omega ancestral state -## Trend -298 0.0 0.814 152.1 3 NA NA 3.255 -## BM -294 3.6 0.138 149.3 2 NA NA 3.267 -## OU -292 5.7 0.048 149.3 3 NA NA 3.267 -## EB -246 51.7 0.000 126.3 3 NA NA 4.092 -## Stasis 41 339.5 0.000 -18.7 2 3.629 0.074 NA +## Trend -303 0.0 0.821 154.5 3 NA NA 3.119 +## BM -299 3.6 0.133 151.6 2 NA NA 3.132 +## OU -297 5.7 0.046 151.6 3 NA NA 3.132 +## EB -250 53.0 0.000 128.0 3 NA NA 3.934 +## Stasis 35 338.0 0.000 -15.6 2 3.486 0.07 NA ## sigma squared alpha trend eb median p value lower p value -## Trend 0.001 NA 0.007 NA 0.984015984 0.9820180 -## BM 0.001 NA NA NA 0.256743257 0.2487512 -## OU 0.001 0 NA NA 0.293706294 0.2917083 -## EB 0.000 NA NA -0.032 0.000999001 0.0000000 +## Trend 0.001 NA 0.007 NA 0.989010989 0.9880120 +## BM 0.001 NA NA NA 0.224775225 0.2117882 +## OU 0.001 0 NA NA 0.264735265 0.2637363 +## EB 0.000 NA NA -0.034 0.000999001 0.0000000 ## Stasis NA NA NA NA 0.999000999 0.9980020 ## upper p value -## Trend 0.9840160 -## BM 0.2797203 -## OU 0.3166833 +## Trend 0.9890110 +## BM 0.2507493 +## OU 0.2967033 ## EB 0.1378621 ## Stasis 0.9990010 \end{verbatim} @@ -4413,22 +4213,22 @@ \subsection{Multiple modes of evolution (time shifts)}\label{multiple-modes-of-e \begin{Shaded} \begin{Highlighting}[] -\NormalTok{disp\_time \textless{}{-}}\StringTok{ }\KeywordTok{model.test.wrapper}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_disparity,} - \DataTypeTok{model =} \KeywordTok{c}\NormalTok{(}\StringTok{"BM"}\NormalTok{, }\StringTok{"Trend"}\NormalTok{, }\StringTok{"OU"}\NormalTok{, }\StringTok{"multi.OU"}\NormalTok{),} - \DataTypeTok{time.split =} \DecValTok{66}\NormalTok{,} - \DataTypeTok{pool.variance =} \OtherTok{NULL}\NormalTok{,} - \DataTypeTok{show.p =} \OtherTok{TRUE}\NormalTok{,} - \DataTypeTok{fixed.optima =} \OtherTok{TRUE}\NormalTok{)} +\NormalTok{disp\_time }\OtherTok{\textless{}{-}} \FunctionTok{model.test.wrapper}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_disparity,} + \AttributeTok{model =} \FunctionTok{c}\NormalTok{(}\StringTok{"BM"}\NormalTok{, }\StringTok{"Trend"}\NormalTok{, }\StringTok{"OU"}\NormalTok{, }\StringTok{"multi.OU"}\NormalTok{),} + \AttributeTok{time.split =} \DecValTok{66}\NormalTok{,} + \AttributeTok{pool.variance =} \ConstantTok{NULL}\NormalTok{,} + \AttributeTok{show.p =} \ConstantTok{TRUE}\NormalTok{,} + \AttributeTok{fixed.optima =} \ConstantTok{TRUE}\NormalTok{)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## Evidence of equal variance (Bartlett's test of equal variances p = 0). ## Variance is not pooled. -## Running BM model...Done. Log-likelihood = 149.289 -## Running Trend model...Done. Log-likelihood = 152.116 -## Running OU model...Done. Log-likelihood = 149.289 -## Running multi.OU model...Done. Log-likelihood = 151.958 +## Running BM model...Done. Log-likelihood = 151.637 +## Running Trend model...Done. Log-likelihood = 154.508 +## Running OU model...Done. Log-likelihood = 151.637 +## Running multi.OU model...Done. Log-likelihood = 154.492 \end{verbatim} \begin{figure} @@ -4448,20 +4248,20 @@ \subsection{Multiple modes of evolution (time shifts)}\label{multiple-modes-of-e \begin{verbatim} ## aicc delta_aicc weight_aicc log.lik param ancestral state -## Trend -298 0.000 0.657 152.1 3 3.255 -## multi.OU -296 2.456 0.193 152.0 4 3.253 -## BM -294 3.550 0.111 149.3 2 3.267 -## OU -292 5.654 0.039 149.3 3 3.267 +## Trend -303 0.000 0.642 154.5 3 3.119 +## multi.OU -301 2.170 0.217 154.5 4 3.117 +## BM -299 3.639 0.104 151.6 2 3.132 +## OU -297 5.742 0.036 151.6 3 3.132 ## sigma squared trend alpha optima.2 median p value lower p value ## Trend 0.001 0.007 NA NA 0.9870130 0.9860140 -## multi.OU 0.001 NA 0.006 4.686 0.9570430 0.9560440 -## BM 0.001 NA NA NA 0.1868132 0.1808192 -## OU 0.001 NA 0.000 NA 0.2727273 0.2707293 +## multi.OU 0.001 NA 0.003 5.582 0.9620380 0.9610390 +## BM 0.001 NA NA NA 0.1848152 0.1838162 +## OU 0.001 NA 0.000 NA 0.2787213 0.2757243 ## upper p value ## Trend 0.9870130 -## multi.OU 0.9590410 -## BM 0.2207792 -## OU 0.3016983 +## multi.OU 0.9620380 +## BM 0.2217782 +## OU 0.3046953 \end{verbatim} The multi-OU model shows an increase an optima at the Cretaceous-Palaeogene boundary, indicating a shift in disparity. @@ -4472,11 +4272,11 @@ \subsection{Multiple modes of evolution (time shifts)}\label{multiple-modes-of-e \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# An example of a time split model in which all potential splits are tested} -\CommentTok{\#\# }\AlertTok{WARNING}\CommentTok{: this will take between 20 minutes and half and hour to run!} -\NormalTok{disp\_time \textless{}{-}}\StringTok{ }\KeywordTok{model.test.wrapper}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_disparity,} - \DataTypeTok{model =} \KeywordTok{c}\NormalTok{(}\StringTok{"BM"}\NormalTok{, }\StringTok{"Trend"}\NormalTok{, }\StringTok{"OU"}\NormalTok{, }\StringTok{"multi.OU"}\NormalTok{),} - \DataTypeTok{show.p =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{fixed.optima =} \OtherTok{TRUE}\NormalTok{)} +\DocumentationTok{\#\# An example of a time split model in which all potential splits are tested} +\DocumentationTok{\#\# }\AlertTok{WARNING}\DocumentationTok{: this will take between 20 minutes and half and hour to run!} +\NormalTok{disp\_time }\OtherTok{\textless{}{-}} \FunctionTok{model.test.wrapper}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_disparity,} + \AttributeTok{model =} \FunctionTok{c}\NormalTok{(}\StringTok{"BM"}\NormalTok{, }\StringTok{"Trend"}\NormalTok{, }\StringTok{"OU"}\NormalTok{, }\StringTok{"multi.OU"}\NormalTok{),} + \AttributeTok{show.p =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{fixed.optima =} \ConstantTok{TRUE}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -4489,28 +4289,28 @@ \subsection{Multiple modes of evolution (time shifts)}\label{multiple-modes-of-e \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The models to test} -\NormalTok{my\_models \textless{}{-}}\StringTok{ }\KeywordTok{list}\NormalTok{(}\KeywordTok{c}\NormalTok{(}\StringTok{"BM"}\NormalTok{, }\StringTok{"OU"}\NormalTok{),} - \KeywordTok{c}\NormalTok{(}\StringTok{"Stasis"}\NormalTok{, }\StringTok{"OU"}\NormalTok{),} - \KeywordTok{c}\NormalTok{(}\StringTok{"BM"}\NormalTok{, }\StringTok{"Stasis"}\NormalTok{),} - \KeywordTok{c}\NormalTok{(}\StringTok{"OU"}\NormalTok{, }\StringTok{"Trend"}\NormalTok{),} - \KeywordTok{c}\NormalTok{(}\StringTok{"Stasis"}\NormalTok{, }\StringTok{"BM"}\NormalTok{))} +\DocumentationTok{\#\# The models to test} +\NormalTok{my\_models }\OtherTok{\textless{}{-}} \FunctionTok{list}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\StringTok{"BM"}\NormalTok{, }\StringTok{"OU"}\NormalTok{),} + \FunctionTok{c}\NormalTok{(}\StringTok{"Stasis"}\NormalTok{, }\StringTok{"OU"}\NormalTok{),} + \FunctionTok{c}\NormalTok{(}\StringTok{"BM"}\NormalTok{, }\StringTok{"Stasis"}\NormalTok{),} + \FunctionTok{c}\NormalTok{(}\StringTok{"OU"}\NormalTok{, }\StringTok{"Trend"}\NormalTok{),} + \FunctionTok{c}\NormalTok{(}\StringTok{"Stasis"}\NormalTok{, }\StringTok{"BM"}\NormalTok{))} -\CommentTok{\#\# Testing the models} -\NormalTok{disp\_time \textless{}{-}}\StringTok{ }\KeywordTok{model.test.wrapper}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_disparity,} - \DataTypeTok{model =}\NormalTok{ my\_models, }\DataTypeTok{time.split =} \DecValTok{66}\NormalTok{,} - \DataTypeTok{show.p =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{fixed.optima =} \OtherTok{TRUE}\NormalTok{)} +\DocumentationTok{\#\# Testing the models} +\NormalTok{disp\_time }\OtherTok{\textless{}{-}} \FunctionTok{model.test.wrapper}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_disparity,} + \AttributeTok{model =}\NormalTok{ my\_models, }\AttributeTok{time.split =} \DecValTok{66}\NormalTok{,} + \AttributeTok{show.p =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{fixed.optima =} \ConstantTok{TRUE}\NormalTok{)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## Evidence of equal variance (Bartlett's test of equal variances p = 0). ## Variance is not pooled. -## Running BM:OU model...Done. Log-likelihood = 144.102 -## Running Stasis:OU model...Done. Log-likelihood = 125.066 -## Running BM:Stasis model...Done. Log-likelihood = 69.265 -## Running OU:Trend model...Done. Log-likelihood = 147.839 -## Running Stasis:BM model...Done. Log-likelihood = 125.066 +## Running BM:OU model...Done. Log-likelihood = 146.472 +## Running Stasis:OU model...Done. Log-likelihood = 127.707 +## Running BM:Stasis model...Done. Log-likelihood = 72.456 +## Running OU:Trend model...Done. Log-likelihood = 150.208 +## Running Stasis:BM model...Done. Log-likelihood = 127.707 \end{verbatim} \begin{figure} @@ -4530,22 +4330,22 @@ \subsection{Multiple modes of evolution (time shifts)}\label{multiple-modes-of-e \begin{verbatim} ## aicc delta_aicc weight_aicc log.lik param ancestral state -## OU:Trend -287 0.0 0.977 147.8 4 3.352 -## BM:OU -280 7.5 0.023 144.1 4 3.350 -## Stasis:BM -244 43.4 0.000 125.1 3 NA -## Stasis:OU -240 47.7 0.000 125.1 5 NA -## BM:Stasis -130 157.1 0.000 69.3 4 3.268 +## OU:Trend -292 0.0 0.977 150.2 4 3.218 +## BM:OU -285 7.5 0.023 146.5 4 3.216 +## Stasis:BM -249 42.9 0.000 127.7 3 NA +## Stasis:OU -245 47.2 0.000 127.7 5 NA +## BM:Stasis -137 155.5 0.000 72.5 4 3.132 ## sigma squared alpha optima.1 theta.1 omega trend median p value -## OU:Trend 0.001 0.041 NA NA NA 0.011 0.2987013 -## BM:OU 0.001 0.000 4.092 NA NA NA 0.4925075 -## Stasis:BM 0.002 NA NA 3.390 0.004 NA 0.9970030 -## Stasis:OU 0.002 0.000 4.092 3.390 0.004 NA 1.0000000 -## BM:Stasis 0.000 NA NA 3.806 0.058 NA 1.0000000 +## OU:Trend 0.001 0.042 NA NA NA 0.011 0.3066933 +## BM:OU 0.001 0.000 3.934 NA NA NA 0.4985015 +## Stasis:BM 0.002 NA NA 3.25 0.004 NA 0.9960040 +## Stasis:OU 0.002 0.000 3.934 3.25 0.004 NA 0.9990010 +## BM:Stasis 0.000 NA NA 3.66 0.053 NA 1.0000000 ## lower p value upper p value -## OU:Trend 0.2947053 0.3536464 -## BM:OU 0.4875125 0.5134865 -## Stasis:BM 0.9960040 0.9970030 -## Stasis:OU 0.9990010 1.0000000 +## OU:Trend 0.3026973 0.3626374 +## BM:OU 0.4945055 0.5184815 +## Stasis:BM 0.9950050 0.9960040 +## Stasis:OU 0.9980020 1.0000000 ## BM:Stasis 0.9990010 1.0000000 \end{verbatim} @@ -4568,11 +4368,11 @@ \subsection{\texorpdfstring{\texttt{model.test.sim}}{model.test.sim}}\label{mode \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# A simple BM model} -\NormalTok{model\_simulation \textless{}{-}}\StringTok{ }\KeywordTok{model.test.sim}\NormalTok{(}\DataTypeTok{sim =} \DecValTok{1000}\NormalTok{, }\DataTypeTok{model =} \StringTok{"BM"}\NormalTok{,} - \DataTypeTok{time.span =} \DecValTok{50}\NormalTok{, }\DataTypeTok{variance =} \FloatTok{0.1}\NormalTok{,} - \DataTypeTok{sample.size =} \DecValTok{100}\NormalTok{,} - \DataTypeTok{parameters =} \KeywordTok{list}\NormalTok{(}\DataTypeTok{ancestral.state =} \DecValTok{0}\NormalTok{))} +\DocumentationTok{\#\# A simple BM model} +\NormalTok{model\_simulation }\OtherTok{\textless{}{-}} \FunctionTok{model.test.sim}\NormalTok{(}\AttributeTok{sim =} \DecValTok{1000}\NormalTok{, }\AttributeTok{model =} \StringTok{"BM"}\NormalTok{,} + \AttributeTok{time.span =} \DecValTok{50}\NormalTok{, }\AttributeTok{variance =} \FloatTok{0.1}\NormalTok{,} + \AttributeTok{sample.size =} \DecValTok{100}\NormalTok{,} + \AttributeTok{parameters =} \FunctionTok{list}\NormalTok{(}\AttributeTok{ancestral.state =} \DecValTok{0}\NormalTok{))} \NormalTok{model\_simulation} \end{Highlighting} \end{Shaded} @@ -4591,8 +4391,8 @@ \subsection{\texorpdfstring{\texttt{model.test.sim}}{model.test.sim}}\label{mode \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Displaying the 5 first rows of the summary} -\KeywordTok{head}\NormalTok{(}\KeywordTok{summary}\NormalTok{(model\_simulation))} +\DocumentationTok{\#\# Displaying the 5 first rows of the summary} +\FunctionTok{head}\NormalTok{(}\FunctionTok{summary}\NormalTok{(model\_simulation))} \end{Highlighting} \end{Shaded} @@ -4608,8 +4408,8 @@ \subsection{\texorpdfstring{\texttt{model.test.sim}}{model.test.sim}}\label{mode \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Plotting the simulations} -\KeywordTok{plot}\NormalTok{(model\_simulation)} +\DocumentationTok{\#\# Plotting the simulations} +\FunctionTok{plot}\NormalTok{(model\_simulation)} \end{Highlighting} \end{Shaded} @@ -4632,50 +4432,50 @@ \subsubsection{Simulating tested models}\label{simulating-tested-models}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Fitting multiple models on the data set} -\NormalTok{disp\_time \textless{}{-}}\StringTok{ }\KeywordTok{model.test}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_disparity,} - \DataTypeTok{model =} \KeywordTok{c}\NormalTok{(}\StringTok{"Stasis"}\NormalTok{, }\StringTok{"BM"}\NormalTok{, }\StringTok{"OU"}\NormalTok{, }\StringTok{"Trend"}\NormalTok{, }\StringTok{"EB"}\NormalTok{))} +\DocumentationTok{\#\# Fitting multiple models on the data set} +\NormalTok{disp\_time }\OtherTok{\textless{}{-}} \FunctionTok{model.test}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_disparity,} + \AttributeTok{model =} \FunctionTok{c}\NormalTok{(}\StringTok{"Stasis"}\NormalTok{, }\StringTok{"BM"}\NormalTok{, }\StringTok{"OU"}\NormalTok{, }\StringTok{"Trend"}\NormalTok{, }\StringTok{"EB"}\NormalTok{))} \end{Highlighting} \end{Shaded} \begin{verbatim} ## Evidence of equal variance (Bartlett's test of equal variances p = 0). ## Variance is not pooled. -## Running Stasis model...Done. Log-likelihood = -18.694 -## Running BM model...Done. Log-likelihood = 149.289 -## Running OU model...Done. Log-likelihood = 152.119 -## Running Trend model...Done. Log-likelihood = 152.116 -## Running EB model...Done. Log-likelihood = 126.268 +## Running Stasis model...Done. Log-likelihood = -15.562 +## Running BM model...Done. Log-likelihood = 151.637 +## Running OU model...Done. Log-likelihood = 154.512 +## Running Trend model...Done. Log-likelihood = 154.508 +## Running EB model...Done. Log-likelihood = 128.008 \end{verbatim} \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{summary}\NormalTok{(disp\_time)} +\FunctionTok{summary}\NormalTok{(disp\_time)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## aicc delta_aicc weight_aicc log.lik param theta.1 omega ancestral state -## Stasis 41 339.5 0.000 -18.7 2 3.629 0.074 NA -## BM -294 3.6 0.112 149.3 2 NA NA 3.267 -## OU -296 2.1 0.227 152.1 4 NA NA 3.254 -## Trend -298 0.0 0.661 152.1 3 NA NA 3.255 -## EB -246 51.7 0.000 126.3 3 NA NA 4.092 +## Stasis 35 338.0 0.000 -15.6 2 3.486 0.07 NA +## BM -299 3.6 0.108 151.6 2 NA NA 3.132 +## OU -301 2.1 0.229 154.5 4 NA NA 3.118 +## Trend -303 0.0 0.664 154.5 3 NA NA 3.119 +## EB -250 53.0 0.000 128.0 3 NA NA 3.934 ## sigma squared alpha optima.1 trend eb ## Stasis NA NA NA NA NA ## BM 0.001 NA NA NA NA -## OU 0.001 0.001 12.35 NA NA +## OU 0.001 0.001 10.18 NA NA ## Trend 0.001 NA NA 0.007 NA -## EB 0.000 NA NA NA -0.032 +## EB 0.000 NA NA NA -0.034 \end{verbatim} As seen before, the Trend model fitted this dataset the best. -To simulate what 1000 Trend models would look like using the same parameters as the ones estimated with \texttt{model.test} (here the ancestral state being 3.255, the sigma squared being 0.001 and the trend of 0.007), we can simply pass this model to \texttt{model.test.sim}: +To simulate what 1000 Trend models would look like using the same parameters as the ones estimated with \texttt{model.test} (here the ancestral state being 3.119, the sigma squared being 0.001 and the trend of 0.007), we can simply pass this model to \texttt{model.test.sim}: \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Simulating 1000 Trend model with the observed parameters} -\NormalTok{sim\_trend \textless{}{-}}\StringTok{ }\KeywordTok{model.test.sim}\NormalTok{(}\DataTypeTok{sim =} \DecValTok{1000}\NormalTok{, }\DataTypeTok{model =}\NormalTok{ disp\_time)} +\DocumentationTok{\#\# Simulating 1000 Trend model with the observed parameters} +\NormalTok{sim\_trend }\OtherTok{\textless{}{-}} \FunctionTok{model.test.sim}\NormalTok{(}\AttributeTok{sim =} \DecValTok{1000}\NormalTok{, }\AttributeTok{model =}\NormalTok{ disp\_time)} \NormalTok{sim\_trend} \end{Highlighting} \end{Shaded} @@ -4686,20 +4486,20 @@ \subsubsection{Simulating tested models}\label{simulating-tested-models}} ## ## Model simulated (1000 times): ## aicc log.lik param ancestral state sigma squared trend -## Trend -298 152.1 3 3.255 0.001 0.007 +## Trend -303 154.5 3 3.119 0.001 0.007 ## ## Rank envelope test: -## p-value of the global test: 0.99001 (ties method: erl) -## p-interval : (0.989011, 0.99001) +## p-value of the global test: 0.992008 (ties method: erl) +## p-interval : (0.991009, 0.992008) \end{verbatim} By default, the model simulated is the one with the lowest AICc (\texttt{model.rank\ =\ 1}) but it is possible to choose any ranked model, for example, the OU (second one): \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Simulating 1000 OU model with the observed parameters} -\NormalTok{sim\_OU \textless{}{-}}\StringTok{ }\KeywordTok{model.test.sim}\NormalTok{(}\DataTypeTok{sim =} \DecValTok{1000}\NormalTok{, }\DataTypeTok{model =}\NormalTok{ disp\_time,} - \DataTypeTok{model.rank =} \DecValTok{2}\NormalTok{)} +\DocumentationTok{\#\# Simulating 1000 OU model with the observed parameters} +\NormalTok{sim\_OU }\OtherTok{\textless{}{-}} \FunctionTok{model.test.sim}\NormalTok{(}\AttributeTok{sim =} \DecValTok{1000}\NormalTok{, }\AttributeTok{model =}\NormalTok{ disp\_time,} + \AttributeTok{model.rank =} \DecValTok{2}\NormalTok{)} \NormalTok{sim\_OU} \end{Highlighting} \end{Shaded} @@ -4710,55 +4510,55 @@ \subsubsection{Simulating tested models}\label{simulating-tested-models}} ## ## Model simulated (1000 times): ## aicc log.lik param ancestral state sigma squared alpha optima.1 -## OU -296 152.1 4 3.254 0.001 0.001 12.35 +## OU -301 154.5 4 3.118 0.001 0.001 10.18 ## ## Rank envelope test: -## p-value of the global test: 0.992008 (ties method: erl) -## p-interval : (0.99001, 0.992008) +## p-value of the global test: 0.991009 (ties method: erl) +## p-interval : (0.989011, 0.991009) \end{verbatim} And as the example above, the simulated data can be plotted or summarised: \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{head}\NormalTok{(}\KeywordTok{summary}\NormalTok{(sim\_trend))} +\FunctionTok{head}\NormalTok{(}\FunctionTok{summary}\NormalTok{(sim\_trend))} \end{Highlighting} \end{Shaded} \begin{verbatim} ## subsets n var median 2.5% 25% 75% 97.5% -## 1 120 5 0.01723152 3.255121 3.135057 3.219150 3.293407 3.375118 -## 2 119 5 0.03555816 3.265538 3.093355 3.200493 3.323520 3.440795 -## 3 118 6 0.03833089 3.269497 3.090438 3.212015 3.329629 3.443074 -## 4 117 7 0.03264826 3.279180 3.112205 3.224810 3.336801 3.447997 -## 5 116 7 0.03264826 3.284500 3.114788 3.223247 3.347970 3.463631 -## 6 115 7 0.03264826 3.293918 3.101298 3.231659 3.354321 3.474645 +## 1 120 5 0.01791717 3.119216 2.996786 3.082536 3.158256 3.241577 +## 2 119 5 0.03522253 3.129400 2.958681 3.064908 3.186889 3.303168 +## 3 118 6 0.03783622 3.133125 2.957150 3.076447 3.192556 3.304469 +## 4 117 7 0.03214472 3.143511 2.978352 3.089036 3.199075 3.307842 +## 5 116 7 0.03214472 3.147732 2.981253 3.087695 3.210136 3.321990 +## 6 115 7 0.03214472 3.157588 2.969189 3.094733 3.216221 3.335341 \end{verbatim} \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{head}\NormalTok{(}\KeywordTok{summary}\NormalTok{(sim\_OU))} +\FunctionTok{head}\NormalTok{(}\FunctionTok{summary}\NormalTok{(sim\_OU))} \end{Highlighting} \end{Shaded} \begin{verbatim} ## subsets n var median 2.5% 25% 75% 97.5% -## 1 120 5 0.01723152 3.253367 3.141471 3.212180 3.293760 3.371622 -## 2 119 5 0.03555816 3.263167 3.083477 3.197442 3.324438 3.440447 -## 3 118 6 0.03833089 3.262952 3.101351 3.203860 3.332595 3.440163 -## 4 117 7 0.03264826 3.272569 3.104476 3.214511 3.330587 3.442792 -## 5 116 7 0.03264826 3.280423 3.100220 3.219765 3.342726 3.475877 -## 6 115 7 0.03264826 3.287359 3.094699 3.222523 3.355278 3.477518 +## 1 120 5 0.01791717 3.116975 3.002874 3.074977 3.158164 3.237559 +## 2 119 5 0.03522253 3.126662 2.948491 3.061492 3.187414 3.302442 +## 3 118 6 0.03783622 3.126408 2.966988 3.068517 3.195251 3.301177 +## 4 117 7 0.03214472 3.136145 2.970973 3.079345 3.192427 3.301722 +## 5 116 7 0.03214472 3.144302 2.967779 3.083789 3.205035 3.336560 +## 6 115 7 0.03214472 3.151057 2.961801 3.086444 3.216077 3.336897 \end{verbatim} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The trend model with some graphical options} -\KeywordTok{plot}\NormalTok{(sim\_trend, }\DataTypeTok{xlab =} \StringTok{"Time (Mya)"}\NormalTok{, }\DataTypeTok{ylab =} \StringTok{"sum of variances"}\NormalTok{,} - \DataTypeTok{col =} \KeywordTok{c}\NormalTok{(}\StringTok{"\#F65205"}\NormalTok{, }\StringTok{"\#F38336"}\NormalTok{, }\StringTok{"\#F7B27E"}\NormalTok{))} +\DocumentationTok{\#\# The trend model with some graphical options} +\FunctionTok{plot}\NormalTok{(sim\_trend, }\AttributeTok{xlab =} \StringTok{"Time (Mya)"}\NormalTok{, }\AttributeTok{ylab =} \StringTok{"sum of variances"}\NormalTok{,} + \AttributeTok{col =} \FunctionTok{c}\NormalTok{(}\StringTok{"\#F65205"}\NormalTok{, }\StringTok{"\#F38336"}\NormalTok{, }\StringTok{"\#F7B27E"}\NormalTok{))} -\CommentTok{\#\# Adding the observed disparity through time} -\KeywordTok{plot}\NormalTok{(BeckLee\_disparity, }\DataTypeTok{add =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{col =} \KeywordTok{c}\NormalTok{(}\StringTok{"\#3E9CBA"}\NormalTok{, }\StringTok{"\#98D4CF90"}\NormalTok{, }\StringTok{"\#BFE4E390"}\NormalTok{))} +\DocumentationTok{\#\# Adding the observed disparity through time} +\FunctionTok{plot}\NormalTok{(BeckLee\_disparity, }\AttributeTok{add =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{col =} \FunctionTok{c}\NormalTok{(}\StringTok{"\#3E9CBA"}\NormalTok{, }\StringTok{"\#98D4CF90"}\NormalTok{, }\StringTok{"\#BFE4E390"}\NormalTok{))} \end{Highlighting} \end{Shaded} @@ -4784,9 +4584,9 @@ \section{Disparity as a distribution}\label{disparity-distribution}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Measuring disparity as a whole distribution} -\NormalTok{disparity\_centroids \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(boot\_time\_slices, } - \DataTypeTok{metric =}\NormalTok{ centroids)} +\DocumentationTok{\#\# Measuring disparity as a whole distribution} +\NormalTok{disparity\_centroids }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(boot\_time\_slices, } + \AttributeTok{metric =}\NormalTok{ centroids)} \end{Highlighting} \end{Shaded} @@ -4794,9 +4594,9 @@ \section{Disparity as a distribution}\label{disparity-distribution}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Measuring median disparity in each time slice} -\NormalTok{disparity\_centroids\_median \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(disparity\_centroids,} - \DataTypeTok{metric =}\NormalTok{ median)} +\DocumentationTok{\#\# Measuring median disparity in each time slice} +\NormalTok{disparity\_centroids\_median }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(disparity\_centroids,} + \AttributeTok{metric =}\NormalTok{ median)} \end{Highlighting} \end{Shaded} @@ -4804,33 +4604,33 @@ \section{Disparity as a distribution}\label{disparity-distribution}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Summarising both disparity measurements:} -\CommentTok{\#\# The distributions:} -\KeywordTok{summary}\NormalTok{(disparity\_centroids)} +\DocumentationTok{\#\# Summarising both disparity measurements:} +\DocumentationTok{\#\# The distributions:} +\FunctionTok{summary}\NormalTok{(disparity\_centroids)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## subsets n obs.median bs.median 2.5% 25% 75% 97.5% -## 1 120 5 1.605 1.376 0.503 1.247 1.695 1.895 -## 2 80 19 1.834 1.774 1.514 1.691 1.853 1.968 -## 3 40 15 1.804 1.789 1.468 1.684 1.889 2.095 -## 4 0 10 1.911 1.809 1.337 1.721 1.968 2.099 +## 1 120 5 1.569 1.338 0.834 1.230 1.650 1.894 +## 2 80 19 1.796 1.739 1.498 1.652 1.812 1.928 +## 3 40 15 1.767 1.764 1.427 1.654 1.859 2.052 +## 4 0 10 1.873 1.779 1.361 1.685 1.934 2.058 \end{verbatim} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The summary of the distributions (as median)} -\KeywordTok{summary}\NormalTok{(disparity\_centroids\_median)} +\DocumentationTok{\#\# The summary of the distributions (as median)} +\FunctionTok{summary}\NormalTok{(disparity\_centroids\_median)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## subsets n obs bs.median 2.5% 25% 75% 97.5% -## 1 120 5 1.605 1.395 0.503 0.994 1.625 1.686 -## 2 80 19 1.834 1.774 1.682 1.749 1.799 1.823 -## 3 40 15 1.804 1.790 1.579 1.750 1.830 1.875 -## 4 0 10 1.911 1.812 1.659 1.784 1.859 1.930 +## 1 120 5 1.569 1.351 0.648 1.282 1.596 1.641 +## 2 80 19 1.796 1.739 1.655 1.721 1.756 1.787 +## 3 40 15 1.767 1.757 1.623 1.721 1.793 1.837 +## 4 0 10 1.873 1.781 1.564 1.756 1.834 1.900 \end{verbatim} We can see that the summary message for the distribution is slightly different than before. @@ -4841,22 +4641,22 @@ \section{Disparity as a distribution}\label{disparity-distribution}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Graphical parameters} -\NormalTok{op \textless{}{-}}\StringTok{ }\KeywordTok{par}\NormalTok{(}\DataTypeTok{bty =} \StringTok{"n"}\NormalTok{, }\DataTypeTok{mfrow =} \KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{))} +\DocumentationTok{\#\# Graphical parameters} +\NormalTok{op }\OtherTok{\textless{}{-}} \FunctionTok{par}\NormalTok{(}\AttributeTok{bty =} \StringTok{"n"}\NormalTok{, }\AttributeTok{mfrow =} \FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{))} -\CommentTok{\#\# Plotting both disparity measurements} -\KeywordTok{plot}\NormalTok{(disparity\_centroids,} - \DataTypeTok{ylab =} \StringTok{"Distribution of all the distances"}\NormalTok{)} -\KeywordTok{plot}\NormalTok{(disparity\_centroids\_median,} - \DataTypeTok{ylab =} \StringTok{"Distribution of the medians of all the distances"}\NormalTok{)} +\DocumentationTok{\#\# Plotting both disparity measurements} +\FunctionTok{plot}\NormalTok{(disparity\_centroids,} + \AttributeTok{ylab =} \StringTok{"Distribution of all the distances"}\NormalTok{)} +\FunctionTok{plot}\NormalTok{(disparity\_centroids\_median,} + \AttributeTok{ylab =} \StringTok{"Distribution of the medians of all the distances"}\NormalTok{)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-116-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-117-1.pdf} \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{par}\NormalTok{(op)} +\FunctionTok{par}\NormalTok{(op)} \end{Highlighting} \end{Shaded} @@ -4864,19 +4664,19 @@ \section{Disparity as a distribution}\label{disparity-distribution}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Probability of overlap in the distribution of medians} -\KeywordTok{test.dispRity}\NormalTok{(disparity\_centroids\_median, }\DataTypeTok{test =}\NormalTok{ bhatt.coeff)} +\DocumentationTok{\#\# Probability of overlap in the distribution of medians} +\FunctionTok{test.dispRity}\NormalTok{(disparity\_centroids\_median, }\AttributeTok{test =}\NormalTok{ bhatt.coeff)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## bhatt.coeff -## 120 : 80 0.09486833 -## 120 : 40 0.18256185 -## 120 : 0 0.18800657 -## 80 : 40 0.80759884 -## 80 : 0 0.71503765 -## 40 : 0 0.84542569 +## 120 : 80 0.08831761 +## 120 : 40 0.10583005 +## 120 : 0 0.15297059 +## 80 : 40 0.83840952 +## 80 : 0 0.63913150 +## 40 : 0 0.78405839 \end{verbatim} In this case, we are looking at the probability of overlap of the distribution of median distances from centroids among each pair of time slices. @@ -4888,19 +4688,19 @@ \section{Disparity as a distribution}\label{disparity-distribution}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Probability of overlap for the full distributions} -\KeywordTok{test.dispRity}\NormalTok{(disparity\_centroids, }\DataTypeTok{test =}\NormalTok{ bhatt.coeff)} +\DocumentationTok{\#\# Probability of overlap for the full distributions} +\FunctionTok{test.dispRity}\NormalTok{(disparity\_centroids, }\AttributeTok{test =}\NormalTok{ bhatt.coeff)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## bhatt.coeff -## 120 : 80 0.6088450 -## 120 : 40 0.6380217 -## 120 : 0 0.6340849 -## 80 : 40 0.9325982 -## 80 : 0 0.8614280 -## 40 : 0 0.9464329 +## 120 : 80 0.6163631 +## 120 : 40 0.6351473 +## 120 : 0 0.6315225 +## 80 : 40 0.9416508 +## 80 : 0 0.8551990 +## 40 : 0 0.9568684 \end{verbatim} These results show the actual overlap among all the measured distances from centroids concatenated across all the bootstraps. @@ -4911,20 +4711,20 @@ \section{Disparity as a distribution}\label{disparity-distribution}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Boostrapped probability of overlap for the full distributions} -\KeywordTok{test.dispRity}\NormalTok{(disparity\_centroids, }\DataTypeTok{test =}\NormalTok{ bhatt.coeff,} - \DataTypeTok{concatenate =} \OtherTok{FALSE}\NormalTok{)} +\DocumentationTok{\#\# Boostrapped probability of overlap for the full distributions} +\FunctionTok{test.dispRity}\NormalTok{(disparity\_centroids, }\AttributeTok{test =}\NormalTok{ bhatt.coeff,} + \AttributeTok{concatenate =} \ConstantTok{FALSE}\NormalTok{)} \end{Highlighting} \end{Shaded} \begin{verbatim} -## bhatt.coeff 2.5% 25% 75% 97.5% -## 120 : 80 0.2641856 0.0000000 0.1450953 0.3964076 0.5468831 -## 120 : 40 0.2705336 0.0000000 0.1632993 0.3987346 0.6282038 -## 120 : 0 0.2841992 0.0000000 0.2000000 0.4000000 0.7083356 -## 80 : 40 0.6024121 0.3280389 0.4800810 0.7480791 0.8902989 -## 80 : 0 0.4495822 0.1450953 0.3292496 0.5715531 0.7332155 -## 40 : 0 0.5569422 0.2000000 0.4543681 0.6843217 0.8786504 +## bhatt.coeff 2.5% 25% 75% 97.5% +## 120 : 80 0.2671081 0.00000000 0.1450953 0.3964076 0.6084459 +## 120 : 40 0.2864771 0.00000000 0.1632993 0.4238587 0.6444474 +## 120 : 0 0.2864716 0.00000000 0.2000000 0.4000000 0.5837006 +## 80 : 40 0.6187295 0.24391229 0.5284793 0.7440196 0.8961621 +## 80 : 0 0.4790692 0.04873397 0.3754429 0.5946595 0.7797225 +## 40 : 0 0.5513580 0.19542869 0.4207790 0.6870177 0.9066824 \end{verbatim} These results show the median overlap among pairs of distributions in the first column (\texttt{bhatt.coeff}) and then the distribution of these overlaps among each pair of bootstraps. @@ -4944,9 +4744,9 @@ \section{Disparity from other matrices}\label{other-matrices}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Making the eurodist data set into a matrix (rather than "dist" object)} -\NormalTok{eurodist \textless{}{-}}\StringTok{ }\KeywordTok{as.matrix}\NormalTok{(eurodist)} -\NormalTok{eurodist[}\DecValTok{1}\OperatorTok{:}\DecValTok{5}\NormalTok{, }\DecValTok{1}\OperatorTok{:}\DecValTok{5}\NormalTok{]} +\DocumentationTok{\#\# Making the eurodist data set into a matrix (rather than "dist" object)} +\NormalTok{eurodist }\OtherTok{\textless{}{-}} \FunctionTok{as.matrix}\NormalTok{(eurodist)} +\NormalTok{eurodist[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{, }\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{]} \end{Highlighting} \end{Shaded} @@ -4961,34 +4761,35 @@ \section{Disparity from other matrices}\label{other-matrices}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The two groups of cities} -\NormalTok{Northern \textless{}{-}}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"Brussels"}\NormalTok{, }\StringTok{"Calais"}\NormalTok{, }\StringTok{"Cherbourg"}\NormalTok{, }\StringTok{"Cologne"}\NormalTok{, }\StringTok{"Copenhagen"}\NormalTok{,} +\DocumentationTok{\#\# The two groups of cities} +\NormalTok{Northern }\OtherTok{\textless{}{-}} \FunctionTok{c}\NormalTok{(}\StringTok{"Brussels"}\NormalTok{, }\StringTok{"Calais"}\NormalTok{, }\StringTok{"Cherbourg"}\NormalTok{, }\StringTok{"Cologne"}\NormalTok{, }\StringTok{"Copenhagen"}\NormalTok{,} \StringTok{"Hamburg"}\NormalTok{, }\StringTok{"Hook of Holland"}\NormalTok{, }\StringTok{"Paris"}\NormalTok{, }\StringTok{"Stockholm"}\NormalTok{)} -\NormalTok{Southern \textless{}{-}}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"Athens"}\NormalTok{, }\StringTok{"Barcelona"}\NormalTok{, }\StringTok{"Geneva"}\NormalTok{, }\StringTok{"Gibraltar"}\NormalTok{, }\StringTok{"Lisbon"}\NormalTok{, }\StringTok{"Lyons"}\NormalTok{,} +\NormalTok{Southern }\OtherTok{\textless{}{-}} \FunctionTok{c}\NormalTok{(}\StringTok{"Athens"}\NormalTok{, }\StringTok{"Barcelona"}\NormalTok{, }\StringTok{"Geneva"}\NormalTok{, }\StringTok{"Gibraltar"}\NormalTok{, }\StringTok{"Lisbon"}\NormalTok{, }\StringTok{"Lyons"}\NormalTok{,} \StringTok{"Madrid"}\NormalTok{, }\StringTok{"Marseilles"}\NormalTok{, }\StringTok{"Milan"}\NormalTok{, }\StringTok{"Munich"}\NormalTok{, }\StringTok{"Rome"}\NormalTok{, }\StringTok{"Vienna"}\NormalTok{)} -\CommentTok{\#\# Creating the subset dispRity object} -\NormalTok{eurodist\_subsets \textless{}{-}}\StringTok{ }\KeywordTok{custom.subsets}\NormalTok{(eurodist, }\DataTypeTok{group =} \KeywordTok{list}\NormalTok{(}\StringTok{"Northern"}\NormalTok{ =}\StringTok{ }\NormalTok{Northern,} - \StringTok{"Southern"}\NormalTok{ =}\StringTok{ }\NormalTok{Southern))} +\DocumentationTok{\#\# Creating the subset dispRity object} +\NormalTok{eurodist\_subsets }\OtherTok{\textless{}{-}} \FunctionTok{custom.subsets}\NormalTok{(eurodist, }\AttributeTok{group =} \FunctionTok{list}\NormalTok{(}\StringTok{"Northern"} \OtherTok{=}\NormalTok{ Northern,} + \StringTok{"Southern"} \OtherTok{=}\NormalTok{ Southern))} \end{Highlighting} \end{Shaded} \begin{verbatim} ## Warning: custom.subsets is applied on what seems to be a distance matrix. ## The resulting matrices won't be distance matrices anymore! +## You can use dist.data = TRUE, if you want to keep the data as a distance matrix. \end{verbatim} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Bootstrapping and rarefying to 9 elements (the number of Northern cities)} -\NormalTok{eurodist\_bs \textless{}{-}}\StringTok{ }\KeywordTok{boot.matrix}\NormalTok{(eurodist\_subsets, }\DataTypeTok{rarefaction =} \DecValTok{9}\NormalTok{)} +\DocumentationTok{\#\# Bootstrapping and rarefying to 9 elements (the number of Northern cities)} +\NormalTok{eurodist\_bs }\OtherTok{\textless{}{-}} \FunctionTok{boot.matrix}\NormalTok{(eurodist\_subsets, }\AttributeTok{rarefaction =} \DecValTok{9}\NormalTok{)} -\CommentTok{\#\# Measuring disparity as the median distance from group\textquotesingle{}s centroid} -\NormalTok{euro\_disp \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(eurodist\_bs, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(median, centroids))} +\DocumentationTok{\#\# Measuring disparity as the median distance from group\textquotesingle{}s centroid} +\NormalTok{euro\_disp }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(eurodist\_bs, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(median, centroids))} -\CommentTok{\#\# Testing the differences using a simple wilcox.test} -\NormalTok{euro\_diff \textless{}{-}}\StringTok{ }\KeywordTok{test.dispRity}\NormalTok{(euro\_disp, }\DataTypeTok{test =}\NormalTok{ wilcox.test)} -\NormalTok{euro\_diff\_rar \textless{}{-}}\StringTok{ }\KeywordTok{test.dispRity}\NormalTok{(euro\_disp, }\DataTypeTok{test =}\NormalTok{ wilcox.test, }\DataTypeTok{rarefaction =} \DecValTok{9}\NormalTok{)} +\DocumentationTok{\#\# Testing the differences using a simple wilcox.test} +\NormalTok{euro\_diff }\OtherTok{\textless{}{-}} \FunctionTok{test.dispRity}\NormalTok{(euro\_disp, }\AttributeTok{test =}\NormalTok{ wilcox.test)} +\NormalTok{euro\_diff\_rar }\OtherTok{\textless{}{-}} \FunctionTok{test.dispRity}\NormalTok{(euro\_disp, }\AttributeTok{test =}\NormalTok{ wilcox.test, }\AttributeTok{rarefaction =} \DecValTok{9}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -4996,17 +4797,17 @@ \section{Disparity from other matrices}\label{other-matrices}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Ordinating the eurodist matrix (with 11 dimensions)} -\NormalTok{euro\_ord \textless{}{-}}\StringTok{ }\KeywordTok{cmdscale}\NormalTok{(eurodist, }\DataTypeTok{k =} \DecValTok{11}\NormalTok{)} +\DocumentationTok{\#\# Ordinating the eurodist matrix (with 11 dimensions)} +\NormalTok{euro\_ord }\OtherTok{\textless{}{-}} \FunctionTok{cmdscale}\NormalTok{(eurodist, }\AttributeTok{k =} \DecValTok{11}\NormalTok{)} -\CommentTok{\#\# Calculating disparity on the bootstrapped and rarefied subset data} -\NormalTok{euro\_ord\_disp \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(}\KeywordTok{boot.matrix}\NormalTok{(}\KeywordTok{custom.subsets}\NormalTok{(euro\_ord, }\DataTypeTok{group =} - \KeywordTok{list}\NormalTok{(}\StringTok{"Northern"}\NormalTok{ =}\StringTok{ }\NormalTok{Northern, }\StringTok{"Southern"}\NormalTok{ =}\StringTok{ }\NormalTok{Southern)), }\DataTypeTok{rarefaction =} \DecValTok{9}\NormalTok{),} - \DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(median, centroids))} +\DocumentationTok{\#\# Calculating disparity on the bootstrapped and rarefied subset data} +\NormalTok{euro\_ord\_disp }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(}\FunctionTok{boot.matrix}\NormalTok{(}\FunctionTok{custom.subsets}\NormalTok{(euro\_ord, }\AttributeTok{group =} + \FunctionTok{list}\NormalTok{(}\StringTok{"Northern"} \OtherTok{=}\NormalTok{ Northern, }\StringTok{"Southern"} \OtherTok{=}\NormalTok{ Southern)), }\AttributeTok{rarefaction =} \DecValTok{9}\NormalTok{),} + \AttributeTok{metric =} \FunctionTok{c}\NormalTok{(median, centroids))} -\CommentTok{\#\# Testing the differences using a simple wilcox.test} -\NormalTok{euro\_ord\_diff \textless{}{-}}\StringTok{ }\KeywordTok{test.dispRity}\NormalTok{(euro\_ord\_disp, }\DataTypeTok{test =}\NormalTok{ wilcox.test)} -\NormalTok{euro\_ord\_diff\_rar \textless{}{-}}\StringTok{ }\KeywordTok{test.dispRity}\NormalTok{(euro\_ord\_disp, }\DataTypeTok{test =}\NormalTok{ wilcox.test, }\DataTypeTok{rarefaction =} \DecValTok{9}\NormalTok{)} +\DocumentationTok{\#\# Testing the differences using a simple wilcox.test} +\NormalTok{euro\_ord\_diff }\OtherTok{\textless{}{-}} \FunctionTok{test.dispRity}\NormalTok{(euro\_ord\_disp, }\AttributeTok{test =}\NormalTok{ wilcox.test)} +\NormalTok{euro\_ord\_diff\_rar }\OtherTok{\textless{}{-}} \FunctionTok{test.dispRity}\NormalTok{(euro\_ord\_disp, }\AttributeTok{test =}\NormalTok{ wilcox.test, }\AttributeTok{rarefaction =} \DecValTok{9}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -5014,29 +4815,29 @@ \section{Disparity from other matrices}\label{other-matrices}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Plotting the differences} -\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =} \KeywordTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{), }\DataTypeTok{bty =} \StringTok{"n"}\NormalTok{)} -\CommentTok{\#\# Plotting the normal disparity} -\KeywordTok{plot}\NormalTok{(euro\_disp, }\DataTypeTok{main =} \StringTok{"Distance differences"}\NormalTok{)} -\CommentTok{\#\# Adding the p{-}value} -\KeywordTok{text}\NormalTok{(}\FloatTok{1.5}\NormalTok{, }\DecValTok{4000}\NormalTok{, }\KeywordTok{paste0}\NormalTok{(}\StringTok{"p="}\NormalTok{,}\KeywordTok{round}\NormalTok{(euro\_diff[[}\DecValTok{2}\NormalTok{]][[}\DecValTok{1}\NormalTok{]], }\DataTypeTok{digit =} \DecValTok{5}\NormalTok{)))} -\CommentTok{\#\# Plotting the rarefied disparity} -\KeywordTok{plot}\NormalTok{(euro\_disp, }\DataTypeTok{rarefaction =} \DecValTok{9}\NormalTok{, }\DataTypeTok{main =} \StringTok{"Distance differences (rarefied)"}\NormalTok{)} -\CommentTok{\#\# Adding the p{-}value} -\KeywordTok{text}\NormalTok{(}\FloatTok{1.5}\NormalTok{, }\DecValTok{4000}\NormalTok{, }\KeywordTok{paste0}\NormalTok{(}\StringTok{"p="}\NormalTok{,}\KeywordTok{round}\NormalTok{(euro\_diff\_rar[[}\DecValTok{2}\NormalTok{]][[}\DecValTok{1}\NormalTok{]], }\DataTypeTok{digit =} \DecValTok{5}\NormalTok{)))} +\DocumentationTok{\#\# Plotting the differences} +\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =} \FunctionTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{), }\AttributeTok{bty =} \StringTok{"n"}\NormalTok{)} +\DocumentationTok{\#\# Plotting the normal disparity} +\FunctionTok{plot}\NormalTok{(euro\_disp, }\AttributeTok{main =} \StringTok{"Distance differences"}\NormalTok{)} +\DocumentationTok{\#\# Adding the p{-}value} +\FunctionTok{text}\NormalTok{(}\FloatTok{1.5}\NormalTok{, }\DecValTok{4000}\NormalTok{, }\FunctionTok{paste0}\NormalTok{(}\StringTok{"p="}\NormalTok{,}\FunctionTok{round}\NormalTok{(euro\_diff[[}\DecValTok{2}\NormalTok{]][[}\DecValTok{1}\NormalTok{]], }\AttributeTok{digit =} \DecValTok{5}\NormalTok{)))} +\DocumentationTok{\#\# Plotting the rarefied disparity} +\FunctionTok{plot}\NormalTok{(euro\_disp, }\AttributeTok{rarefaction =} \DecValTok{9}\NormalTok{, }\AttributeTok{main =} \StringTok{"Distance differences (rarefied)"}\NormalTok{)} +\DocumentationTok{\#\# Adding the p{-}value} +\FunctionTok{text}\NormalTok{(}\FloatTok{1.5}\NormalTok{, }\DecValTok{4000}\NormalTok{, }\FunctionTok{paste0}\NormalTok{(}\StringTok{"p="}\NormalTok{,}\FunctionTok{round}\NormalTok{(euro\_diff\_rar[[}\DecValTok{2}\NormalTok{]][[}\DecValTok{1}\NormalTok{]], }\AttributeTok{digit =} \DecValTok{5}\NormalTok{)))} -\CommentTok{\#\# Plotting the ordinated disparity} -\KeywordTok{plot}\NormalTok{(euro\_ord\_disp, }\DataTypeTok{main =} \StringTok{"Ordinated differences"}\NormalTok{)} -\CommentTok{\#\# Adding the p{-}value} -\KeywordTok{text}\NormalTok{(}\FloatTok{1.5}\NormalTok{, }\DecValTok{1400}\NormalTok{, }\KeywordTok{paste0}\NormalTok{(}\StringTok{"p="}\NormalTok{,}\KeywordTok{round}\NormalTok{(euro\_ord\_diff[[}\DecValTok{2}\NormalTok{]][[}\DecValTok{1}\NormalTok{]], }\DataTypeTok{digit =} \DecValTok{5}\NormalTok{) ))} -\CommentTok{\#\# Plotting the rarefied disparity} -\KeywordTok{plot}\NormalTok{(euro\_ord\_disp, }\DataTypeTok{rarefaction =} \DecValTok{9}\NormalTok{, }\DataTypeTok{main =} \StringTok{"Ordinated differences (rarefied)"}\NormalTok{)} -\CommentTok{\#\# Adding the p{-}value} -\KeywordTok{text}\NormalTok{(}\FloatTok{1.5}\NormalTok{, }\DecValTok{1400}\NormalTok{, }\KeywordTok{paste0}\NormalTok{(}\StringTok{"p="}\NormalTok{,}\KeywordTok{round}\NormalTok{(euro\_ord\_diff\_rar[[}\DecValTok{2}\NormalTok{]][[}\DecValTok{1}\NormalTok{]], }\DataTypeTok{digit =} \DecValTok{5}\NormalTok{) ))} +\DocumentationTok{\#\# Plotting the ordinated disparity} +\FunctionTok{plot}\NormalTok{(euro\_ord\_disp, }\AttributeTok{main =} \StringTok{"Ordinated differences"}\NormalTok{)} +\DocumentationTok{\#\# Adding the p{-}value} +\FunctionTok{text}\NormalTok{(}\FloatTok{1.5}\NormalTok{, }\DecValTok{1400}\NormalTok{, }\FunctionTok{paste0}\NormalTok{(}\StringTok{"p="}\NormalTok{,}\FunctionTok{round}\NormalTok{(euro\_ord\_diff[[}\DecValTok{2}\NormalTok{]][[}\DecValTok{1}\NormalTok{]], }\AttributeTok{digit =} \DecValTok{5}\NormalTok{) ))} +\DocumentationTok{\#\# Plotting the rarefied disparity} +\FunctionTok{plot}\NormalTok{(euro\_ord\_disp, }\AttributeTok{rarefaction =} \DecValTok{9}\NormalTok{, }\AttributeTok{main =} \StringTok{"Ordinated differences (rarefied)"}\NormalTok{)} +\DocumentationTok{\#\# Adding the p{-}value} +\FunctionTok{text}\NormalTok{(}\FloatTok{1.5}\NormalTok{, }\DecValTok{1400}\NormalTok{, }\FunctionTok{paste0}\NormalTok{(}\StringTok{"p="}\NormalTok{,}\FunctionTok{round}\NormalTok{(euro\_ord\_diff\_rar[[}\DecValTok{2}\NormalTok{]][[}\DecValTok{1}\NormalTok{]], }\AttributeTok{digit =} \DecValTok{5}\NormalTok{) ))} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-122-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-123-1.pdf} As expected, the results are pretty similar in pattern but different in terms of scale. The median centroids distance is expressed in km in the ``Distance differences'' plots and in Euclidean units of variation in the ``Ordinated differences'' plots. @@ -5049,11 +4850,11 @@ \section{Disparity from multiple matrices (and multiple trees!)}\label{multi.inp \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)} -\CommentTok{\#\# Creating 3 matrices with 4 dimensions and 10 elements each (called t1, t2, t3, etc...)} -\NormalTok{matrix\_list \textless{}{-}}\StringTok{ }\KeywordTok{replicate}\NormalTok{(}\DecValTok{3}\NormalTok{, }\KeywordTok{matrix}\NormalTok{(}\KeywordTok{rnorm}\NormalTok{(}\DecValTok{40}\NormalTok{), }\DecValTok{10}\NormalTok{, }\DecValTok{4}\NormalTok{, }\DataTypeTok{dimnames =} \KeywordTok{list}\NormalTok{(}\KeywordTok{paste0}\NormalTok{(}\StringTok{"t"}\NormalTok{, }\DecValTok{1}\OperatorTok{:}\DecValTok{10}\NormalTok{))),} - \DataTypeTok{simplify =} \OtherTok{FALSE}\NormalTok{)} -\KeywordTok{class}\NormalTok{(matrix\_list) }\CommentTok{\# This is a list of matrices} +\FunctionTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)} +\DocumentationTok{\#\# Creating 3 matrices with 4 dimensions and 10 elements each (called t1, t2, t3, etc...)} +\NormalTok{matrix\_list }\OtherTok{\textless{}{-}} \FunctionTok{replicate}\NormalTok{(}\DecValTok{3}\NormalTok{, }\FunctionTok{matrix}\NormalTok{(}\FunctionTok{rnorm}\NormalTok{(}\DecValTok{40}\NormalTok{), }\DecValTok{10}\NormalTok{, }\DecValTok{4}\NormalTok{, }\AttributeTok{dimnames =} \FunctionTok{list}\NormalTok{(}\FunctionTok{paste0}\NormalTok{(}\StringTok{"t"}\NormalTok{, }\DecValTok{1}\SpecialCharTok{:}\DecValTok{10}\NormalTok{))),} + \AttributeTok{simplify =} \ConstantTok{FALSE}\NormalTok{)} +\FunctionTok{class}\NormalTok{(matrix\_list) }\CommentTok{\# This is a list of matrices} \end{Highlighting} \end{Shaded} @@ -5063,8 +4864,8 @@ \section{Disparity from multiple matrices (and multiple trees!)}\label{multi.inp \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Measuring some disparity metric on one of the matrices} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(matrix\_list[[}\DecValTok{1}\NormalTok{]], }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, variances)))} +\DocumentationTok{\#\# Measuring some disparity metric on one of the matrices} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(matrix\_list[[}\DecValTok{1}\NormalTok{]], }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, variances)))} \end{Highlighting} \end{Shaded} @@ -5075,8 +4876,8 @@ \section{Disparity from multiple matrices (and multiple trees!)}\label{multi.inp \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Measuring the same disparity metric on the three matrices} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(matrix\_list, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, variances)))} +\DocumentationTok{\#\# Measuring the same disparity metric on the three matrices} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(matrix\_list, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, variances)))} \end{Highlighting} \end{Shaded} @@ -5094,23 +4895,23 @@ \section{Disparity from multiple matrices (and multiple trees!)}\label{multi.inp \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)} -\CommentTok{\#\# Matches the trees and the matrices} -\CommentTok{\#\# A bunch of trees} -\NormalTok{make.tree \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(n, }\DataTypeTok{fun =}\NormalTok{ rtree) \{} - \CommentTok{\#\# Make the tree} -\NormalTok{ tree \textless{}{-}}\StringTok{ }\KeywordTok{fun}\NormalTok{(n)} -\NormalTok{ tree \textless{}{-}}\StringTok{ }\KeywordTok{chronos}\NormalTok{(tree, }\DataTypeTok{quiet =} \OtherTok{TRUE}\NormalTok{,} - \DataTypeTok{calibration =} \KeywordTok{makeChronosCalib}\NormalTok{(tree, }\DataTypeTok{age.min =} \DecValTok{10}\NormalTok{, }\DataTypeTok{age.max =} \DecValTok{10}\NormalTok{))} - \KeywordTok{class}\NormalTok{(tree) \textless{}{-}}\StringTok{ "phylo"} - \CommentTok{\#\# Add the node labels} -\NormalTok{ tree}\OperatorTok{$}\NormalTok{node.label \textless{}{-}}\StringTok{ }\KeywordTok{paste0}\NormalTok{(}\StringTok{"n"}\NormalTok{, }\DecValTok{1}\OperatorTok{:}\KeywordTok{Nnode}\NormalTok{(tree))} - \CommentTok{\#\# Add the root time} -\NormalTok{ tree}\OperatorTok{$}\NormalTok{root.time \textless{}{-}}\StringTok{ }\KeywordTok{max}\NormalTok{(}\KeywordTok{tree.age}\NormalTok{(tree)}\OperatorTok{$}\NormalTok{ages)} - \KeywordTok{return}\NormalTok{(tree)} +\FunctionTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)} +\DocumentationTok{\#\# Matches the trees and the matrices} +\DocumentationTok{\#\# A bunch of trees} +\NormalTok{make.tree }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(n, }\AttributeTok{fun =}\NormalTok{ rtree) \{} + \DocumentationTok{\#\# Make the tree} +\NormalTok{ tree }\OtherTok{\textless{}{-}} \FunctionTok{fun}\NormalTok{(n)} +\NormalTok{ tree }\OtherTok{\textless{}{-}} \FunctionTok{chronos}\NormalTok{(tree, }\AttributeTok{quiet =} \ConstantTok{TRUE}\NormalTok{,} + \AttributeTok{calibration =} \FunctionTok{makeChronosCalib}\NormalTok{(tree, }\AttributeTok{age.min =} \DecValTok{10}\NormalTok{, }\AttributeTok{age.max =} \DecValTok{10}\NormalTok{))} + \FunctionTok{class}\NormalTok{(tree) }\OtherTok{\textless{}{-}} \StringTok{"phylo"} + \DocumentationTok{\#\# Add the node labels} +\NormalTok{ tree}\SpecialCharTok{$}\NormalTok{node.label }\OtherTok{\textless{}{-}} \FunctionTok{paste0}\NormalTok{(}\StringTok{"n"}\NormalTok{, }\DecValTok{1}\SpecialCharTok{:}\FunctionTok{Nnode}\NormalTok{(tree))} + \DocumentationTok{\#\# Add the root time} +\NormalTok{ tree}\SpecialCharTok{$}\NormalTok{root.time }\OtherTok{\textless{}{-}} \FunctionTok{max}\NormalTok{(}\FunctionTok{tree.age}\NormalTok{(tree)}\SpecialCharTok{$}\NormalTok{ages)} + \FunctionTok{return}\NormalTok{(tree)} \NormalTok{\}} -\NormalTok{trees \textless{}{-}}\StringTok{ }\KeywordTok{replicate}\NormalTok{(}\DecValTok{3}\NormalTok{, }\KeywordTok{make.tree}\NormalTok{(}\DecValTok{10}\NormalTok{), }\DataTypeTok{simplify =} \OtherTok{FALSE}\NormalTok{)} -\KeywordTok{class}\NormalTok{(trees) \textless{}{-}}\StringTok{ "multiPhylo"} +\NormalTok{trees }\OtherTok{\textless{}{-}} \FunctionTok{replicate}\NormalTok{(}\DecValTok{3}\NormalTok{, }\FunctionTok{make.tree}\NormalTok{(}\DecValTok{10}\NormalTok{), }\AttributeTok{simplify =} \ConstantTok{FALSE}\NormalTok{)} +\FunctionTok{class}\NormalTok{(trees) }\OtherTok{\textless{}{-}} \StringTok{"multiPhylo"} \NormalTok{trees} \end{Highlighting} \end{Shaded} @@ -5123,20 +4924,20 @@ \section{Disparity from multiple matrices (and multiple trees!)}\label{multi.inp \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# A function for running the ancestral states estimations} -\NormalTok{do.ace \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(tree, matrix) \{} - \CommentTok{\#\# Run one ace} -\NormalTok{ fun.ace \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(character, tree) \{} -\NormalTok{ results \textless{}{-}}\StringTok{ }\KeywordTok{ace}\NormalTok{(character, }\DataTypeTok{phy =}\NormalTok{ tree)}\OperatorTok{$}\NormalTok{ace} - \KeywordTok{names}\NormalTok{(results) \textless{}{-}}\StringTok{ }\KeywordTok{paste0}\NormalTok{(}\StringTok{"n"}\NormalTok{, }\DecValTok{1}\OperatorTok{:}\KeywordTok{Nnode}\NormalTok{(tree))} - \KeywordTok{return}\NormalTok{(results)} +\DocumentationTok{\#\# A function for running the ancestral states estimations} +\NormalTok{do.ace }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(tree, matrix) \{} + \DocumentationTok{\#\# Run one ace} +\NormalTok{ fun.ace }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(character, tree) \{} +\NormalTok{ results }\OtherTok{\textless{}{-}} \FunctionTok{ace}\NormalTok{(character, }\AttributeTok{phy =}\NormalTok{ tree)}\SpecialCharTok{$}\NormalTok{ace} + \FunctionTok{names}\NormalTok{(results) }\OtherTok{\textless{}{-}} \FunctionTok{paste0}\NormalTok{(}\StringTok{"n"}\NormalTok{, }\DecValTok{1}\SpecialCharTok{:}\FunctionTok{Nnode}\NormalTok{(tree))} + \FunctionTok{return}\NormalTok{(results)} \NormalTok{ \}} - \CommentTok{\#\# Run all ace} - \KeywordTok{return}\NormalTok{(}\KeywordTok{rbind}\NormalTok{(matrix, }\KeywordTok{apply}\NormalTok{(matrix, }\DecValTok{2}\NormalTok{, fun.ace, }\DataTypeTok{tree =}\NormalTok{ tree)))} + \DocumentationTok{\#\# Run all ace} + \FunctionTok{return}\NormalTok{(}\FunctionTok{rbind}\NormalTok{(matrix, }\FunctionTok{apply}\NormalTok{(matrix, }\DecValTok{2}\NormalTok{, fun.ace, }\AttributeTok{tree =}\NormalTok{ tree)))} \NormalTok{\}} -\CommentTok{\#\# All matrices} -\NormalTok{matrices \textless{}{-}}\StringTok{ }\KeywordTok{mapply}\NormalTok{(do.ace, trees, matrix\_list, }\DataTypeTok{SIMPLIFY =} \OtherTok{FALSE}\NormalTok{)} +\DocumentationTok{\#\# All matrices} +\NormalTok{matrices }\OtherTok{\textless{}{-}} \FunctionTok{mapply}\NormalTok{(do.ace, trees, matrix\_list, }\AttributeTok{SIMPLIFY =} \ConstantTok{FALSE}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -5146,16 +4947,16 @@ \section{Disparity from multiple matrices (and multiple trees!)}\label{multi.inp \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Making three "proximity" time slices across one tree} -\NormalTok{one\_tree \textless{}{-}}\StringTok{ }\KeywordTok{chrono.subsets}\NormalTok{(matrices[[}\DecValTok{1}\NormalTok{]], trees[[}\DecValTok{1}\NormalTok{]],} - \DataTypeTok{method =} \StringTok{"continuous"}\NormalTok{,} - \DataTypeTok{model =} \StringTok{"proximity"}\NormalTok{, }\DataTypeTok{time =} \DecValTok{3}\NormalTok{)} -\CommentTok{\#\# Making three "proximity" time slices across the three trees} -\NormalTok{three\_tree \textless{}{-}}\StringTok{ }\KeywordTok{chrono.subsets}\NormalTok{(matrices[[}\DecValTok{1}\NormalTok{]], trees,} - \DataTypeTok{method =} \StringTok{"continuous"}\NormalTok{,} - \DataTypeTok{model =} \StringTok{"proximity"}\NormalTok{, }\DataTypeTok{time =} \DecValTok{3}\NormalTok{)} -\CommentTok{\#\# Measuring disparity as the sum of variances and summarising it} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(one\_tree, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, variances)))} +\DocumentationTok{\#\# Making three "proximity" time slices across one tree} +\NormalTok{one\_tree }\OtherTok{\textless{}{-}} \FunctionTok{chrono.subsets}\NormalTok{(matrices[[}\DecValTok{1}\NormalTok{]], trees[[}\DecValTok{1}\NormalTok{]],} + \AttributeTok{method =} \StringTok{"continuous"}\NormalTok{,} + \AttributeTok{model =} \StringTok{"proximity"}\NormalTok{, }\AttributeTok{time =} \DecValTok{3}\NormalTok{)} +\DocumentationTok{\#\# Making three "proximity" time slices across the three trees} +\NormalTok{three\_tree }\OtherTok{\textless{}{-}} \FunctionTok{chrono.subsets}\NormalTok{(matrices[[}\DecValTok{1}\NormalTok{]], trees,} + \AttributeTok{method =} \StringTok{"continuous"}\NormalTok{,} + \AttributeTok{model =} \StringTok{"proximity"}\NormalTok{, }\AttributeTok{time =} \DecValTok{3}\NormalTok{)} +\DocumentationTok{\#\# Measuring disparity as the sum of variances and summarising it} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(one\_tree, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, variances)))} \end{Highlighting} \end{Shaded} @@ -5168,7 +4969,7 @@ \section{Disparity from multiple matrices (and multiple trees!)}\label{multi.inp \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(three\_tree, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, variances)))} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(three\_tree, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, variances)))} \end{Highlighting} \end{Shaded} @@ -5183,19 +4984,19 @@ \section{Disparity from multiple matrices (and multiple trees!)}\label{multi.inp \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =} \KeywordTok{c}\NormalTok{(}\DecValTok{3}\NormalTok{,}\DecValTok{1}\NormalTok{))} -\NormalTok{slices \textless{}{-}}\StringTok{ }\KeywordTok{c}\NormalTok{(}\FloatTok{7.9}\NormalTok{, }\FloatTok{3.95}\NormalTok{, }\DecValTok{0}\NormalTok{)} -\NormalTok{fun.plot \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(tree) \{} - \KeywordTok{plot}\NormalTok{(tree)} - \KeywordTok{nodelabels}\NormalTok{(tree}\OperatorTok{$}\NormalTok{node.label, }\DataTypeTok{cex =} \FloatTok{0.8}\NormalTok{)} - \KeywordTok{axisPhylo}\NormalTok{()} - \KeywordTok{abline}\NormalTok{(}\DataTypeTok{v =}\NormalTok{ tree}\OperatorTok{$}\NormalTok{root.time }\OperatorTok{{-}}\StringTok{ }\NormalTok{slices)} +\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =} \FunctionTok{c}\NormalTok{(}\DecValTok{3}\NormalTok{,}\DecValTok{1}\NormalTok{))} +\NormalTok{slices }\OtherTok{\textless{}{-}} \FunctionTok{c}\NormalTok{(}\FloatTok{7.9}\NormalTok{, }\FloatTok{3.95}\NormalTok{, }\DecValTok{0}\NormalTok{)} +\NormalTok{fun.plot }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(tree) \{} + \FunctionTok{plot}\NormalTok{(tree)} + \FunctionTok{nodelabels}\NormalTok{(tree}\SpecialCharTok{$}\NormalTok{node.label, }\AttributeTok{cex =} \FloatTok{0.8}\NormalTok{)} + \FunctionTok{axisPhylo}\NormalTok{()} + \FunctionTok{abline}\NormalTok{(}\AttributeTok{v =}\NormalTok{ tree}\SpecialCharTok{$}\NormalTok{root.time }\SpecialCharTok{{-}}\NormalTok{ slices)} \NormalTok{\}} -\NormalTok{silent \textless{}{-}}\StringTok{ }\KeywordTok{lapply}\NormalTok{(trees, fun.plot)} +\NormalTok{silent }\OtherTok{\textless{}{-}} \FunctionTok{lapply}\NormalTok{(trees, fun.plot)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-127-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-128-1.pdf} Note that in this example, the nodes are actually even different in each tree! The node \texttt{n4} for example, is not direct descendent of \texttt{t4} and \texttt{t6} in all trees! To fix that, it is possible to input a list of trees and a list of matrices that correspond to each tree in \texttt{chrono.subsets} by using the \texttt{bind.data\ =\ TRUE} option. @@ -5203,21 +5004,21 @@ \section{Disparity from multiple matrices (and multiple trees!)}\label{multi.inp \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Making three "proximity" time slices across three trees and three bound matrices} -\NormalTok{bound\_data \textless{}{-}}\StringTok{ }\KeywordTok{chrono.subsets}\NormalTok{(matrices, trees,} - \DataTypeTok{method =} \StringTok{"continuous"}\NormalTok{,} - \DataTypeTok{model =} \StringTok{"proximity"}\NormalTok{,} - \DataTypeTok{time =} \DecValTok{3}\NormalTok{,} - \DataTypeTok{bind.data =} \OtherTok{TRUE}\NormalTok{)} -\CommentTok{\#\# Making three "proximity" time slices across three trees and three matrices} -\NormalTok{unbound\_data \textless{}{-}}\StringTok{ }\KeywordTok{chrono.subsets}\NormalTok{(matrices, trees,} - \DataTypeTok{method =} \StringTok{"continuous"}\NormalTok{,} - \DataTypeTok{model =} \StringTok{"proximity"}\NormalTok{,} - \DataTypeTok{time =} \DecValTok{3}\NormalTok{,} - \DataTypeTok{bind.data =} \OtherTok{FALSE}\NormalTok{)} +\DocumentationTok{\#\# Making three "proximity" time slices across three trees and three bound matrices} +\NormalTok{bound\_data }\OtherTok{\textless{}{-}} \FunctionTok{chrono.subsets}\NormalTok{(matrices, trees,} + \AttributeTok{method =} \StringTok{"continuous"}\NormalTok{,} + \AttributeTok{model =} \StringTok{"proximity"}\NormalTok{,} + \AttributeTok{time =} \DecValTok{3}\NormalTok{,} + \AttributeTok{bind.data =} \ConstantTok{TRUE}\NormalTok{)} +\DocumentationTok{\#\# Making three "proximity" time slices across three trees and three matrices} +\NormalTok{unbound\_data }\OtherTok{\textless{}{-}} \FunctionTok{chrono.subsets}\NormalTok{(matrices, trees,} + \AttributeTok{method =} \StringTok{"continuous"}\NormalTok{,} + \AttributeTok{model =} \StringTok{"proximity"}\NormalTok{,} + \AttributeTok{time =} \DecValTok{3}\NormalTok{,} + \AttributeTok{bind.data =} \ConstantTok{FALSE}\NormalTok{)} -\CommentTok{\#\# Measuring disparity as the sum of variances and summarising it} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(bound\_data, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, variances)))} +\DocumentationTok{\#\# Measuring disparity as the sum of variances and summarising it} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(bound\_data, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, variances)))} \end{Highlighting} \end{Shaded} @@ -5230,7 +5031,7 @@ \section{Disparity from multiple matrices (and multiple trees!)}\label{multi.inp \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(unbound\_data, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, variances)))} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(unbound\_data, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, variances)))} \end{Highlighting} \end{Shaded} @@ -5265,34 +5066,34 @@ \section{\texorpdfstring{Disparity with trees: \emph{dispRitree!}}{Disparity wit \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Loading some demo data:} -\CommentTok{\#\# An ordinated matrix with node and tip labels} -\KeywordTok{data}\NormalTok{(BeckLee\_mat99)} -\CommentTok{\#\# The corresponding tree with tip and node labels} -\KeywordTok{data}\NormalTok{(BeckLee\_tree)} -\CommentTok{\#\# A list of tips ages for the fossil data} -\KeywordTok{data}\NormalTok{(BeckLee\_ages)} +\DocumentationTok{\#\# Loading some demo data:} +\DocumentationTok{\#\# An ordinated matrix with node and tip labels} +\FunctionTok{data}\NormalTok{(BeckLee\_mat99)} +\DocumentationTok{\#\# The corresponding tree with tip and node labels} +\FunctionTok{data}\NormalTok{(BeckLee\_tree)} +\DocumentationTok{\#\# A list of tips ages for the fossil data} +\FunctionTok{data}\NormalTok{(BeckLee\_ages)} -\CommentTok{\#\# Time slicing through the tree using the equal split algorithm} -\NormalTok{time\_slices \textless{}{-}}\StringTok{ }\KeywordTok{chrono.subsets}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_mat99,} - \DataTypeTok{tree =}\NormalTok{ BeckLee\_tree,} - \DataTypeTok{FADLAD =}\NormalTok{ BeckLee\_ages,} - \DataTypeTok{method =} \StringTok{"continuous"}\NormalTok{,} - \DataTypeTok{model =} \StringTok{"acctran"}\NormalTok{,} - \DataTypeTok{time =} \DecValTok{15}\NormalTok{)} +\DocumentationTok{\#\# Time slicing through the tree using the equal split algorithm} +\NormalTok{time\_slices }\OtherTok{\textless{}{-}} \FunctionTok{chrono.subsets}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_mat99,} + \AttributeTok{tree =}\NormalTok{ BeckLee\_tree,} + \AttributeTok{FADLAD =}\NormalTok{ BeckLee\_ages,} + \AttributeTok{method =} \StringTok{"continuous"}\NormalTok{,} + \AttributeTok{model =} \StringTok{"acctran"}\NormalTok{,} + \AttributeTok{time =} \DecValTok{15}\NormalTok{)} -\CommentTok{\#\# We can visualise the resulting trait space with the phylogeny} -\CommentTok{\#\# (using the specific argument as follows)} -\KeywordTok{plot}\NormalTok{(time\_slices, }\DataTypeTok{type =} \StringTok{"preview"}\NormalTok{,} - \DataTypeTok{specific.args =} \KeywordTok{list}\NormalTok{(}\DataTypeTok{tree =} \OtherTok{TRUE}\NormalTok{))} +\DocumentationTok{\#\# We can visualise the resulting trait space with the phylogeny} +\DocumentationTok{\#\# (using the specific argument as follows)} +\FunctionTok{plot}\NormalTok{(time\_slices, }\AttributeTok{type =} \StringTok{"preview"}\NormalTok{,} + \AttributeTok{specific.args =} \FunctionTok{list}\NormalTok{(}\AttributeTok{tree =} \ConstantTok{TRUE}\NormalTok{))} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-129-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-130-1.pdf} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Note that some nodes are never selected thus explaining the branches not reaching them.} +\DocumentationTok{\#\# Note that some nodes are never selected thus explaining the branches not reaching them.} \end{Highlighting} \end{Shaded} @@ -5300,10 +5101,10 @@ \section{\texorpdfstring{Disparity with trees: \emph{dispRitree!}}{Disparity wit \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Measuring the sum of the edge length per slice} -\NormalTok{sum\_edge\_length \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(}\KeywordTok{boot.matrix}\NormalTok{(time\_slices), }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, edge.length.tree))} -\CommentTok{\#\# Summarising and plotting} -\KeywordTok{summary}\NormalTok{(sum\_edge\_length)} +\DocumentationTok{\#\# Measuring the sum of the edge length per slice} +\NormalTok{sum\_edge\_length }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(}\FunctionTok{boot.matrix}\NormalTok{(time\_slices), }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, edge.length.tree))} +\DocumentationTok{\#\# Summarising and plotting} +\FunctionTok{summary}\NormalTok{(sum\_edge\_length)} \end{Highlighting} \end{Shaded} @@ -5328,11 +5129,11 @@ \section{\texorpdfstring{Disparity with trees: \emph{dispRitree!}}{Disparity wit \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{plot}\NormalTok{(sum\_edge\_length)} +\FunctionTok{plot}\NormalTok{(sum\_edge\_length)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-130-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-131-1.pdf} Of course this can be done with multiple trees and be combined with an approach using multiple matrices (see \protect\hyperlink{multi.input}{here})! @@ -5347,6 +5148,7 @@ \section{Disparity of variance-covariance matrices (covar)}\label{covar}} You can then analyse this data using a glmm with something like \texttt{my\_data\ \textasciitilde{}\ observations\ +\ phylogeny\ +\ redisduals}. For more info on these models \href{https://en.wikipedia.org/wiki/Generalized_linear_mixed_model}{start here}. For more details on running these models, I suggest using the \texttt{MCMCglmm} package (\citet{MCMCglmm}) from \citet{hadfield2010} (but see also \citet{mulTree}). +For an example use of this code, see \citet{guillerme2023innovation}. \hypertarget{creating-a-disprity-object-with-a-covar-component}{% \subsection{\texorpdfstring{Creating a \texttt{dispRity} object with a \texttt{\$covar} component}{Creating a dispRity object with a \$covar component}}\label{creating-a-disprity-object-with-a-covar-component}} @@ -5355,8 +5157,8 @@ \subsection{\texorpdfstring{Creating a \texttt{dispRity} object with a \texttt{\ \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Loading the charadriiformes data} -\KeywordTok{data}\NormalTok{(charadriiformes)} +\DocumentationTok{\#\# Loading the charadriiformes data} +\FunctionTok{data}\NormalTok{(charadriiformes)} \end{Highlighting} \end{Shaded} @@ -5366,14 +5168,14 @@ \subsection{\texorpdfstring{Creating a \texttt{dispRity} object with a \texttt{\ \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The term names} -\NormalTok{model\_terms \textless{}{-}}\StringTok{ }\KeywordTok{MCMCglmm.levels}\NormalTok{(charadriiformes}\OperatorTok{$}\NormalTok{posteriors)[}\DecValTok{1}\OperatorTok{:}\DecValTok{4}\NormalTok{]} -\CommentTok{\#\# Note that we\textquotesingle{}re ignoring the 5th term of the model that\textquotesingle{}s just the normal residuals} +\DocumentationTok{\#\# The term names} +\NormalTok{model\_terms }\OtherTok{\textless{}{-}} \FunctionTok{MCMCglmm.levels}\NormalTok{(charadriiformes}\SpecialCharTok{$}\NormalTok{posteriors)[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{4}\NormalTok{]} +\DocumentationTok{\#\# Note that we\textquotesingle{}re ignoring the 5th term of the model that\textquotesingle{}s just the normal residuals} -\CommentTok{\#\# The dispRity object} -\KeywordTok{MCMCglmm.subsets}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ charadriiformes}\OperatorTok{$}\NormalTok{data,} - \DataTypeTok{posteriors =}\NormalTok{ charadriiformes}\OperatorTok{$}\NormalTok{posteriors,} - \DataTypeTok{group =}\NormalTok{ model\_terms)} +\DocumentationTok{\#\# The dispRity object} +\FunctionTok{MCMCglmm.subsets}\NormalTok{(}\AttributeTok{data =}\NormalTok{ charadriiformes}\SpecialCharTok{$}\NormalTok{data,} + \AttributeTok{posteriors =}\NormalTok{ charadriiformes}\SpecialCharTok{$}\NormalTok{posteriors,} + \AttributeTok{group =}\NormalTok{ model\_terms)} \end{Highlighting} \end{Shaded} @@ -5389,13 +5191,13 @@ \subsection{\texorpdfstring{Creating a \texttt{dispRity} object with a \texttt{\ \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# A fancier dispRity object} -\NormalTok{my\_covar \textless{}{-}}\StringTok{ }\KeywordTok{MCMCglmm.subsets}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ charadriiformes}\OperatorTok{$}\NormalTok{data,} - \DataTypeTok{posteriors =}\NormalTok{ charadriiformes}\OperatorTok{$}\NormalTok{posteriors,} - \DataTypeTok{group =}\NormalTok{ model\_terms,} - \DataTypeTok{tree =}\NormalTok{ charadriiformes}\OperatorTok{$}\NormalTok{tree,} - \DataTypeTok{rename.groups =} \KeywordTok{c}\NormalTok{(}\KeywordTok{levels}\NormalTok{(charadriiformes}\OperatorTok{$}\NormalTok{data}\OperatorTok{$}\NormalTok{clade), }\StringTok{"phylogeny"}\NormalTok{))} -\CommentTok{\#\# Note that the group names is contained in the clade column of the charadriiformes dataset as factors} +\DocumentationTok{\#\# A fancier dispRity object} +\NormalTok{my\_covar }\OtherTok{\textless{}{-}} \FunctionTok{MCMCglmm.subsets}\NormalTok{(}\AttributeTok{data =}\NormalTok{ charadriiformes}\SpecialCharTok{$}\NormalTok{data,} + \AttributeTok{posteriors =}\NormalTok{ charadriiformes}\SpecialCharTok{$}\NormalTok{posteriors,} + \AttributeTok{group =}\NormalTok{ model\_terms,} + \AttributeTok{tree =}\NormalTok{ charadriiformes}\SpecialCharTok{$}\NormalTok{tree,} + \AttributeTok{rename.groups =} \FunctionTok{c}\NormalTok{(}\FunctionTok{levels}\NormalTok{(charadriiformes}\SpecialCharTok{$}\NormalTok{data}\SpecialCharTok{$}\NormalTok{clade), }\StringTok{"phylogeny"}\NormalTok{))} +\DocumentationTok{\#\# Note that the group names is contained in the clade column of the charadriiformes dataset as factors} \end{Highlighting} \end{Shaded} @@ -5408,22 +5210,22 @@ \subsection{Visualising covar objects}\label{visualising-covar-objects}} \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =} \KeywordTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{))} -\CommentTok{\#\# The traitspace} -\KeywordTok{covar.plot}\NormalTok{(my\_covar, }\DataTypeTok{col =} \KeywordTok{c}\NormalTok{(}\StringTok{"orange"}\NormalTok{, }\StringTok{"darkgreen"}\NormalTok{, }\StringTok{"blue"}\NormalTok{), }\DataTypeTok{main =} \StringTok{"Trait space"}\NormalTok{)} -\CommentTok{\#\# The traitspace\textquotesingle{}s variance{-}covariance mean ellipses} -\KeywordTok{covar.plot}\NormalTok{(my\_covar, }\DataTypeTok{col =} \KeywordTok{c}\NormalTok{(}\StringTok{"orange"}\NormalTok{, }\StringTok{"darkgreen"}\NormalTok{, }\StringTok{"blue"}\NormalTok{, }\StringTok{"grey"}\NormalTok{), }\DataTypeTok{main =} \StringTok{"Mean VCV ellipses"}\NormalTok{,} - \DataTypeTok{points =} \OtherTok{FALSE}\NormalTok{, }\DataTypeTok{ellipses =}\NormalTok{ mean) } -\CommentTok{\#\# The traitspace\textquotesingle{}s variance{-}covariance mean ellipses} -\KeywordTok{covar.plot}\NormalTok{(my\_covar, }\DataTypeTok{col =} \KeywordTok{c}\NormalTok{(}\StringTok{"orange"}\NormalTok{, }\StringTok{"darkgreen"}\NormalTok{, }\StringTok{"blue"}\NormalTok{, }\StringTok{"grey"}\NormalTok{), }\DataTypeTok{main =} \StringTok{"Mean major axes"}\NormalTok{,} - \DataTypeTok{points =} \OtherTok{FALSE}\NormalTok{, }\DataTypeTok{major.axes =}\NormalTok{ mean)} -\CommentTok{\#\# A bit of everything} -\KeywordTok{covar.plot}\NormalTok{(my\_covar, }\DataTypeTok{col =} \KeywordTok{c}\NormalTok{(}\StringTok{"orange"}\NormalTok{, }\StringTok{"darkgreen"}\NormalTok{, }\StringTok{"blue"}\NormalTok{, }\StringTok{"grey"}\NormalTok{), }\DataTypeTok{main =} \StringTok{"Ten random VCV matrices"}\NormalTok{,} - \DataTypeTok{points =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{major.axes =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{points.cex =} \DecValTok{1}\OperatorTok{/}\DecValTok{3}\NormalTok{, }\DataTypeTok{n =} \DecValTok{10}\NormalTok{, }\DataTypeTok{ellipses =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{legend =} \OtherTok{TRUE}\NormalTok{)} +\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =} \FunctionTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{))} +\DocumentationTok{\#\# The traitspace} +\FunctionTok{covar.plot}\NormalTok{(my\_covar, }\AttributeTok{col =} \FunctionTok{c}\NormalTok{(}\StringTok{"orange"}\NormalTok{, }\StringTok{"darkgreen"}\NormalTok{, }\StringTok{"blue"}\NormalTok{), }\AttributeTok{main =} \StringTok{"Trait space"}\NormalTok{)} +\DocumentationTok{\#\# The traitspace\textquotesingle{}s variance{-}covariance mean ellipses} +\FunctionTok{covar.plot}\NormalTok{(my\_covar, }\AttributeTok{col =} \FunctionTok{c}\NormalTok{(}\StringTok{"orange"}\NormalTok{, }\StringTok{"darkgreen"}\NormalTok{, }\StringTok{"blue"}\NormalTok{, }\StringTok{"grey"}\NormalTok{), }\AttributeTok{main =} \StringTok{"Mean VCV ellipses"}\NormalTok{,} + \AttributeTok{points =} \ConstantTok{FALSE}\NormalTok{, }\AttributeTok{ellipses =}\NormalTok{ mean) } +\DocumentationTok{\#\# The traitspace\textquotesingle{}s variance{-}covariance mean ellipses} +\FunctionTok{covar.plot}\NormalTok{(my\_covar, }\AttributeTok{col =} \FunctionTok{c}\NormalTok{(}\StringTok{"orange"}\NormalTok{, }\StringTok{"darkgreen"}\NormalTok{, }\StringTok{"blue"}\NormalTok{, }\StringTok{"grey"}\NormalTok{), }\AttributeTok{main =} \StringTok{"Mean major axes"}\NormalTok{,} + \AttributeTok{points =} \ConstantTok{FALSE}\NormalTok{, }\AttributeTok{major.axes =}\NormalTok{ mean)} +\DocumentationTok{\#\# A bit of everything} +\FunctionTok{covar.plot}\NormalTok{(my\_covar, }\AttributeTok{col =} \FunctionTok{c}\NormalTok{(}\StringTok{"orange"}\NormalTok{, }\StringTok{"darkgreen"}\NormalTok{, }\StringTok{"blue"}\NormalTok{, }\StringTok{"grey"}\NormalTok{), }\AttributeTok{main =} \StringTok{"Ten random VCV matrices"}\NormalTok{,} + \AttributeTok{points =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{major.axes =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{points.cex =} \DecValTok{1}\SpecialCharTok{/}\DecValTok{3}\NormalTok{, }\AttributeTok{n =} \DecValTok{10}\NormalTok{, }\AttributeTok{ellipses =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{legend =} \ConstantTok{TRUE}\NormalTok{)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-134-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-135-1.pdf} \hypertarget{disparity-analyses-with-a-covar-component}{% \subsection{\texorpdfstring{Disparity analyses with a \texttt{\$covar} component}{Disparity analyses with a \$covar component}}\label{disparity-analyses-with-a-covar-component}} @@ -5433,7 +5235,7 @@ \subsection{\texorpdfstring{Disparity analyses with a \texttt{\$covar} component \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(my\_covar, }\DataTypeTok{metric =}\NormalTok{ variances))} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(my\_covar, }\AttributeTok{metric =}\NormalTok{ variances))} \end{Highlighting} \end{Shaded} @@ -5452,8 +5254,8 @@ \subsection{\texorpdfstring{Disparity analyses with a \texttt{\$covar} component \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The first variance covariance matrix for the "gulls" group} -\NormalTok{my\_covar}\OperatorTok{$}\NormalTok{covar[[}\StringTok{"gulls"}\NormalTok{]][[}\DecValTok{1}\NormalTok{]]} +\DocumentationTok{\#\# The first variance covariance matrix for the "gulls" group} +\NormalTok{my\_covar}\SpecialCharTok{$}\NormalTok{covar[[}\StringTok{"gulls"}\NormalTok{]][[}\DecValTok{1}\NormalTok{]]} \end{Highlighting} \end{Shaded} @@ -5472,8 +5274,8 @@ \subsection{\texorpdfstring{Disparity analyses with a \texttt{\$covar} component \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Using the variances function on a VCV matrix} -\KeywordTok{variances}\NormalTok{(my\_covar}\OperatorTok{$}\NormalTok{covar[[}\StringTok{"gulls"}\NormalTok{]][[}\DecValTok{1}\NormalTok{]]}\OperatorTok{$}\NormalTok{VCV)} +\DocumentationTok{\#\# Using the variances function on a VCV matrix} +\FunctionTok{variances}\NormalTok{(my\_covar}\SpecialCharTok{$}\NormalTok{covar[[}\StringTok{"gulls"}\NormalTok{]][[}\DecValTok{1}\NormalTok{]]}\SpecialCharTok{$}\NormalTok{VCV)} \end{Highlighting} \end{Shaded} @@ -5483,8 +5285,8 @@ \subsection{\texorpdfstring{Disparity analyses with a \texttt{\$covar} component \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The same but using it as a covar metric} -\KeywordTok{as.covar}\NormalTok{(variances)(my\_covar}\OperatorTok{$}\NormalTok{covar[[}\StringTok{"gulls"}\NormalTok{]][[}\DecValTok{1}\NormalTok{]])} +\DocumentationTok{\#\# The same but using it as a covar metric} +\FunctionTok{as.covar}\NormalTok{(variances)(my\_covar}\SpecialCharTok{$}\NormalTok{covar[[}\StringTok{"gulls"}\NormalTok{]][[}\DecValTok{1}\NormalTok{]])} \end{Highlighting} \end{Shaded} @@ -5494,8 +5296,8 @@ \subsection{\texorpdfstring{Disparity analyses with a \texttt{\$covar} component \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The same but applied to the dispRity function} -\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(my\_covar, }\DataTypeTok{metric =} \KeywordTok{as.covar}\NormalTok{(variances)))} +\DocumentationTok{\#\# The same but applied to the dispRity function} +\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(my\_covar, }\AttributeTok{metric =} \FunctionTok{as.covar}\NormalTok{(variances)))} \end{Highlighting} \end{Shaded} @@ -5507,6 +5309,176 @@ \subsection{\texorpdfstring{Disparity analyses with a \texttt{\$covar} component ## 4 phylogeny 359 0.000 0 0 0.006 0.020 \end{verbatim} +\hypertarget{disparity-and-distances}{% +\section{Disparity and distances}\label{disparity-and-distances}} + +There are two ways to use distances in \texttt{dispRity}, either with your input data being directly a distance matrix or with your disparity metric involving some kind of distance calculations. + +\hypertarget{disparity-data-is-a-distance}{% +\subsection{Disparity data is a distance}\label{disparity-data-is-a-distance}} + +If your disparity data is a distance matrix, you can use the option \texttt{dist.data\ =\ TRUE} in \texttt{dispRity} to make sure that all the operations done on your data take into account the fact that your disparity data has distance properties. +For example, if you bootstrap the data, this will automatically bootstrap both rows AND columns (i.e.~so that the bootstrapped matrices are still distances). +This also improves speed on some calculations if you use \protect\hyperlink{disparity-metrics}{disparity metrics} directly implemented in the package by avoiding recalculating distances (the full list can be seen in \texttt{?dispRity.metric} - they are usually the metrics with \texttt{dist} in their name). + +\hypertarget{subsets}{% +\subsubsection{Subsets}\label{subsets}} + +By default, the \texttt{dispRity} package does not treat any matrix as a distance matrix. +It will however try to guess whether your input data is a distance matrix or not. +This means that if you input a distance matrix, you might get a warning letting you know the input matrix might not be treated correctly (e.g.~when bootstrapping or subsetting). +For the functions \texttt{dispRity}, \texttt{custom.subsets} and \texttt{chrono.subsets} you can simply toggle the option \texttt{dist.data\ =\ TRUE} to make sure you treat your input data as a distance matrix throughout your analysis. + +\begin{Shaded} +\begin{Highlighting}[] +\DocumentationTok{\#\# Creating a distance matrix} +\NormalTok{distance\_data }\OtherTok{\textless{}{-}} \FunctionTok{as.matrix}\NormalTok{(}\FunctionTok{dist}\NormalTok{(BeckLee\_mat50))} + +\DocumentationTok{\#\# Measuring the diagonal of the distance matrix} +\FunctionTok{dispRity}\NormalTok{(distance\_data, }\AttributeTok{metric =}\NormalTok{ diag, }\AttributeTok{dist.data =} \ConstantTok{TRUE}\NormalTok{)} +\end{Highlighting} +\end{Shaded} + +\begin{verbatim} +## ---- dispRity object ---- +## 50 elements in one matrix with 50 dimensions. +## Disparity was calculated as: diag. +\end{verbatim} + +If you use a pipeline of any of these functions, you only need to specify it once and the data will be treated as a distance matrix throughout. + +\begin{Shaded} +\begin{Highlighting}[] +\DocumentationTok{\#\# Creating a distance matrix} +\NormalTok{distance\_data }\OtherTok{\textless{}{-}} \FunctionTok{as.matrix}\NormalTok{(}\FunctionTok{dist}\NormalTok{(BeckLee\_mat50))} + +\DocumentationTok{\#\# Creating two subsets specifying that the data is a distance matrix} +\NormalTok{subsets }\OtherTok{\textless{}{-}} \FunctionTok{custom.subsets}\NormalTok{(distance\_data, }\AttributeTok{group =} \FunctionTok{list}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{), }\FunctionTok{c}\NormalTok{(}\DecValTok{6}\SpecialCharTok{:}\DecValTok{10}\NormalTok{)), }\AttributeTok{dist.data =} \ConstantTok{TRUE}\NormalTok{)} +\DocumentationTok{\#\# Measuring disparity treating the data as distance matrices} +\FunctionTok{dispRity}\NormalTok{(subsets, }\AttributeTok{metric =}\NormalTok{ diag)} +\end{Highlighting} +\end{Shaded} + +\begin{verbatim} +## ---- dispRity object ---- +## 2 customised subsets for 50 elements in one matrix with 50 dimensions: +## 1, 2. +## Disparity was calculated as: diag. +\end{verbatim} + +\begin{Shaded} +\begin{Highlighting}[] +\DocumentationTok{\#\# Measuring disparity treating the data as a normal matrix (toggling the option to FALSE)} +\FunctionTok{dispRity}\NormalTok{(subsets, }\AttributeTok{metric =}\NormalTok{ diag, }\AttributeTok{dist.data =} \ConstantTok{FALSE}\NormalTok{)} +\end{Highlighting} +\end{Shaded} + +\begin{verbatim} +## Warning in dispRity(subsets, metric = diag, dist.data = FALSE): data.dist is +## set to FALSE (the data will not be treated as a distance matrix) even though +## subsets contains distance treated data. +\end{verbatim} + +\begin{verbatim} +## ---- dispRity object ---- +## 2 customised subsets for 50 elements in one matrix with 50 dimensions: +## 1, 2. +## Disparity was calculated as: diag. +\end{verbatim} + +\begin{Shaded} +\begin{Highlighting}[] +\DocumentationTok{\#\# Note that a warning appears but the function still runs} +\end{Highlighting} +\end{Shaded} + +\hypertarget{bootstrapping}{% +\subsubsection{Bootstrapping}\label{bootstrapping}} + +The function \texttt{boot.matrix} also can deal with distance matrices by bootstrapping both rows and columns in a linked way (e.g.~if a bootstrap pseudo-replicate draws the values 1, 2, and 5, it will select both columns 1, 2, and 5 and rows 1, 2, and 5 - keeping the distance structure of the data). +You can do that by using the \texttt{boot.by\ =\ "dist"} function that will bootstrap the data in a distance matrix fashion: + +\begin{Shaded} +\begin{Highlighting}[] +\DocumentationTok{\#\# Measuring the diagonal of a bootstrapped matrix} +\FunctionTok{boot.matrix}\NormalTok{(distance\_data, }\AttributeTok{boot.by =} \StringTok{"dist"}\NormalTok{)} +\end{Highlighting} +\end{Shaded} + +\begin{verbatim} +## ---- dispRity object ---- +## 50 elements in one matrix with 50 dimensions. +## Rows and columns were bootstrapped 100 times (method:"full"). +\end{verbatim} + +Similarly to the \texttt{dispRity}, \texttt{custom.subsets} and \texttt{chrono.subsets} function above, the option to treat the input data as a distance matrix is recorded and recycled so there is no need to specify it each time. + +\hypertarget{disparity-metric-is-a-distance}{% +\subsection{Disparity metric is a distance}\label{disparity-metric-is-a-distance}} + +On the other hand if your data is not a distance matrix but you are using a metric that uses some kind of distance calculations, you can use the option \texttt{dist.helper} to greatly speed up calculations. +\texttt{dist.helper} can be either a pre-calculated distance matrix (or a list of distance matrices) or, better yet, a function to calculate distance matrices, like \texttt{stats::dist} or \texttt{vegan::vegdist}. +This option directly stores the distance matrix separately in the RAM and allows the disparity metric to directly access it at every disparity calculation iteration, making it much faster. +Note that if you provide a function for \texttt{dist.helper}, you can also provide any un-ambiguous optional argument to that function, for example \texttt{method\ =\ "euclidean"}. + +If you use a disparity metric implemented in \texttt{dispRity}, the \texttt{dist.helper} option is correctly loaded onto the RAM regardless of the argument you provide (a matrix, a list of matrix or any function to calculate a distance matrix). +On the other hand, if you use your own function for the disparity metric, make sure that \texttt{dist.helper} exactly matches the internal distance calculation function. +For example if you use the already implemented \texttt{pairwise.dist} metric all the following options will be using \texttt{dist.helper} optimally: + +\begin{Shaded} +\begin{Highlighting}[] +\DocumentationTok{\#\# Using the dist function from stats (specifying it comes from stats)} +\FunctionTok{dispRity}\NormalTok{(my\_data, }\AttributeTok{metric =}\NormalTok{ pairwise.dist, }\AttributeTok{dist.helper =}\NormalTok{ stats}\SpecialCharTok{::}\NormalTok{dist)} + +\DocumentationTok{\#\# Using the dist function from vegdist function (without specifying its origin)} +\FunctionTok{dispRity}\NormalTok{(my\_data, }\AttributeTok{metric =}\NormalTok{ pairwise.dist, }\AttributeTok{dist.helper =}\NormalTok{ vegdist)} + +\DocumentationTok{\#\# Using some pre{-}calculated distance with a generic function} +\NormalTok{my\_distance\_matrix }\OtherTok{\textless{}{-}} \FunctionTok{dist}\NormalTok{(my\_distance\_data)} +\FunctionTok{dispRity}\NormalTok{(my\_data, }\AttributeTok{metric =}\NormalTok{ pairwise.dist, }\AttributeTok{dist.helper =}\NormalTok{ my\_distance\_matrix)} + +\DocumentationTok{\#\# Using some pre{-}calculated distance with a user function defined elsewhere} +\NormalTok{my\_distance\_matrix }\OtherTok{\textless{}{-}} \FunctionTok{my.personalised.function}\NormalTok{(my\_distance\_data)} +\FunctionTok{dispRity}\NormalTok{(my\_data, }\AttributeTok{metric =}\NormalTok{ pairwise.dist, }\AttributeTok{dist.helper =}\NormalTok{ my\_distance\_matrix)} +\end{Highlighting} +\end{Shaded} + +However, if you use a homemade metric for calculating distances like this: + +\begin{Shaded} +\begin{Highlighting}[] +\DocumentationTok{\#\# a personalised distance function} +\NormalTok{my.sum.of.dist }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(matrix) \{} + \FunctionTok{return}\NormalTok{(}\FunctionTok{sum}\NormalTok{(}\FunctionTok{dist}\NormalTok{(matrix)))} +\NormalTok{\}} +\end{Highlighting} +\end{Shaded} + +The \texttt{dist.helper} will only work if you specify the function using the same syntax as in the user function: + +\begin{Shaded} +\begin{Highlighting}[] +\DocumentationTok{\#\# The following uses the helper correctly (as in saves a lot of calculation time)} +\FunctionTok{dispRity}\NormalTok{(my\_data, }\AttributeTok{metric =}\NormalTok{ my.sum.of.dist, }\AttributeTok{dist.helper =}\NormalTok{ dist)} + +\DocumentationTok{\#\# These ones however, work but don\textquotesingle{}t use the dist.helper (don\textquotesingle{}t save time)} +\DocumentationTok{\#\# The dist.helper is not a function} +\FunctionTok{dispRity}\NormalTok{(my\_data, }\AttributeTok{metric =}\NormalTok{ my.sum.of.dist, }\AttributeTok{dist.helper =} \FunctionTok{dist}\NormalTok{(my\_data))} +\DocumentationTok{\#\# The dist.helper is not the correct function (should be dist)} +\FunctionTok{dispRity}\NormalTok{(my\_data, }\AttributeTok{metric =}\NormalTok{ my.sum.of.dist, }\AttributeTok{dist.helper =}\NormalTok{ vegdist)} +\DocumentationTok{\#\# The dist.helper is not the correct function (should be just dist)} +\FunctionTok{dispRity}\NormalTok{(my\_data, }\AttributeTok{metric =}\NormalTok{ my.sum.of.dist, }\AttributeTok{dist.helper =}\NormalTok{ stats}\SpecialCharTok{::}\NormalTok{dist)} +\end{Highlighting} +\end{Shaded} + +\begin{Shaded} +\begin{Highlighting}[] + \FunctionTok{expect\_equal}\NormalTok{(}\FunctionTok{summary}\NormalTok{(test)}\SpecialCharTok{$}\NormalTok{obs.median, }\DecValTok{0}\NormalTok{)} +\end{Highlighting} +\end{Shaded} + +--\textgreater{} + \hypertarget{making-stuff-up}{% \chapter{Making stuff up!}\label{making-stuff-up}} @@ -5526,18 +5498,18 @@ \section{Simulating discrete morphological data}\label{simulating-discrete-morph \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{set.seed}\NormalTok{(}\DecValTok{3}\NormalTok{)} -\CommentTok{\#\# Simulating a starting tree with 15 taxa as a random coalescent tree} -\NormalTok{my\_tree \textless{}{-}}\StringTok{ }\KeywordTok{rcoal}\NormalTok{(}\DecValTok{15}\NormalTok{)} +\FunctionTok{set.seed}\NormalTok{(}\DecValTok{3}\NormalTok{)} +\DocumentationTok{\#\# Simulating a starting tree with 15 taxa as a random coalescent tree} +\NormalTok{my\_tree }\OtherTok{\textless{}{-}} \FunctionTok{rcoal}\NormalTok{(}\DecValTok{15}\NormalTok{)} -\CommentTok{\#\# Generating a matrix with 100 characters (85\% binary and 15\% three state) and} -\CommentTok{\#\# an equal rates model with a gamma rate distribution (0.5, 1) with no } -\CommentTok{\#\# invariant characters.} -\NormalTok{my\_matrix \textless{}{-}}\StringTok{ }\KeywordTok{sim.morpho}\NormalTok{(}\DataTypeTok{tree =}\NormalTok{ my\_tree, }\DataTypeTok{characters =} \DecValTok{100}\NormalTok{, }\DataTypeTok{states =} \KeywordTok{c}\NormalTok{(}\FloatTok{0.85}\NormalTok{,} - \FloatTok{0.15}\NormalTok{), }\DataTypeTok{rates =} \KeywordTok{c}\NormalTok{(rgamma, }\FloatTok{0.5}\NormalTok{, }\DecValTok{1}\NormalTok{), }\DataTypeTok{invariant =} \OtherTok{FALSE}\NormalTok{)} +\DocumentationTok{\#\# Generating a matrix with 100 characters (85\% binary and 15\% three state) and} +\DocumentationTok{\#\# an equal rates model with a gamma rate distribution (0.5, 1) with no } +\DocumentationTok{\#\# invariant characters.} +\NormalTok{my\_matrix }\OtherTok{\textless{}{-}} \FunctionTok{sim.morpho}\NormalTok{(}\AttributeTok{tree =}\NormalTok{ my\_tree, }\AttributeTok{characters =} \DecValTok{100}\NormalTok{, }\AttributeTok{states =} \FunctionTok{c}\NormalTok{(}\FloatTok{0.85}\NormalTok{,} + \FloatTok{0.15}\NormalTok{), }\AttributeTok{rates =} \FunctionTok{c}\NormalTok{(rgamma, }\FloatTok{0.5}\NormalTok{, }\DecValTok{1}\NormalTok{), }\AttributeTok{invariant =} \ConstantTok{FALSE}\NormalTok{)} -\CommentTok{\#\# The first few lines of the matrix} -\NormalTok{my\_matrix[}\DecValTok{1}\OperatorTok{:}\DecValTok{5}\NormalTok{, }\DecValTok{1}\OperatorTok{:}\DecValTok{10}\NormalTok{]} +\DocumentationTok{\#\# The first few lines of the matrix} +\NormalTok{my\_matrix[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{, }\DecValTok{1}\SpecialCharTok{:}\DecValTok{10}\NormalTok{]} \end{Highlighting} \end{Shaded} @@ -5552,8 +5524,8 @@ \section{Simulating discrete morphological data}\label{simulating-discrete-morph \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Checking the matrix properties with a quick Maximum Parsimony tree search} -\KeywordTok{check.morpho}\NormalTok{(my\_matrix, my\_tree)} +\DocumentationTok{\#\# Checking the matrix properties with a quick Maximum Parsimony tree search} +\FunctionTok{check.morpho}\NormalTok{(my\_matrix, my\_tree)} \end{Highlighting} \end{Shaded} @@ -5650,13 +5622,13 @@ \subsubsection{Adding inapplicable characters}\label{adding-inapplicable-charact \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Generating 5 "character" NAs and 10 "clade" NAs} -\NormalTok{my\_matrix\_NA \textless{}{-}}\StringTok{ }\KeywordTok{apply.NA}\NormalTok{(my\_matrix, }\DataTypeTok{tree =}\NormalTok{ my\_tree,} - \DataTypeTok{NAs =} \KeywordTok{c}\NormalTok{(}\KeywordTok{rep}\NormalTok{(}\StringTok{"character"}\NormalTok{, }\DecValTok{5}\NormalTok{),} - \KeywordTok{rep}\NormalTok{(}\StringTok{"clade"}\NormalTok{, }\DecValTok{10}\NormalTok{)))} +\DocumentationTok{\#\# Generating 5 "character" NAs and 10 "clade" NAs} +\NormalTok{my\_matrix\_NA }\OtherTok{\textless{}{-}} \FunctionTok{apply.NA}\NormalTok{(my\_matrix, }\AttributeTok{tree =}\NormalTok{ my\_tree,} + \AttributeTok{NAs =} \FunctionTok{c}\NormalTok{(}\FunctionTok{rep}\NormalTok{(}\StringTok{"character"}\NormalTok{, }\DecValTok{5}\NormalTok{),} + \FunctionTok{rep}\NormalTok{(}\StringTok{"clade"}\NormalTok{, }\DecValTok{10}\NormalTok{)))} -\CommentTok{\#\# The first few lines of the resulting matrix} -\NormalTok{my\_matrix\_NA[}\DecValTok{1}\OperatorTok{:}\DecValTok{10}\NormalTok{, }\DecValTok{90}\OperatorTok{:}\DecValTok{100}\NormalTok{]} +\DocumentationTok{\#\# The first few lines of the resulting matrix} +\NormalTok{my\_matrix\_NA[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{10}\NormalTok{, }\DecValTok{90}\SpecialCharTok{:}\DecValTok{100}\NormalTok{]} \end{Highlighting} \end{Shaded} @@ -5682,16 +5654,16 @@ \subsection{Parameters for a realistic(ish) matrix}\label{parameters-for-a-reali \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{set.seed}\NormalTok{(}\DecValTok{0}\NormalTok{)} -\CommentTok{\#\# tree} -\NormalTok{my\_tree \textless{}{-}}\StringTok{ }\KeywordTok{rcoal}\NormalTok{(}\DecValTok{15}\NormalTok{)} -\CommentTok{\#\# matrix} -\NormalTok{morpho\_mat \textless{}{-}}\StringTok{ }\KeywordTok{sim.morpho}\NormalTok{(my\_tree,} - \DataTypeTok{characters =} \DecValTok{100}\NormalTok{,} - \DataTypeTok{model =} \StringTok{"ER"}\NormalTok{,} - \DataTypeTok{rates =} \KeywordTok{c}\NormalTok{(rgamma, }\DataTypeTok{rate =} \DecValTok{100}\NormalTok{, }\DataTypeTok{shape =} \DecValTok{5}\NormalTok{),} - \DataTypeTok{invariant =} \OtherTok{FALSE}\NormalTok{)} -\KeywordTok{check.morpho}\NormalTok{(morpho\_mat, my\_tree)} +\FunctionTok{set.seed}\NormalTok{(}\DecValTok{0}\NormalTok{)} +\DocumentationTok{\#\# tree} +\NormalTok{my\_tree }\OtherTok{\textless{}{-}} \FunctionTok{rcoal}\NormalTok{(}\DecValTok{15}\NormalTok{)} +\DocumentationTok{\#\# matrix} +\NormalTok{morpho\_mat }\OtherTok{\textless{}{-}} \FunctionTok{sim.morpho}\NormalTok{(my\_tree,} + \AttributeTok{characters =} \DecValTok{100}\NormalTok{,} + \AttributeTok{model =} \StringTok{"ER"}\NormalTok{,} + \AttributeTok{rates =} \FunctionTok{c}\NormalTok{(rgamma, }\AttributeTok{rate =} \DecValTok{100}\NormalTok{, }\AttributeTok{shape =} \DecValTok{5}\NormalTok{),} + \AttributeTok{invariant =} \ConstantTok{FALSE}\NormalTok{)} +\FunctionTok{check.morpho}\NormalTok{(morpho\_mat, my\_tree)} \end{Highlighting} \end{Shaded} @@ -5723,14 +5695,14 @@ \section{Simulating multidimensional spaces}\label{simulating-multidimensional-s \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Graphical options} -\NormalTok{op \textless{}{-}}\StringTok{ }\KeywordTok{par}\NormalTok{(}\DataTypeTok{bty =} \StringTok{"n"}\NormalTok{)} +\DocumentationTok{\#\# Graphical options} +\NormalTok{op }\OtherTok{\textless{}{-}} \FunctionTok{par}\NormalTok{(}\AttributeTok{bty =} \StringTok{"n"}\NormalTok{)} -\CommentTok{\#\# A square space} -\NormalTok{square\_space \textless{}{-}}\StringTok{ }\KeywordTok{space.maker}\NormalTok{(}\DecValTok{100}\NormalTok{, }\DecValTok{2}\NormalTok{, runif)} +\DocumentationTok{\#\# A square space} +\NormalTok{square\_space }\OtherTok{\textless{}{-}} \FunctionTok{space.maker}\NormalTok{(}\DecValTok{100}\NormalTok{, }\DecValTok{2}\NormalTok{, runif)} -\CommentTok{\#\# The resulting 2D matrix} -\KeywordTok{head}\NormalTok{(square\_space)} +\DocumentationTok{\#\# The resulting 2D matrix} +\FunctionTok{head}\NormalTok{(square\_space)} \end{Highlighting} \end{Shaded} @@ -5746,25 +5718,25 @@ \section{Simulating multidimensional spaces}\label{simulating-multidimensional-s \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Visualising the space} -\KeywordTok{plot}\NormalTok{(square\_space, }\DataTypeTok{pch =} \DecValTok{20}\NormalTok{, }\DataTypeTok{xlab =} \StringTok{""}\NormalTok{, }\DataTypeTok{ylab =} \StringTok{""}\NormalTok{,} - \DataTypeTok{main =} \StringTok{"Uniform 2D space"}\NormalTok{)} +\DocumentationTok{\#\# Visualising the space} +\FunctionTok{plot}\NormalTok{(square\_space, }\AttributeTok{pch =} \DecValTok{20}\NormalTok{, }\AttributeTok{xlab =} \StringTok{""}\NormalTok{, }\AttributeTok{ylab =} \StringTok{""}\NormalTok{,} + \AttributeTok{main =} \StringTok{"Uniform 2D space"}\NormalTok{)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-141-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-149-1.pdf} Of course, more complex spaces can be created by changing the distributions, their arguments or adding a correlation matrix or a cumulative variance vector: \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# A plane space: uniform with one dimensions equal to 0} -\NormalTok{plane\_space \textless{}{-}}\StringTok{ }\KeywordTok{space.maker}\NormalTok{(}\DecValTok{2500}\NormalTok{, }\DecValTok{3}\NormalTok{, }\KeywordTok{c}\NormalTok{(runif, runif, runif),} - \DataTypeTok{arguments =} \KeywordTok{list}\NormalTok{(}\KeywordTok{list}\NormalTok{(}\DataTypeTok{min =} \DecValTok{0}\NormalTok{, }\DataTypeTok{max =} \DecValTok{0}\NormalTok{),} - \OtherTok{NULL}\NormalTok{, }\OtherTok{NULL}\NormalTok{))} +\DocumentationTok{\#\# A plane space: uniform with one dimensions equal to 0} +\NormalTok{plane\_space }\OtherTok{\textless{}{-}} \FunctionTok{space.maker}\NormalTok{(}\DecValTok{2500}\NormalTok{, }\DecValTok{3}\NormalTok{, }\FunctionTok{c}\NormalTok{(runif, runif, runif),} + \AttributeTok{arguments =} \FunctionTok{list}\NormalTok{(}\FunctionTok{list}\NormalTok{(}\AttributeTok{min =} \DecValTok{0}\NormalTok{, }\AttributeTok{max =} \DecValTok{0}\NormalTok{),} + \ConstantTok{NULL}\NormalTok{, }\ConstantTok{NULL}\NormalTok{))} -\CommentTok{\#\# Correlation matrix for a 3D space} -\NormalTok{(cor\_matrix \textless{}{-}}\StringTok{ }\KeywordTok{matrix}\NormalTok{(}\KeywordTok{cbind}\NormalTok{(}\DecValTok{1}\NormalTok{, }\FloatTok{0.8}\NormalTok{, }\FloatTok{0.2}\NormalTok{, }\FloatTok{0.8}\NormalTok{, }\DecValTok{1}\NormalTok{, }\FloatTok{0.7}\NormalTok{, }\FloatTok{0.2}\NormalTok{, }\FloatTok{0.7}\NormalTok{, }\DecValTok{1}\NormalTok{), }\DataTypeTok{nrow =} \DecValTok{3}\NormalTok{))} +\DocumentationTok{\#\# Correlation matrix for a 3D space} +\NormalTok{(cor\_matrix }\OtherTok{\textless{}{-}} \FunctionTok{matrix}\NormalTok{(}\FunctionTok{cbind}\NormalTok{(}\DecValTok{1}\NormalTok{, }\FloatTok{0.8}\NormalTok{, }\FloatTok{0.2}\NormalTok{, }\FloatTok{0.8}\NormalTok{, }\DecValTok{1}\NormalTok{, }\FloatTok{0.7}\NormalTok{, }\FloatTok{0.2}\NormalTok{, }\FloatTok{0.7}\NormalTok{, }\DecValTok{1}\NormalTok{), }\AttributeTok{nrow =} \DecValTok{3}\NormalTok{))} \end{Highlighting} \end{Shaded} @@ -5777,13 +5749,13 @@ \section{Simulating multidimensional spaces}\label{simulating-multidimensional-s \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# An ellipsoid space (normal space with correlation)} -\NormalTok{ellipse\_space \textless{}{-}}\StringTok{ }\KeywordTok{space.maker}\NormalTok{(}\DecValTok{2500}\NormalTok{, }\DecValTok{3}\NormalTok{, rnorm,} - \DataTypeTok{cor.matrix =}\NormalTok{ cor\_matrix)} +\DocumentationTok{\#\# An ellipsoid space (normal space with correlation)} +\NormalTok{ellipse\_space }\OtherTok{\textless{}{-}} \FunctionTok{space.maker}\NormalTok{(}\DecValTok{2500}\NormalTok{, }\DecValTok{3}\NormalTok{, rnorm,} + \AttributeTok{cor.matrix =}\NormalTok{ cor\_matrix)} -\CommentTok{\#\# A cylindrical space with decreasing axes variance} -\NormalTok{cylindrical\_space \textless{}{-}}\StringTok{ }\KeywordTok{space.maker}\NormalTok{(}\DecValTok{2500}\NormalTok{, }\DecValTok{3}\NormalTok{, }\KeywordTok{c}\NormalTok{(rnorm, rnorm, runif),} - \DataTypeTok{scree =} \KeywordTok{c}\NormalTok{(}\FloatTok{0.7}\NormalTok{, }\FloatTok{0.2}\NormalTok{, }\FloatTok{0.1}\NormalTok{))} +\DocumentationTok{\#\# A cylindrical space with decreasing axes variance} +\NormalTok{cylindrical\_space }\OtherTok{\textless{}{-}} \FunctionTok{space.maker}\NormalTok{(}\DecValTok{2500}\NormalTok{, }\DecValTok{3}\NormalTok{, }\FunctionTok{c}\NormalTok{(rnorm, rnorm, runif),} + \AttributeTok{scree =} \FunctionTok{c}\NormalTok{(}\FloatTok{0.7}\NormalTok{, }\FloatTok{0.2}\NormalTok{, }\FloatTok{0.1}\NormalTok{))} \end{Highlighting} \end{Shaded} @@ -5798,25 +5770,25 @@ \subsection{Personalised dimensions distributions}\label{personalised-dimensions \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Graphical options} -\NormalTok{op \textless{}{-}}\StringTok{ }\KeywordTok{par}\NormalTok{(}\DataTypeTok{bty =} \StringTok{"n"}\NormalTok{)} +\DocumentationTok{\#\# Graphical options} +\NormalTok{op }\OtherTok{\textless{}{-}} \FunctionTok{par}\NormalTok{(}\AttributeTok{bty =} \StringTok{"n"}\NormalTok{)} -\CommentTok{\#\# Generating coordinates for a normal circle with a upper boundary of 1} -\NormalTok{circle \textless{}{-}}\StringTok{ }\KeywordTok{random.circle}\NormalTok{(}\DecValTok{1000}\NormalTok{, rnorm, }\DataTypeTok{inner =} \DecValTok{0}\NormalTok{, }\DataTypeTok{outer =} \DecValTok{1}\NormalTok{)} +\DocumentationTok{\#\# Generating coordinates for a normal circle with a upper boundary of 1} +\NormalTok{circle }\OtherTok{\textless{}{-}} \FunctionTok{random.circle}\NormalTok{(}\DecValTok{1000}\NormalTok{, rnorm, }\AttributeTok{inner =} \DecValTok{0}\NormalTok{, }\AttributeTok{outer =} \DecValTok{1}\NormalTok{)} -\CommentTok{\#\# Plotting the circle} -\KeywordTok{plot}\NormalTok{(circle, }\DataTypeTok{xlab =} \StringTok{"x"}\NormalTok{, }\DataTypeTok{ylab =} \StringTok{"y"}\NormalTok{, }\DataTypeTok{main =} \StringTok{"A normal circle"}\NormalTok{)} +\DocumentationTok{\#\# Plotting the circle} +\FunctionTok{plot}\NormalTok{(circle, }\AttributeTok{xlab =} \StringTok{"x"}\NormalTok{, }\AttributeTok{ylab =} \StringTok{"y"}\NormalTok{, }\AttributeTok{main =} \StringTok{"A normal circle"}\NormalTok{)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-143-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-151-1.pdf} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Creating doughnut space (a spherical space with a hole)} -\NormalTok{doughnut\_space \textless{}{-}}\StringTok{ }\KeywordTok{space.maker}\NormalTok{(}\DecValTok{5000}\NormalTok{, }\DecValTok{3}\NormalTok{, }\KeywordTok{c}\NormalTok{(rnorm, random.circle),} - \DataTypeTok{arguments =} \KeywordTok{list}\NormalTok{(}\KeywordTok{list}\NormalTok{(}\DataTypeTok{mean =} \DecValTok{0}\NormalTok{),} - \KeywordTok{list}\NormalTok{(runif, }\DataTypeTok{inner =} \FloatTok{0.5}\NormalTok{, }\DataTypeTok{outer =} \DecValTok{1}\NormalTok{)))} +\DocumentationTok{\#\# Creating doughnut space (a spherical space with a hole)} +\NormalTok{doughnut\_space }\OtherTok{\textless{}{-}} \FunctionTok{space.maker}\NormalTok{(}\DecValTok{5000}\NormalTok{, }\DecValTok{3}\NormalTok{, }\FunctionTok{c}\NormalTok{(rnorm, random.circle),} + \AttributeTok{arguments =} \FunctionTok{list}\NormalTok{(}\FunctionTok{list}\NormalTok{(}\AttributeTok{mean =} \DecValTok{0}\NormalTok{),} + \FunctionTok{list}\NormalTok{(runif, }\AttributeTok{inner =} \FloatTok{0.5}\NormalTok{, }\AttributeTok{outer =} \DecValTok{1}\NormalTok{)))} \end{Highlighting} \end{Shaded} @@ -5827,10 +5799,10 @@ \subsection{Visualising the space}\label{visualising-the-space}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Graphical options} -\NormalTok{op \textless{}{-}}\StringTok{ }\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =}\NormalTok{ (}\KeywordTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{, }\DecValTok{2}\NormalTok{)), }\DataTypeTok{bty =} \StringTok{"n"}\NormalTok{)} -\CommentTok{\#\# Visualising 3D spaces} -\KeywordTok{require}\NormalTok{(scatterplot3d)} +\DocumentationTok{\#\# Graphical options} +\NormalTok{op }\OtherTok{\textless{}{-}} \FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =}\NormalTok{ (}\FunctionTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{, }\DecValTok{2}\NormalTok{)), }\AttributeTok{bty =} \StringTok{"n"}\NormalTok{)} +\DocumentationTok{\#\# Visualising 3D spaces} +\FunctionTok{require}\NormalTok{(scatterplot3d)} \end{Highlighting} \end{Shaded} @@ -5840,30 +5812,30 @@ \subsection{Visualising the space}\label{visualising-the-space}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The plane space} -\KeywordTok{scatterplot3d}\NormalTok{(plane\_space, }\DataTypeTok{pch =} \DecValTok{20}\NormalTok{, }\DataTypeTok{xlab =} \StringTok{""}\NormalTok{, }\DataTypeTok{ylab =} \StringTok{""}\NormalTok{, }\DataTypeTok{zlab =} \StringTok{""}\NormalTok{,} - \DataTypeTok{xlim =} \KeywordTok{c}\NormalTok{(}\OperatorTok{{-}}\FloatTok{0.5}\NormalTok{, }\FloatTok{0.5}\NormalTok{), }\DataTypeTok{main =} \StringTok{"Plane space"}\NormalTok{)} +\DocumentationTok{\#\# The plane space} +\FunctionTok{scatterplot3d}\NormalTok{(plane\_space, }\AttributeTok{pch =} \DecValTok{20}\NormalTok{, }\AttributeTok{xlab =} \StringTok{""}\NormalTok{, }\AttributeTok{ylab =} \StringTok{""}\NormalTok{, }\AttributeTok{zlab =} \StringTok{""}\NormalTok{,} + \AttributeTok{xlim =} \FunctionTok{c}\NormalTok{(}\SpecialCharTok{{-}}\FloatTok{0.5}\NormalTok{, }\FloatTok{0.5}\NormalTok{), }\AttributeTok{main =} \StringTok{"Plane space"}\NormalTok{)} -\CommentTok{\#\# The ellipsoid space} -\KeywordTok{scatterplot3d}\NormalTok{(ellipse\_space, }\DataTypeTok{pch =} \DecValTok{20}\NormalTok{, }\DataTypeTok{xlab =} \StringTok{""}\NormalTok{, }\DataTypeTok{ylab =} \StringTok{""}\NormalTok{, }\DataTypeTok{zlab =} \StringTok{""}\NormalTok{,} - \DataTypeTok{main =} \StringTok{"Normal ellipsoid space"}\NormalTok{)} +\DocumentationTok{\#\# The ellipsoid space} +\FunctionTok{scatterplot3d}\NormalTok{(ellipse\_space, }\AttributeTok{pch =} \DecValTok{20}\NormalTok{, }\AttributeTok{xlab =} \StringTok{""}\NormalTok{, }\AttributeTok{ylab =} \StringTok{""}\NormalTok{, }\AttributeTok{zlab =} \StringTok{""}\NormalTok{,} + \AttributeTok{main =} \StringTok{"Normal ellipsoid space"}\NormalTok{)} -\CommentTok{\#\# A cylindrical space with a decreasing variance per axis} -\KeywordTok{scatterplot3d}\NormalTok{(cylindrical\_space, }\DataTypeTok{pch =} \DecValTok{20}\NormalTok{, }\DataTypeTok{xlab =} \StringTok{""}\NormalTok{, }\DataTypeTok{ylab =} \StringTok{""}\NormalTok{, }\DataTypeTok{zlab =} \StringTok{""}\NormalTok{,} - \DataTypeTok{main =} \StringTok{"Normal cylindrical space"}\NormalTok{)} -\CommentTok{\#\# Axes have different orders of magnitude} +\DocumentationTok{\#\# A cylindrical space with a decreasing variance per axis} +\FunctionTok{scatterplot3d}\NormalTok{(cylindrical\_space, }\AttributeTok{pch =} \DecValTok{20}\NormalTok{, }\AttributeTok{xlab =} \StringTok{""}\NormalTok{, }\AttributeTok{ylab =} \StringTok{""}\NormalTok{, }\AttributeTok{zlab =} \StringTok{""}\NormalTok{,} + \AttributeTok{main =} \StringTok{"Normal cylindrical space"}\NormalTok{)} +\DocumentationTok{\#\# Axes have different orders of magnitude} -\CommentTok{\#\# Plotting the doughnut space} -\KeywordTok{scatterplot3d}\NormalTok{(doughnut\_space[,}\KeywordTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{1}\NormalTok{,}\DecValTok{3}\NormalTok{)], }\DataTypeTok{pch =} \DecValTok{20}\NormalTok{, }\DataTypeTok{xlab =} \StringTok{""}\NormalTok{, }\DataTypeTok{ylab =} \StringTok{""}\NormalTok{,} - \DataTypeTok{zlab =} \StringTok{""}\NormalTok{, }\DataTypeTok{main =} \StringTok{"Doughnut space"}\NormalTok{)} +\DocumentationTok{\#\# Plotting the doughnut space} +\FunctionTok{scatterplot3d}\NormalTok{(doughnut\_space[,}\FunctionTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{1}\NormalTok{,}\DecValTok{3}\NormalTok{)], }\AttributeTok{pch =} \DecValTok{20}\NormalTok{, }\AttributeTok{xlab =} \StringTok{""}\NormalTok{, }\AttributeTok{ylab =} \StringTok{""}\NormalTok{,} + \AttributeTok{zlab =} \StringTok{""}\NormalTok{, }\AttributeTok{main =} \StringTok{"Doughnut space"}\NormalTok{)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-144-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-152-1.pdf} \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{par}\NormalTok{(op)} +\FunctionTok{par}\NormalTok{(op)} \end{Highlighting} \end{Shaded} @@ -5875,41 +5847,41 @@ \subsection{Generating realistic spaces}\label{generating-realistic-spaces}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Loading the data} -\KeywordTok{data}\NormalTok{(BeckLee\_mat50)} +\DocumentationTok{\#\# Loading the data} +\FunctionTok{data}\NormalTok{(BeckLee\_mat50)} -\CommentTok{\#\# Number of dimensions} -\NormalTok{obs\_dim \textless{}{-}}\StringTok{ }\KeywordTok{ncol}\NormalTok{(BeckLee\_mat50)} +\DocumentationTok{\#\# Number of dimensions} +\NormalTok{obs\_dim }\OtherTok{\textless{}{-}} \FunctionTok{ncol}\NormalTok{(BeckLee\_mat50)} -\CommentTok{\#\# Observed correlation between the dimensions} -\NormalTok{obs\_correlations \textless{}{-}}\StringTok{ }\KeywordTok{cor}\NormalTok{(BeckLee\_mat50)} +\DocumentationTok{\#\# Observed correlation between the dimensions} +\NormalTok{obs\_correlations }\OtherTok{\textless{}{-}} \FunctionTok{cor}\NormalTok{(BeckLee\_mat50)} -\CommentTok{\#\# Observed mean and standard deviation per axis} -\NormalTok{obs\_mu\_sd\_axis \textless{}{-}}\StringTok{ }\KeywordTok{mapply}\NormalTok{(}\ControlFlowTok{function}\NormalTok{(x,y) }\KeywordTok{list}\NormalTok{(}\StringTok{"mean"}\NormalTok{ =}\StringTok{ }\NormalTok{x, }\StringTok{"sd"}\NormalTok{ =}\StringTok{ }\NormalTok{y),} - \KeywordTok{as.list}\NormalTok{(}\KeywordTok{apply}\NormalTok{(BeckLee\_mat50, }\DecValTok{2}\NormalTok{, mean)),} - \KeywordTok{as.list}\NormalTok{(}\KeywordTok{apply}\NormalTok{(BeckLee\_mat50, }\DecValTok{2}\NormalTok{, sd)), }\DataTypeTok{SIMPLIFY =} \OtherTok{FALSE}\NormalTok{)} +\DocumentationTok{\#\# Observed mean and standard deviation per axis} +\NormalTok{obs\_mu\_sd\_axis }\OtherTok{\textless{}{-}} \FunctionTok{mapply}\NormalTok{(}\ControlFlowTok{function}\NormalTok{(x,y) }\FunctionTok{list}\NormalTok{(}\StringTok{"mean"} \OtherTok{=}\NormalTok{ x, }\StringTok{"sd"} \OtherTok{=}\NormalTok{ y),} + \FunctionTok{as.list}\NormalTok{(}\FunctionTok{apply}\NormalTok{(BeckLee\_mat50, }\DecValTok{2}\NormalTok{, mean)),} + \FunctionTok{as.list}\NormalTok{(}\FunctionTok{apply}\NormalTok{(BeckLee\_mat50, }\DecValTok{2}\NormalTok{, sd)), }\AttributeTok{SIMPLIFY =} \ConstantTok{FALSE}\NormalTok{)} -\CommentTok{\#\# Observed overall mean and standard deviation} -\NormalTok{obs\_mu\_sd\_glob \textless{}{-}}\StringTok{ }\KeywordTok{list}\NormalTok{(}\StringTok{"mean"}\NormalTok{ =}\StringTok{ }\KeywordTok{mean}\NormalTok{(BeckLee\_mat50), }\StringTok{"sd"}\NormalTok{ =}\StringTok{ }\KeywordTok{sd}\NormalTok{(BeckLee\_mat50))} +\DocumentationTok{\#\# Observed overall mean and standard deviation} +\NormalTok{obs\_mu\_sd\_glob }\OtherTok{\textless{}{-}} \FunctionTok{list}\NormalTok{(}\StringTok{"mean"} \OtherTok{=} \FunctionTok{mean}\NormalTok{(BeckLee\_mat50), }\StringTok{"sd"} \OtherTok{=} \FunctionTok{sd}\NormalTok{(BeckLee\_mat50))} -\CommentTok{\#\# Scaled observed variance per axis (scree plot)} -\NormalTok{obs\_scree \textless{}{-}}\StringTok{ }\KeywordTok{variances}\NormalTok{(BeckLee\_mat50)}\OperatorTok{/}\KeywordTok{sum}\NormalTok{(}\KeywordTok{variances}\NormalTok{(BeckLee\_mat50))} +\DocumentationTok{\#\# Scaled observed variance per axis (scree plot)} +\NormalTok{obs\_scree }\OtherTok{\textless{}{-}} \FunctionTok{variances}\NormalTok{(BeckLee\_mat50)}\SpecialCharTok{/}\FunctionTok{sum}\NormalTok{(}\FunctionTok{variances}\NormalTok{(BeckLee\_mat50))} -\CommentTok{\#\# Generating our simulated space} -\NormalTok{simulated\_space \textless{}{-}}\StringTok{ }\KeywordTok{space.maker}\NormalTok{(}\DecValTok{1000}\NormalTok{, }\DataTypeTok{dimensions =}\NormalTok{ obs\_dim, } - \DataTypeTok{distribution =} \KeywordTok{rep}\NormalTok{(}\KeywordTok{list}\NormalTok{(rnorm), obs\_dim),} - \DataTypeTok{arguments =}\NormalTok{ obs\_mu\_sd\_axis,} - \DataTypeTok{cor.matrix =}\NormalTok{ obs\_correlations)} +\DocumentationTok{\#\# Generating our simulated space} +\NormalTok{simulated\_space }\OtherTok{\textless{}{-}} \FunctionTok{space.maker}\NormalTok{(}\DecValTok{1000}\NormalTok{, }\AttributeTok{dimensions =}\NormalTok{ obs\_dim, } + \AttributeTok{distribution =} \FunctionTok{rep}\NormalTok{(}\FunctionTok{list}\NormalTok{(rnorm), obs\_dim),} + \AttributeTok{arguments =}\NormalTok{ obs\_mu\_sd\_axis,} + \AttributeTok{cor.matrix =}\NormalTok{ obs\_correlations)} -\CommentTok{\#\# Visualising the fit of our data in the space (in the two first dimensions)} -\KeywordTok{plot}\NormalTok{(simulated\_space[,}\DecValTok{1}\OperatorTok{:}\DecValTok{2}\NormalTok{], }\DataTypeTok{xlab =} \StringTok{"PC1"}\NormalTok{, }\DataTypeTok{ylab =} \StringTok{"PC2"}\NormalTok{)} -\KeywordTok{points}\NormalTok{(BeckLee\_mat50[,}\DecValTok{1}\OperatorTok{:}\DecValTok{2}\NormalTok{], }\DataTypeTok{col =} \StringTok{"red"}\NormalTok{, }\DataTypeTok{pch =} \DecValTok{20}\NormalTok{)} -\KeywordTok{legend}\NormalTok{(}\StringTok{"topleft"}\NormalTok{, }\DataTypeTok{legend =} \KeywordTok{c}\NormalTok{(}\StringTok{"observed"}\NormalTok{, }\StringTok{"simulated"}\NormalTok{),} - \DataTypeTok{pch =} \KeywordTok{c}\NormalTok{(}\DecValTok{20}\NormalTok{,}\DecValTok{21}\NormalTok{), }\DataTypeTok{col =} \KeywordTok{c}\NormalTok{(}\StringTok{"red"}\NormalTok{, }\StringTok{"black"}\NormalTok{))} +\DocumentationTok{\#\# Visualising the fit of our data in the space (in the two first dimensions)} +\FunctionTok{plot}\NormalTok{(simulated\_space[,}\DecValTok{1}\SpecialCharTok{:}\DecValTok{2}\NormalTok{], }\AttributeTok{xlab =} \StringTok{"PC1"}\NormalTok{, }\AttributeTok{ylab =} \StringTok{"PC2"}\NormalTok{)} +\FunctionTok{points}\NormalTok{(BeckLee\_mat50[,}\DecValTok{1}\SpecialCharTok{:}\DecValTok{2}\NormalTok{], }\AttributeTok{col =} \StringTok{"red"}\NormalTok{, }\AttributeTok{pch =} \DecValTok{20}\NormalTok{)} +\FunctionTok{legend}\NormalTok{(}\StringTok{"topleft"}\NormalTok{, }\AttributeTok{legend =} \FunctionTok{c}\NormalTok{(}\StringTok{"observed"}\NormalTok{, }\StringTok{"simulated"}\NormalTok{),} + \AttributeTok{pch =} \FunctionTok{c}\NormalTok{(}\DecValTok{20}\NormalTok{,}\DecValTok{21}\NormalTok{), }\AttributeTok{col =} \FunctionTok{c}\NormalTok{(}\StringTok{"red"}\NormalTok{, }\StringTok{"black"}\NormalTok{))} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-145-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-153-1.pdf} It is now possible to simulate a space using these observed arguments to test several hypothesis: @@ -5923,36 +5895,36 @@ \subsection{Generating realistic spaces}\label{generating-realistic-spaces}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Measuring disparity as the sum of variance} -\NormalTok{observed\_disp \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(BeckLee\_mat50, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(median, centroids))} +\DocumentationTok{\#\# Measuring disparity as the sum of variance} +\NormalTok{observed\_disp }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(BeckLee\_mat50, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(median, centroids))} -\CommentTok{\#\# Is the space uniform?} -\NormalTok{test\_unif \textless{}{-}}\StringTok{ }\KeywordTok{null.test}\NormalTok{(observed\_disp, }\DataTypeTok{null.distrib =}\NormalTok{ runif)} +\DocumentationTok{\#\# Is the space uniform?} +\NormalTok{test\_unif }\OtherTok{\textless{}{-}} \FunctionTok{null.test}\NormalTok{(observed\_disp, }\AttributeTok{null.distrib =}\NormalTok{ runif)} -\CommentTok{\#\# Is the space normal with a mean of 0 and a sd of 1?} -\NormalTok{test\_norm1 \textless{}{-}}\StringTok{ }\KeywordTok{null.test}\NormalTok{(observed\_disp, }\DataTypeTok{null.distrib =}\NormalTok{ rnorm)} +\DocumentationTok{\#\# Is the space normal with a mean of 0 and a sd of 1?} +\NormalTok{test\_norm1 }\OtherTok{\textless{}{-}} \FunctionTok{null.test}\NormalTok{(observed\_disp, }\AttributeTok{null.distrib =}\NormalTok{ rnorm)} -\CommentTok{\#\# Is the space normal with the observed mean and sd and cumulative variance} -\NormalTok{test\_norm2 \textless{}{-}}\StringTok{ }\KeywordTok{null.test}\NormalTok{(observed\_disp, }\DataTypeTok{null.distrib =} \KeywordTok{rep}\NormalTok{(}\KeywordTok{list}\NormalTok{(rnorm), obs\_dim),} - \DataTypeTok{null.args =} \KeywordTok{rep}\NormalTok{(}\KeywordTok{list}\NormalTok{(obs\_mu\_sd\_glob), obs\_dim),} - \DataTypeTok{null.scree =}\NormalTok{ obs\_scree)} +\DocumentationTok{\#\# Is the space normal with the observed mean and sd and cumulative variance} +\NormalTok{test\_norm2 }\OtherTok{\textless{}{-}} \FunctionTok{null.test}\NormalTok{(observed\_disp, }\AttributeTok{null.distrib =} \FunctionTok{rep}\NormalTok{(}\FunctionTok{list}\NormalTok{(rnorm), obs\_dim),} + \AttributeTok{null.args =} \FunctionTok{rep}\NormalTok{(}\FunctionTok{list}\NormalTok{(obs\_mu\_sd\_glob), obs\_dim),} + \AttributeTok{null.scree =}\NormalTok{ obs\_scree)} -\CommentTok{\#\# Is the space multiple normal with multiple means and sds and a correlation?} -\NormalTok{test\_norm3 \textless{}{-}}\StringTok{ }\KeywordTok{null.test}\NormalTok{(observed\_disp, }\DataTypeTok{null.distrib =} \KeywordTok{rep}\NormalTok{(}\KeywordTok{list}\NormalTok{(rnorm), obs\_dim),} - \DataTypeTok{null.args =}\NormalTok{ obs\_mu\_sd\_axis, }\DataTypeTok{null.cor =}\NormalTok{ obs\_correlations)} +\DocumentationTok{\#\# Is the space multiple normal with multiple means and sds and a correlation?} +\NormalTok{test\_norm3 }\OtherTok{\textless{}{-}} \FunctionTok{null.test}\NormalTok{(observed\_disp, }\AttributeTok{null.distrib =} \FunctionTok{rep}\NormalTok{(}\FunctionTok{list}\NormalTok{(rnorm), obs\_dim),} + \AttributeTok{null.args =}\NormalTok{ obs\_mu\_sd\_axis, }\AttributeTok{null.cor =}\NormalTok{ obs\_correlations)} -\CommentTok{\#\# Graphical options} -\NormalTok{op \textless{}{-}}\StringTok{ }\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =}\NormalTok{ (}\KeywordTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{, }\DecValTok{2}\NormalTok{)), }\DataTypeTok{bty =} \StringTok{"n"}\NormalTok{)} -\CommentTok{\#\# Plotting the results} -\KeywordTok{plot}\NormalTok{(test\_unif, }\DataTypeTok{main =} \StringTok{"Uniform (0,1)"}\NormalTok{)} -\KeywordTok{plot}\NormalTok{(test\_norm1, }\DataTypeTok{main =} \StringTok{"Normal (0,1)"}\NormalTok{)} -\KeywordTok{plot}\NormalTok{(test\_norm2, }\DataTypeTok{main =} \KeywordTok{paste0}\NormalTok{(}\StringTok{"Normal ("}\NormalTok{, }\KeywordTok{round}\NormalTok{(obs\_mu\_sd\_glob[[}\DecValTok{1}\NormalTok{]], }\DataTypeTok{digit =} \DecValTok{3}\NormalTok{),} - \StringTok{","}\NormalTok{, }\KeywordTok{round}\NormalTok{(obs\_mu\_sd\_glob[[}\DecValTok{2}\NormalTok{]], }\DataTypeTok{digit =} \DecValTok{3}\NormalTok{), }\StringTok{")"}\NormalTok{))} -\KeywordTok{plot}\NormalTok{(test\_norm3, }\DataTypeTok{main =} \StringTok{"Normal (variable + correlation)"}\NormalTok{)} +\DocumentationTok{\#\# Graphical options} +\NormalTok{op }\OtherTok{\textless{}{-}} \FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =}\NormalTok{ (}\FunctionTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{, }\DecValTok{2}\NormalTok{)), }\AttributeTok{bty =} \StringTok{"n"}\NormalTok{)} +\DocumentationTok{\#\# Plotting the results} +\FunctionTok{plot}\NormalTok{(test\_unif, }\AttributeTok{main =} \StringTok{"Uniform (0,1)"}\NormalTok{)} +\FunctionTok{plot}\NormalTok{(test\_norm1, }\AttributeTok{main =} \StringTok{"Normal (0,1)"}\NormalTok{)} +\FunctionTok{plot}\NormalTok{(test\_norm2, }\AttributeTok{main =} \FunctionTok{paste0}\NormalTok{(}\StringTok{"Normal ("}\NormalTok{, }\FunctionTok{round}\NormalTok{(obs\_mu\_sd\_glob[[}\DecValTok{1}\NormalTok{]], }\AttributeTok{digit =} \DecValTok{3}\NormalTok{),} + \StringTok{","}\NormalTok{, }\FunctionTok{round}\NormalTok{(obs\_mu\_sd\_glob[[}\DecValTok{2}\NormalTok{]], }\AttributeTok{digit =} \DecValTok{3}\NormalTok{), }\StringTok{")"}\NormalTok{))} +\FunctionTok{plot}\NormalTok{(test\_norm3, }\AttributeTok{main =} \StringTok{"Normal (variable + correlation)"}\NormalTok{)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-146-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-154-1.pdf} If we measure disparity as the median distance from the morphospace centroid, we can explain the distribution of the data as normal with the variable observed mean and standard deviation and with a correlation between the dimensions. @@ -5980,9 +5952,9 @@ \section{\texorpdfstring{\texttt{char.diff}}{char.diff}}\label{char.diff}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# A random binary matrix} -\NormalTok{matrix\_binary \textless{}{-}}\StringTok{ }\KeywordTok{matrix}\NormalTok{(}\KeywordTok{sample}\NormalTok{(}\KeywordTok{c}\NormalTok{(}\DecValTok{0}\NormalTok{,}\DecValTok{1}\NormalTok{), }\DecValTok{12}\NormalTok{, }\DataTypeTok{replace =} \OtherTok{TRUE}\NormalTok{), }\DataTypeTok{ncol =} \DecValTok{4}\NormalTok{,} - \DataTypeTok{dimnames =} \KeywordTok{list}\NormalTok{(letters[}\DecValTok{1}\OperatorTok{:}\DecValTok{3}\NormalTok{], LETTERS[}\DecValTok{1}\OperatorTok{:}\DecValTok{4}\NormalTok{]))} +\DocumentationTok{\#\# A random binary matrix} +\NormalTok{matrix\_binary }\OtherTok{\textless{}{-}} \FunctionTok{matrix}\NormalTok{(}\FunctionTok{sample}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\DecValTok{0}\NormalTok{,}\DecValTok{1}\NormalTok{), }\DecValTok{12}\NormalTok{, }\AttributeTok{replace =} \ConstantTok{TRUE}\NormalTok{), }\AttributeTok{ncol =} \DecValTok{4}\NormalTok{,} + \AttributeTok{dimnames =} \FunctionTok{list}\NormalTok{(letters[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{3}\NormalTok{], LETTERS[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{4}\NormalTok{]))} \end{Highlighting} \end{Shaded} @@ -5990,8 +5962,8 @@ \section{\texorpdfstring{\texttt{char.diff}}{char.diff}}\label{char.diff}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The hamming distance between characters} -\NormalTok{(differences \textless{}{-}}\StringTok{ }\KeywordTok{char.diff}\NormalTok{(matrix\_binary))} +\DocumentationTok{\#\# The hamming distance between characters} +\NormalTok{(differences }\OtherTok{\textless{}{-}} \FunctionTok{char.diff}\NormalTok{(matrix\_binary))} \end{Highlighting} \end{Shaded} @@ -6010,12 +5982,12 @@ \section{\texorpdfstring{\texttt{char.diff}}{char.diff}}\label{char.diff}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Visualising the matrix} -\KeywordTok{plot}\NormalTok{(differences)} +\DocumentationTok{\#\# Visualising the matrix} +\FunctionTok{plot}\NormalTok{(differences)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-149-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-157-1.pdf} You can check all the numerous plotting options in the \texttt{?plot.char.diff} manual (it won't be developed here). @@ -6023,8 +5995,8 @@ \section{\texorpdfstring{\texttt{char.diff}}{char.diff}}\label{char.diff}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Euclidean distance between rows} -\KeywordTok{char.diff}\NormalTok{(matrix\_binary, }\DataTypeTok{by.col =} \OtherTok{FALSE}\NormalTok{, }\DataTypeTok{method =} \StringTok{"euclidean"}\NormalTok{)} +\DocumentationTok{\#\# Euclidean distance between rows} +\FunctionTok{char.diff}\NormalTok{(matrix\_binary, }\AttributeTok{by.col =} \ConstantTok{FALSE}\NormalTok{, }\AttributeTok{method =} \StringTok{"euclidean"}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -6042,9 +6014,9 @@ \section{\texorpdfstring{\texttt{char.diff}}{char.diff}}\label{char.diff}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# A random character matrix} -\NormalTok{(matrix\_character \textless{}{-}}\StringTok{ }\KeywordTok{matrix}\NormalTok{(}\KeywordTok{sample}\NormalTok{(}\KeywordTok{c}\NormalTok{(}\StringTok{"0"}\NormalTok{,}\StringTok{"1"}\NormalTok{,}\StringTok{"2"}\NormalTok{), }\DecValTok{30}\NormalTok{, }\DataTypeTok{replace =} \OtherTok{TRUE}\NormalTok{), }\DataTypeTok{ncol =} \DecValTok{5}\NormalTok{,} - \DataTypeTok{dimnames =} \KeywordTok{list}\NormalTok{(letters[}\DecValTok{1}\OperatorTok{:}\DecValTok{6}\NormalTok{], LETTERS[}\DecValTok{1}\OperatorTok{:}\DecValTok{5}\NormalTok{])))} +\DocumentationTok{\#\# A random character matrix} +\NormalTok{(matrix\_character }\OtherTok{\textless{}{-}} \FunctionTok{matrix}\NormalTok{(}\FunctionTok{sample}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\StringTok{"0"}\NormalTok{,}\StringTok{"1"}\NormalTok{,}\StringTok{"2"}\NormalTok{), }\DecValTok{30}\NormalTok{, }\AttributeTok{replace =} \ConstantTok{TRUE}\NormalTok{), }\AttributeTok{ncol =} \DecValTok{5}\NormalTok{,} + \AttributeTok{dimnames =} \FunctionTok{list}\NormalTok{(letters[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{6}\NormalTok{], LETTERS[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{])))} \end{Highlighting} \end{Shaded} @@ -6060,8 +6032,8 @@ \section{\texorpdfstring{\texttt{char.diff}}{char.diff}}\label{char.diff}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The hamming difference between columns} -\KeywordTok{char.diff}\NormalTok{(matrix\_character)} +\DocumentationTok{\#\# The hamming difference between columns} +\FunctionTok{char.diff}\NormalTok{(matrix\_character)} \end{Highlighting} \end{Shaded} @@ -6080,13 +6052,13 @@ \section{\texorpdfstring{\texttt{char.diff}}{char.diff}}\label{char.diff}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Adding uncertain characters} -\NormalTok{matrix\_character[}\KeywordTok{sample}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{30}\NormalTok{, }\DecValTok{8}\NormalTok{)] \textless{}{-}}\StringTok{ "0/1"} +\DocumentationTok{\#\# Adding uncertain characters} +\NormalTok{matrix\_character[}\FunctionTok{sample}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{30}\NormalTok{, }\DecValTok{8}\NormalTok{)] }\OtherTok{\textless{}{-}} \StringTok{"0/1"} -\CommentTok{\#\# Adding missing data} -\NormalTok{matrix\_character[}\KeywordTok{sample}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{30}\NormalTok{, }\DecValTok{5}\NormalTok{)] \textless{}{-}}\StringTok{ "?"} +\DocumentationTok{\#\# Adding missing data} +\NormalTok{matrix\_character[}\FunctionTok{sample}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{30}\NormalTok{, }\DecValTok{5}\NormalTok{)] }\OtherTok{\textless{}{-}} \StringTok{"?"} -\CommentTok{\#\# This is what it looks like now} +\DocumentationTok{\#\# This is what it looks like now} \NormalTok{matrix\_character} \end{Highlighting} \end{Shaded} @@ -6103,8 +6075,8 @@ \section{\texorpdfstring{\texttt{char.diff}}{char.diff}}\label{char.diff}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The hamming difference between columns including the special characters} -\KeywordTok{char.diff}\NormalTok{(matrix\_character)} +\DocumentationTok{\#\# The hamming difference between columns including the special characters} +\FunctionTok{char.diff}\NormalTok{(matrix\_character)} \end{Highlighting} \end{Shaded} @@ -6126,12 +6098,12 @@ \section{\texorpdfstring{\texttt{char.diff}}{char.diff}}\label{char.diff}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Specifying some special behaviours} -\NormalTok{my\_special\_behaviours \textless{}{-}}\StringTok{ }\KeywordTok{list}\NormalTok{(}\DataTypeTok{missing =} \ControlFlowTok{function}\NormalTok{(x,y) }\KeywordTok{return}\NormalTok{(y),} - \DataTypeTok{uncertainty =} \ControlFlowTok{function}\NormalTok{(x,y) }\KeywordTok{return}\NormalTok{(}\KeywordTok{as.integer}\NormalTok{(}\DecValTok{0}\NormalTok{)))} +\DocumentationTok{\#\# Specifying some special behaviours} +\NormalTok{my\_special\_behaviours }\OtherTok{\textless{}{-}} \FunctionTok{list}\NormalTok{(}\AttributeTok{missing =} \ControlFlowTok{function}\NormalTok{(x,y) }\FunctionTok{return}\NormalTok{(y),} + \AttributeTok{uncertainty =} \ControlFlowTok{function}\NormalTok{(x,y) }\FunctionTok{return}\NormalTok{(}\FunctionTok{as.integer}\NormalTok{(}\DecValTok{0}\NormalTok{)))} -\CommentTok{\#\# Passing these special behaviours to the char.diff function} -\KeywordTok{char.diff}\NormalTok{(matrix\_character, }\DataTypeTok{special.behaviour =}\NormalTok{ my\_special\_behaviours)} +\DocumentationTok{\#\# Passing these special behaviours to the char.diff function} +\FunctionTok{char.diff}\NormalTok{(matrix\_character, }\AttributeTok{special.behaviour =}\NormalTok{ my\_special\_behaviours)} \end{Highlighting} \end{Shaded} @@ -6150,13 +6122,13 @@ \section{\texorpdfstring{\texttt{char.diff}}{char.diff}}\label{char.diff}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Adding weird tokens to the matrix} -\NormalTok{matrix\_character[}\KeywordTok{sample}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{30}\NormalTok{, }\DecValTok{8}\NormalTok{)] \textless{}{-}}\StringTok{ "\%"} +\DocumentationTok{\#\# Adding weird tokens to the matrix} +\NormalTok{matrix\_character[}\FunctionTok{sample}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{30}\NormalTok{, }\DecValTok{8}\NormalTok{)] }\OtherTok{\textless{}{-}} \StringTok{"\%"} -\CommentTok{\#\# Specify the new token and the new behaviour} -\KeywordTok{char.diff}\NormalTok{(matrix\_character, }\DataTypeTok{special.tokens =} \KeywordTok{c}\NormalTok{(}\DataTypeTok{weird\_one =} \StringTok{"\%"}\NormalTok{),} - \DataTypeTok{special.behaviours =} \KeywordTok{list}\NormalTok{(} - \DataTypeTok{weird\_one =} \ControlFlowTok{function}\NormalTok{(x,y) }\KeywordTok{return}\NormalTok{(}\KeywordTok{as.integer}\NormalTok{(}\DecValTok{42}\NormalTok{)))} +\DocumentationTok{\#\# Specify the new token and the new behaviour} +\FunctionTok{char.diff}\NormalTok{(matrix\_character, }\AttributeTok{special.tokens =} \FunctionTok{c}\NormalTok{(}\AttributeTok{weird\_one =} \StringTok{"\%"}\NormalTok{),} + \AttributeTok{special.behaviours =} \FunctionTok{list}\NormalTok{(} + \AttributeTok{weird\_one =} \ControlFlowTok{function}\NormalTok{(x,y) }\FunctionTok{return}\NormalTok{(}\FunctionTok{as.integer}\NormalTok{(}\DecValTok{42}\NormalTok{)))} \NormalTok{ )} \end{Highlighting} \end{Shaded} @@ -6182,14 +6154,14 @@ \section{\texorpdfstring{\texttt{clean.data}}{clean.data}}\label{clean.data}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Generating a trees with labels from a to e} -\NormalTok{dummy\_tree \textless{}{-}}\StringTok{ }\KeywordTok{rtree}\NormalTok{(}\DecValTok{5}\NormalTok{, }\DataTypeTok{tip.label =}\NormalTok{ LETTERS[}\DecValTok{1}\OperatorTok{:}\DecValTok{5}\NormalTok{])} +\DocumentationTok{\#\# Generating a trees with labels from a to e} +\NormalTok{dummy\_tree }\OtherTok{\textless{}{-}} \FunctionTok{rtree}\NormalTok{(}\DecValTok{5}\NormalTok{, }\AttributeTok{tip.label =}\NormalTok{ LETTERS[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{])} -\CommentTok{\#\# Generating a matrix with rows from b to f} -\NormalTok{dummy\_data \textless{}{-}}\StringTok{ }\KeywordTok{matrix}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{5}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DataTypeTok{dimnames =} \KeywordTok{list}\NormalTok{(LETTERS[}\DecValTok{2}\OperatorTok{:}\DecValTok{6}\NormalTok{], }\KeywordTok{c}\NormalTok{(}\StringTok{"var1"}\NormalTok{, }\StringTok{"var2"}\NormalTok{)))} +\DocumentationTok{\#\# Generating a matrix with rows from b to f} +\NormalTok{dummy\_data }\OtherTok{\textless{}{-}} \FunctionTok{matrix}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{5}\NormalTok{, }\DecValTok{2}\NormalTok{, }\AttributeTok{dimnames =} \FunctionTok{list}\NormalTok{(LETTERS[}\DecValTok{2}\SpecialCharTok{:}\DecValTok{6}\NormalTok{], }\FunctionTok{c}\NormalTok{(}\StringTok{"var1"}\NormalTok{, }\StringTok{"var2"}\NormalTok{)))} -\CommentTok{\#\#Cleaning the trees and the data} -\NormalTok{(cleaned \textless{}{-}}\StringTok{ }\KeywordTok{clean.data}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ dummy\_data, }\DataTypeTok{tree =}\NormalTok{ dummy\_tree))} +\DocumentationTok{\#\#Cleaning the trees and the data} +\NormalTok{(cleaned }\OtherTok{\textless{}{-}} \FunctionTok{clean.data}\NormalTok{(}\AttributeTok{data =}\NormalTok{ dummy\_data, }\AttributeTok{tree =}\NormalTok{ dummy\_tree))} \end{Highlighting} \end{Shaded} @@ -6224,9 +6196,9 @@ \section{\texorpdfstring{\texttt{crown.stem}}{crown.stem}}\label{crown.stem}} \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{data}\NormalTok{(BeckLee\_tree)} -\CommentTok{\#\# Diving both crow and stem species} -\NormalTok{(}\KeywordTok{crown.stem}\NormalTok{(BeckLee\_tree, }\DataTypeTok{inc.nodes =} \OtherTok{FALSE}\NormalTok{))} +\FunctionTok{data}\NormalTok{(BeckLee\_tree)} +\DocumentationTok{\#\# Diving both crow and stem species} +\NormalTok{(}\FunctionTok{crown.stem}\NormalTok{(BeckLee\_tree, }\AttributeTok{inc.nodes =} \ConstantTok{FALSE}\NormalTok{))} \end{Highlighting} \end{Shaded} @@ -6262,7 +6234,7 @@ \section{\texorpdfstring{\texttt{get.bin.ages}}{get.bin.ages}}\label{get.bin.age \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{get.bin.ages}\NormalTok{(BeckLee\_tree)} +\FunctionTok{get.bin.ages}\NormalTok{(BeckLee\_tree)} \end{Highlighting} \end{Shaded} @@ -6289,17 +6261,17 @@ \section{\texorpdfstring{\texttt{match.tip.edge}}{match.tip.edge}}\label{match.t \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Loading the charadriiformes data} -\KeywordTok{data}\NormalTok{(charadriiformes) } -\CommentTok{\#\# Extracting the tree} -\NormalTok{my\_tree \textless{}{-}}\StringTok{ }\NormalTok{charadriiformes}\OperatorTok{$}\NormalTok{tree} -\CommentTok{\#\# Extracting the data column that contains the clade assignments} -\NormalTok{my\_data \textless{}{-}}\StringTok{ }\NormalTok{charadriiformes}\OperatorTok{$}\NormalTok{data[, }\StringTok{"clade"}\NormalTok{]} -\CommentTok{\#\# Changing the levels names (the clade names) to colours} -\KeywordTok{levels}\NormalTok{(my\_data) \textless{}{-}}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"orange"}\NormalTok{, }\StringTok{"blue"}\NormalTok{, }\StringTok{"darkgreen"}\NormalTok{)} -\NormalTok{my\_data \textless{}{-}}\StringTok{ }\KeywordTok{as.character}\NormalTok{(my\_data)} -\CommentTok{\#\# Matching the data rownames to the tip order in the tree} -\NormalTok{my\_data \textless{}{-}}\StringTok{ }\NormalTok{my\_data[}\KeywordTok{match}\NormalTok{(}\KeywordTok{ladderize}\NormalTok{(my\_tree)}\OperatorTok{$}\NormalTok{tip.label, }\KeywordTok{rownames}\NormalTok{(charadriiformes}\OperatorTok{$}\NormalTok{data))]} +\DocumentationTok{\#\# Loading the charadriiformes data} +\FunctionTok{data}\NormalTok{(charadriiformes) } +\DocumentationTok{\#\# Extracting the tree} +\NormalTok{my\_tree }\OtherTok{\textless{}{-}}\NormalTok{ charadriiformes}\SpecialCharTok{$}\NormalTok{tree} +\DocumentationTok{\#\# Extracting the data column that contains the clade assignments} +\NormalTok{my\_data }\OtherTok{\textless{}{-}}\NormalTok{ charadriiformes}\SpecialCharTok{$}\NormalTok{data[, }\StringTok{"clade"}\NormalTok{]} +\DocumentationTok{\#\# Changing the levels names (the clade names) to colours} +\FunctionTok{levels}\NormalTok{(my\_data) }\OtherTok{\textless{}{-}} \FunctionTok{c}\NormalTok{(}\StringTok{"orange"}\NormalTok{, }\StringTok{"blue"}\NormalTok{, }\StringTok{"darkgreen"}\NormalTok{)} +\NormalTok{my\_data }\OtherTok{\textless{}{-}} \FunctionTok{as.character}\NormalTok{(my\_data)} +\DocumentationTok{\#\# Matching the data rownames to the tip order in the tree} +\NormalTok{my\_data }\OtherTok{\textless{}{-}}\NormalTok{ my\_data[}\FunctionTok{match}\NormalTok{(}\FunctionTok{ladderize}\NormalTok{(my\_tree)}\SpecialCharTok{$}\NormalTok{tip.label, }\FunctionTok{rownames}\NormalTok{(charadriiformes}\SpecialCharTok{$}\NormalTok{data))]} \end{Highlighting} \end{Shaded} @@ -6309,31 +6281,31 @@ \section{\texorpdfstring{\texttt{match.tip.edge}}{match.tip.edge}}\label{match.t \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Matching the tip colours (labels) to their descending edges in the tree} -\CommentTok{\#\# (and making the non{-}match edges grey)} -\NormalTok{clade\_edges \textless{}{-}}\StringTok{ }\KeywordTok{match.tip.edge}\NormalTok{(my\_data, my\_tree, }\DataTypeTok{replace.na =} \StringTok{"grey"}\NormalTok{)} +\DocumentationTok{\#\# Matching the tip colours (labels) to their descending edges in the tree} +\DocumentationTok{\#\# (and making the non{-}match edges grey)} +\NormalTok{clade\_edges }\OtherTok{\textless{}{-}} \FunctionTok{match.tip.edge}\NormalTok{(my\_data, my\_tree, }\AttributeTok{replace.na =} \StringTok{"grey"}\NormalTok{)} -\CommentTok{\#\# Plotting the results} -\KeywordTok{plot}\NormalTok{(}\KeywordTok{ladderize}\NormalTok{(my\_tree), }\DataTypeTok{show.tip.label =} \OtherTok{FALSE}\NormalTok{, }\DataTypeTok{edge.color =}\NormalTok{ clade\_edges)} +\DocumentationTok{\#\# Plotting the results} +\FunctionTok{plot}\NormalTok{(}\FunctionTok{ladderize}\NormalTok{(my\_tree), }\AttributeTok{show.tip.label =} \ConstantTok{FALSE}\NormalTok{, }\AttributeTok{edge.color =}\NormalTok{ clade\_edges)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-159-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-167-1.pdf} But you can also use this option to only select some specific edges and modify them (for example making them all equal to one): \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Adding a fixed edge length to the green clade} -\NormalTok{my\_tree\_modif \textless{}{-}}\StringTok{ }\NormalTok{my\_tree} -\NormalTok{green\_clade \textless{}{-}}\StringTok{ }\KeywordTok{which}\NormalTok{(clade\_edges }\OperatorTok{==}\StringTok{ "darkgreen"}\NormalTok{)} -\NormalTok{my\_tree\_modif}\OperatorTok{$}\NormalTok{edge.length[green\_clade] \textless{}{-}}\StringTok{ }\DecValTok{1} -\KeywordTok{plot}\NormalTok{(}\KeywordTok{ladderize}\NormalTok{(my\_tree\_modif), }\DataTypeTok{show.tip.label =} \OtherTok{FALSE}\NormalTok{,} - \DataTypeTok{edge.color =}\NormalTok{ clade\_edges)} +\DocumentationTok{\#\# Adding a fixed edge length to the green clade} +\NormalTok{my\_tree\_modif }\OtherTok{\textless{}{-}}\NormalTok{ my\_tree} +\NormalTok{green\_clade }\OtherTok{\textless{}{-}} \FunctionTok{which}\NormalTok{(clade\_edges }\SpecialCharTok{==} \StringTok{"darkgreen"}\NormalTok{)} +\NormalTok{my\_tree\_modif}\SpecialCharTok{$}\NormalTok{edge.length[green\_clade] }\OtherTok{\textless{}{-}} \DecValTok{1} +\FunctionTok{plot}\NormalTok{(}\FunctionTok{ladderize}\NormalTok{(my\_tree\_modif), }\AttributeTok{show.tip.label =} \ConstantTok{FALSE}\NormalTok{,} + \AttributeTok{edge.color =}\NormalTok{ clade\_edges)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-160-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-168-1.pdf} \hypertarget{MCMCglmm-utilities}{% \section{\texorpdfstring{\texttt{MCMCglmm} utilities}{MCMCglmm utilities}}\label{MCMCglmm-utilities}} @@ -6344,12 +6316,12 @@ \section{\texorpdfstring{\texttt{MCMCglmm} utilities}{MCMCglmm utilities}}\label \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Loading the charadriiformes data that contains a MCMCglmm object} -\KeywordTok{data}\NormalTok{(charadriiformes)} -\NormalTok{my\_MCMCglmm \textless{}{-}}\StringTok{ }\NormalTok{charadriiformes}\OperatorTok{$}\NormalTok{posteriors} +\DocumentationTok{\#\# Loading the charadriiformes data that contains a MCMCglmm object} +\FunctionTok{data}\NormalTok{(charadriiformes)} +\NormalTok{my\_MCMCglmm }\OtherTok{\textless{}{-}}\NormalTok{ charadriiformes}\SpecialCharTok{$}\NormalTok{posteriors} -\CommentTok{\#\# Which traits where used in this model?} -\KeywordTok{MCMCglmm.traits}\NormalTok{(my\_MCMCglmm)} +\DocumentationTok{\#\# Which traits where used in this model?} +\FunctionTok{MCMCglmm.traits}\NormalTok{(my\_MCMCglmm)} \end{Highlighting} \end{Shaded} @@ -6359,8 +6331,8 @@ \section{\texorpdfstring{\texttt{MCMCglmm} utilities}{MCMCglmm utilities}}\label \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Which levels where used for the model\textquotesingle{}s random terms and/or residuals?} -\KeywordTok{MCMCglmm.levels}\NormalTok{(my\_MCMCglmm)} +\DocumentationTok{\#\# Which levels where used for the model\textquotesingle{}s random terms and/or residuals?} +\FunctionTok{MCMCglmm.levels}\NormalTok{(my\_MCMCglmm)} \end{Highlighting} \end{Shaded} @@ -6373,9 +6345,9 @@ \section{\texorpdfstring{\texttt{MCMCglmm} utilities}{MCMCglmm utilities}}\label \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The level names are converted for clarity but you can get them unconverted} -\CommentTok{\#\# (i.e. as they appear in the model)} -\KeywordTok{MCMCglmm.levels}\NormalTok{(my\_MCMCglmm, }\DataTypeTok{convert =} \OtherTok{FALSE}\NormalTok{)} +\DocumentationTok{\#\# The level names are converted for clarity but you can get them unconverted} +\DocumentationTok{\#\# (i.e. as they appear in the model)} +\FunctionTok{MCMCglmm.levels}\NormalTok{(my\_MCMCglmm, }\AttributeTok{convert =} \ConstantTok{FALSE}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -6390,8 +6362,8 @@ \section{\texorpdfstring{\texttt{MCMCglmm} utilities}{MCMCglmm utilities}}\label \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Sampling 2 random posteriors samples IDs} -\NormalTok{(random\_samples \textless{}{-}}\StringTok{ }\KeywordTok{MCMCglmm.sample}\NormalTok{(my\_MCMCglmm, }\DataTypeTok{n =} \DecValTok{2}\NormalTok{))} +\DocumentationTok{\#\# Sampling 2 random posteriors samples IDs} +\NormalTok{(random\_samples }\OtherTok{\textless{}{-}} \FunctionTok{MCMCglmm.sample}\NormalTok{(my\_MCMCglmm, }\AttributeTok{n =} \DecValTok{2}\NormalTok{))} \end{Highlighting} \end{Shaded} @@ -6401,17 +6373,17 @@ \section{\texorpdfstring{\texttt{MCMCglmm} utilities}{MCMCglmm utilities}}\label \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Extracting these two random samples} -\NormalTok{my\_covars \textless{}{-}}\StringTok{ }\KeywordTok{MCMCglmm.covars}\NormalTok{(my\_MCMCglmm, }\DataTypeTok{sample =}\NormalTok{ random\_samples)} +\DocumentationTok{\#\# Extracting these two random samples} +\NormalTok{my\_covars }\OtherTok{\textless{}{-}} \FunctionTok{MCMCglmm.covars}\NormalTok{(my\_MCMCglmm, }\AttributeTok{sample =}\NormalTok{ random\_samples)} -\CommentTok{\#\# Plotting the variance for each term in the model} -\KeywordTok{boxplot}\NormalTok{(}\KeywordTok{MCMCglmm.variance}\NormalTok{(my\_MCMCglmm), }\DataTypeTok{horizontal =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{las =} \DecValTok{1}\NormalTok{,} - \DataTypeTok{xlab =} \StringTok{"Relative variance"}\NormalTok{,} - \DataTypeTok{main =} \StringTok{"Variance explained by each term"}\NormalTok{)} +\DocumentationTok{\#\# Plotting the variance for each term in the model} +\FunctionTok{boxplot}\NormalTok{(}\FunctionTok{MCMCglmm.variance}\NormalTok{(my\_MCMCglmm), }\AttributeTok{horizontal =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{las =} \DecValTok{1}\NormalTok{,} + \AttributeTok{xlab =} \StringTok{"Relative variance"}\NormalTok{,} + \AttributeTok{main =} \StringTok{"Variance explained by each term"}\NormalTok{)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-161-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-169-1.pdf} See more in the \protect\hyperlink{covar}{\texttt{\$covar} section} on what to do with these \texttt{"MCMCglmm"} objects. @@ -6423,16 +6395,16 @@ \section{\texorpdfstring{\texttt{pair.plot}}{pair.plot}}\label{pair.plot}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Random data} -\NormalTok{data \textless{}{-}}\StringTok{ }\KeywordTok{matrix}\NormalTok{(}\DataTypeTok{data =} \KeywordTok{runif}\NormalTok{(}\DecValTok{42}\NormalTok{), }\DataTypeTok{ncol =} \DecValTok{2}\NormalTok{)} +\DocumentationTok{\#\# Random data} +\NormalTok{data }\OtherTok{\textless{}{-}} \FunctionTok{matrix}\NormalTok{(}\AttributeTok{data =} \FunctionTok{runif}\NormalTok{(}\DecValTok{42}\NormalTok{), }\AttributeTok{ncol =} \DecValTok{2}\NormalTok{)} -\CommentTok{\#\# Plotting the first column as a pairwise comparisons} -\KeywordTok{pair.plot}\NormalTok{(data, }\DataTypeTok{what =} \DecValTok{1}\NormalTok{, }\DataTypeTok{col =} \KeywordTok{c}\NormalTok{(}\StringTok{"orange"}\NormalTok{, }\StringTok{"blue"}\NormalTok{), }\DataTypeTok{legend =} \OtherTok{TRUE}\NormalTok{,} - \DataTypeTok{diag =} \DecValTok{1}\NormalTok{)} +\DocumentationTok{\#\# Plotting the first column as a pairwise comparisons} +\FunctionTok{pair.plot}\NormalTok{(data, }\AttributeTok{what =} \DecValTok{1}\NormalTok{, }\AttributeTok{col =} \FunctionTok{c}\NormalTok{(}\StringTok{"orange"}\NormalTok{, }\StringTok{"blue"}\NormalTok{), }\AttributeTok{legend =} \ConstantTok{TRUE}\NormalTok{,} + \AttributeTok{diag =} \DecValTok{1}\NormalTok{)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-162-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-170-1.pdf} Here blue squares are ones that have a high value and orange ones the ones that have low values. Note that the values plotted correspond the first column of the data as designated by \texttt{what\ =\ 1}. @@ -6441,35 +6413,35 @@ \section{\texorpdfstring{\texttt{pair.plot}}{pair.plot}}\label{pair.plot}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The same plot as before without the diagonal being} -\CommentTok{\#\# the maximal observed value} -\KeywordTok{pair.plot}\NormalTok{(data, }\DataTypeTok{what =} \DecValTok{1}\NormalTok{, }\DataTypeTok{col =} \KeywordTok{c}\NormalTok{(}\StringTok{"orange"}\NormalTok{, }\StringTok{"blue"}\NormalTok{), }\DataTypeTok{legend =} \OtherTok{TRUE}\NormalTok{,} - \DataTypeTok{diag =} \StringTok{"max"}\NormalTok{)} -\CommentTok{\#\# Highlighting with an asterisk which squares have a value} -\CommentTok{\#\# below 0.2} -\KeywordTok{pair.plot}\NormalTok{(data, }\DataTypeTok{what =} \DecValTok{1}\NormalTok{, }\DataTypeTok{binary =} \FloatTok{0.2}\NormalTok{, }\DataTypeTok{add =} \StringTok{"*"}\NormalTok{, }\DataTypeTok{cex =} \DecValTok{2}\NormalTok{)} +\DocumentationTok{\#\# The same plot as before without the diagonal being} +\DocumentationTok{\#\# the maximal observed value} +\FunctionTok{pair.plot}\NormalTok{(data, }\AttributeTok{what =} \DecValTok{1}\NormalTok{, }\AttributeTok{col =} \FunctionTok{c}\NormalTok{(}\StringTok{"orange"}\NormalTok{, }\StringTok{"blue"}\NormalTok{), }\AttributeTok{legend =} \ConstantTok{TRUE}\NormalTok{,} + \AttributeTok{diag =} \StringTok{"max"}\NormalTok{)} +\DocumentationTok{\#\# Highlighting with an asterisk which squares have a value} +\DocumentationTok{\#\# below 0.2} +\FunctionTok{pair.plot}\NormalTok{(data, }\AttributeTok{what =} \DecValTok{1}\NormalTok{, }\AttributeTok{binary =} \FloatTok{0.2}\NormalTok{, }\AttributeTok{add =} \StringTok{"*"}\NormalTok{, }\AttributeTok{cex =} \DecValTok{2}\NormalTok{)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-163-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-171-1.pdf} This function can also be used as a binary display when running a series of pairwise t-tests. For example, the following script runs a wilcoxon test between the time-slices from the \texttt{disparity} example dataset and displays in black which pairs of slices have a p-value below 0.05: \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Loading disparity data} -\KeywordTok{data}\NormalTok{(disparity)} +\DocumentationTok{\#\# Loading disparity data} +\FunctionTok{data}\NormalTok{(disparity)} -\CommentTok{\#\# Testing the pairwise difference between slices} -\NormalTok{tests \textless{}{-}}\StringTok{ }\KeywordTok{test.dispRity}\NormalTok{(disparity, }\DataTypeTok{test =}\NormalTok{ wilcox.test, }\DataTypeTok{correction =} \StringTok{"bonferroni"}\NormalTok{)} +\DocumentationTok{\#\# Testing the pairwise difference between slices} +\NormalTok{tests }\OtherTok{\textless{}{-}} \FunctionTok{test.dispRity}\NormalTok{(disparity, }\AttributeTok{test =}\NormalTok{ wilcox.test, }\AttributeTok{correction =} \StringTok{"bonferroni"}\NormalTok{)} -\CommentTok{\#\# Plotting the significance} -\KeywordTok{pair.plot}\NormalTok{(}\KeywordTok{as.data.frame}\NormalTok{(tests), }\DataTypeTok{what =} \StringTok{"p.value"}\NormalTok{, }\DataTypeTok{binary =} \FloatTok{0.05}\NormalTok{)} +\DocumentationTok{\#\# Plotting the significance} +\FunctionTok{pair.plot}\NormalTok{(}\FunctionTok{as.data.frame}\NormalTok{(tests), }\AttributeTok{what =} \StringTok{"p.value"}\NormalTok{, }\AttributeTok{binary =} \FloatTok{0.05}\NormalTok{)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-164-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-172-1.pdf} \hypertarget{reduce.matrix}{% \section{\texorpdfstring{\texttt{reduce.matrix}}{reduce.matrix}}\label{reduce.matrix}} @@ -6481,28 +6453,28 @@ \section{\texorpdfstring{\texttt{reduce.matrix}}{reduce.matrix}}\label{reduce.ma \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)} -\CommentTok{\#\# A 10*5 matrix} -\NormalTok{na\_matrix \textless{}{-}}\StringTok{ }\KeywordTok{matrix}\NormalTok{(}\KeywordTok{rnorm}\NormalTok{(}\DecValTok{50}\NormalTok{), }\DecValTok{10}\NormalTok{, }\DecValTok{5}\NormalTok{)} -\CommentTok{\#\# Making sure some rows don\textquotesingle{}t overlap} -\NormalTok{na\_matrix[}\DecValTok{1}\NormalTok{, }\DecValTok{1}\OperatorTok{:}\DecValTok{2}\NormalTok{] \textless{}{-}}\StringTok{ }\OtherTok{NA} -\NormalTok{na\_matrix[}\DecValTok{2}\NormalTok{, }\DecValTok{3}\OperatorTok{:}\DecValTok{5}\NormalTok{] \textless{}{-}}\StringTok{ }\OtherTok{NA} -\CommentTok{\#\# Adding 50\% NAs} -\NormalTok{na\_matrix[}\KeywordTok{sample}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{50}\NormalTok{, }\DecValTok{25}\NormalTok{)] \textless{}{-}}\StringTok{ }\OtherTok{NA} -\CommentTok{\#\# Illustrating the gappy matrix} -\KeywordTok{image}\NormalTok{(}\KeywordTok{t}\NormalTok{(na\_matrix), }\DataTypeTok{col =} \StringTok{"black"}\NormalTok{)} +\FunctionTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)} +\DocumentationTok{\#\# A 10*5 matrix} +\NormalTok{na\_matrix }\OtherTok{\textless{}{-}} \FunctionTok{matrix}\NormalTok{(}\FunctionTok{rnorm}\NormalTok{(}\DecValTok{50}\NormalTok{), }\DecValTok{10}\NormalTok{, }\DecValTok{5}\NormalTok{)} +\DocumentationTok{\#\# Making sure some rows don\textquotesingle{}t overlap} +\NormalTok{na\_matrix[}\DecValTok{1}\NormalTok{, }\DecValTok{1}\SpecialCharTok{:}\DecValTok{2}\NormalTok{] }\OtherTok{\textless{}{-}} \ConstantTok{NA} +\NormalTok{na\_matrix[}\DecValTok{2}\NormalTok{, }\DecValTok{3}\SpecialCharTok{:}\DecValTok{5}\NormalTok{] }\OtherTok{\textless{}{-}} \ConstantTok{NA} +\DocumentationTok{\#\# Adding 50\% NAs} +\NormalTok{na\_matrix[}\FunctionTok{sample}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{50}\NormalTok{, }\DecValTok{25}\NormalTok{)] }\OtherTok{\textless{}{-}} \ConstantTok{NA} +\DocumentationTok{\#\# Illustrating the gappy matrix} +\FunctionTok{image}\NormalTok{(}\FunctionTok{t}\NormalTok{(na\_matrix), }\AttributeTok{col =} \StringTok{"black"}\NormalTok{)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-165-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-173-1.pdf} We can use the \texttt{reduce.matrix} to double check whether any rows cannot be compared. The functions needs as an input the type of distance that will be used, say a \texttt{"gower"} distance: \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Reducing the matrix by row} -\NormalTok{(reduction \textless{}{-}}\StringTok{ }\KeywordTok{reduce.matrix}\NormalTok{(na\_matrix, }\DataTypeTok{distance =} \StringTok{"gower"}\NormalTok{))} +\DocumentationTok{\#\# Reducing the matrix by row} +\NormalTok{(reduction }\OtherTok{\textless{}{-}} \FunctionTok{reduce.matrix}\NormalTok{(na\_matrix, }\AttributeTok{distance =} \StringTok{"gower"}\NormalTok{))} \end{Highlighting} \end{Shaded} @@ -6518,12 +6490,12 @@ \section{\texorpdfstring{\texttt{reduce.matrix}}{reduce.matrix}}\label{reduce.ma \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{image}\NormalTok{(}\KeywordTok{t}\NormalTok{(na\_matrix[}\OperatorTok{{-}}\KeywordTok{as.numeric}\NormalTok{(reduction}\OperatorTok{$}\NormalTok{rows.to.remove), ]),} - \DataTypeTok{col =} \StringTok{"black"}\NormalTok{)} +\FunctionTok{image}\NormalTok{(}\FunctionTok{t}\NormalTok{(na\_matrix[}\SpecialCharTok{{-}}\FunctionTok{as.numeric}\NormalTok{(reduction}\SpecialCharTok{$}\NormalTok{rows.to.remove), ]),} + \AttributeTok{col =} \StringTok{"black"}\NormalTok{)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-167-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-175-1.pdf} \hypertarget{select.axes}{% \section{\texorpdfstring{\texttt{select.axes}}{select.axes}}\label{select.axes}} @@ -6535,11 +6507,11 @@ \section{\texorpdfstring{\texttt{select.axes}}{select.axes}}\label{select.axes}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The USArrest example in R} -\NormalTok{ordination \textless{}{-}}\StringTok{ }\KeywordTok{princomp}\NormalTok{(USArrests, }\DataTypeTok{cor =} \OtherTok{TRUE}\NormalTok{)} +\DocumentationTok{\#\# The USArrest example in R} +\NormalTok{ordination }\OtherTok{\textless{}{-}} \FunctionTok{princomp}\NormalTok{(USArrests, }\AttributeTok{cor =} \ConstantTok{TRUE}\NormalTok{)} -\CommentTok{\#\# The loading of each variable} -\KeywordTok{loadings}\NormalTok{(ordination)} +\DocumentationTok{\#\# The loading of each variable} +\FunctionTok{loadings}\NormalTok{(ordination)} \end{Highlighting} \end{Shaded} @@ -6560,11 +6532,11 @@ \section{\texorpdfstring{\texttt{select.axes}}{select.axes}}\label{select.axes}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Or the same operation but manually} -\NormalTok{variances \textless{}{-}}\StringTok{ }\KeywordTok{apply}\NormalTok{(ordination}\OperatorTok{$}\NormalTok{scores, }\DecValTok{2}\NormalTok{, var)} -\NormalTok{scaled\_variances \textless{}{-}}\StringTok{ }\NormalTok{variances}\OperatorTok{/}\KeywordTok{sum}\NormalTok{(variances)} -\NormalTok{sumed\_variances \textless{}{-}}\StringTok{ }\KeywordTok{cumsum}\NormalTok{(scaled\_variances)} -\KeywordTok{round}\NormalTok{(}\KeywordTok{rbind}\NormalTok{(variances, scaled\_variances, sumed\_variances), }\DecValTok{3}\NormalTok{)} +\DocumentationTok{\#\# Or the same operation but manually} +\NormalTok{variances }\OtherTok{\textless{}{-}} \FunctionTok{apply}\NormalTok{(ordination}\SpecialCharTok{$}\NormalTok{scores, }\DecValTok{2}\NormalTok{, var)} +\NormalTok{scaled\_variances }\OtherTok{\textless{}{-}}\NormalTok{ variances}\SpecialCharTok{/}\FunctionTok{sum}\NormalTok{(variances)} +\NormalTok{sumed\_variances }\OtherTok{\textless{}{-}} \FunctionTok{cumsum}\NormalTok{(scaled\_variances)} +\FunctionTok{round}\NormalTok{(}\FunctionTok{rbind}\NormalTok{(variances, scaled\_variances, sumed\_variances), }\DecValTok{3}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -6580,8 +6552,8 @@ \section{\texorpdfstring{\texttt{select.axes}}{select.axes}}\label{select.axes}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Same operation automatised} -\NormalTok{(selected \textless{}{-}}\StringTok{ }\KeywordTok{select.axes}\NormalTok{(ordination))} +\DocumentationTok{\#\# Same operation automatised} +\NormalTok{(selected }\OtherTok{\textless{}{-}} \FunctionTok{select.axes}\NormalTok{(ordination))} \end{Highlighting} \end{Shaded} @@ -6594,8 +6566,8 @@ \section{\texorpdfstring{\texttt{select.axes}}{select.axes}}\label{select.axes}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Summarising this info} -\KeywordTok{summary}\NormalTok{(selected)} +\DocumentationTok{\#\# Summarising this info} +\FunctionTok{summary}\NormalTok{(selected)} \end{Highlighting} \end{Shaded} @@ -6608,18 +6580,18 @@ \section{\texorpdfstring{\texttt{select.axes}}{select.axes}}\label{select.axes}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Plotting it} -\KeywordTok{plot}\NormalTok{(selected)} +\DocumentationTok{\#\# Plotting it} +\FunctionTok{plot}\NormalTok{(selected)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-170-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-178-1.pdf} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Extracting the dimensions} -\CommentTok{\#\# (for the dispRity function for example)} -\NormalTok{selected}\OperatorTok{$}\NormalTok{dimensions} +\DocumentationTok{\#\# Extracting the dimensions} +\DocumentationTok{\#\# (for the dispRity function for example)} +\NormalTok{selected}\SpecialCharTok{$}\NormalTok{dimensions} \end{Highlighting} \end{Shaded} @@ -6637,22 +6609,22 @@ \section{\texorpdfstring{\texttt{select.axes}}{select.axes}}\label{select.axes}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Creating some groups of stats} -\NormalTok{states\_groups \textless{}{-}}\StringTok{ }\KeywordTok{list}\NormalTok{(}\StringTok{"Group1"}\NormalTok{ =}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"Mississippi"}\NormalTok{,}\StringTok{"North Carolina"}\NormalTok{,} +\DocumentationTok{\#\# Creating some groups of stats} +\NormalTok{states\_groups }\OtherTok{\textless{}{-}} \FunctionTok{list}\NormalTok{(}\StringTok{"Group1"} \OtherTok{=} \FunctionTok{c}\NormalTok{(}\StringTok{"Mississippi"}\NormalTok{,}\StringTok{"North Carolina"}\NormalTok{,} \StringTok{"South Carolina"}\NormalTok{, }\StringTok{"Georgia"}\NormalTok{, }\StringTok{"Alabama"}\NormalTok{,} \StringTok{"Alaska"}\NormalTok{, }\StringTok{"Tennessee"}\NormalTok{, }\StringTok{"Louisiana"}\NormalTok{),} - \StringTok{"Group2"}\NormalTok{ =}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"Florida"}\NormalTok{, }\StringTok{"New Mexico"}\NormalTok{, }\StringTok{"Michigan"}\NormalTok{,} + \StringTok{"Group2"} \OtherTok{=} \FunctionTok{c}\NormalTok{(}\StringTok{"Florida"}\NormalTok{, }\StringTok{"New Mexico"}\NormalTok{, }\StringTok{"Michigan"}\NormalTok{,} \StringTok{"Indiana"}\NormalTok{, }\StringTok{"Virginia"}\NormalTok{, }\StringTok{"Wyoming"}\NormalTok{, }\StringTok{"Montana"}\NormalTok{,} \StringTok{"Maine"}\NormalTok{, }\StringTok{"Idaho"}\NormalTok{, }\StringTok{"New Hampshire"}\NormalTok{, }\StringTok{"Iowa"}\NormalTok{),} - \StringTok{"Group3"}\NormalTok{ =}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"Rhode Island"}\NormalTok{, }\StringTok{"New Jersey"}\NormalTok{, }\StringTok{"Hawaii"}\NormalTok{, }\StringTok{"Massachusetts"}\NormalTok{))} -\CommentTok{\#\# Running the same analyses but per groups} -\NormalTok{selected \textless{}{-}}\StringTok{ }\KeywordTok{select.axes}\NormalTok{(ordination, }\DataTypeTok{group =}\NormalTok{ states\_groups, }\DataTypeTok{threshold =} \FloatTok{0.9}\NormalTok{)} -\CommentTok{\#\# Plotting the results} -\KeywordTok{plot}\NormalTok{(selected)} + \StringTok{"Group3"} \OtherTok{=} \FunctionTok{c}\NormalTok{(}\StringTok{"Rhode Island"}\NormalTok{, }\StringTok{"New Jersey"}\NormalTok{, }\StringTok{"Hawaii"}\NormalTok{, }\StringTok{"Massachusetts"}\NormalTok{))} +\DocumentationTok{\#\# Running the same analyses but per groups} +\NormalTok{selected }\OtherTok{\textless{}{-}} \FunctionTok{select.axes}\NormalTok{(ordination, }\AttributeTok{group =}\NormalTok{ states\_groups, }\AttributeTok{threshold =} \FloatTok{0.9}\NormalTok{)} +\DocumentationTok{\#\# Plotting the results} +\FunctionTok{plot}\NormalTok{(selected)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-171-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-179-1.pdf} As you can see here, the whole space requires the three first axes to explain at least 90\% of the variance (in fact, 95\% as seen before). However, different groups have a different story! @@ -6663,10 +6635,10 @@ \section{\texorpdfstring{\texttt{select.axes}}{select.axes}}\label{select.axes}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Loading the dispRity package demo data} -\KeywordTok{data}\NormalTok{(demo\_data)} -\CommentTok{\#\# A dispRity object with two groups} -\NormalTok{demo\_data}\OperatorTok{$}\NormalTok{hopkins} +\DocumentationTok{\#\# Loading the dispRity package demo data} +\FunctionTok{data}\NormalTok{(demo\_data)} +\DocumentationTok{\#\# A dispRity object with two groups} +\NormalTok{demo\_data}\SpecialCharTok{$}\NormalTok{hopkins} \end{Highlighting} \end{Shaded} @@ -6678,18 +6650,18 @@ \section{\texorpdfstring{\texttt{select.axes}}{select.axes}}\label{select.axes}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Selecting axes on a dispRity object} -\NormalTok{selected \textless{}{-}}\StringTok{ }\KeywordTok{select.axes}\NormalTok{(demo\_data}\OperatorTok{$}\NormalTok{hopkins)} -\KeywordTok{plot}\NormalTok{(selected)} +\DocumentationTok{\#\# Selecting axes on a dispRity object} +\NormalTok{selected }\OtherTok{\textless{}{-}} \FunctionTok{select.axes}\NormalTok{(demo\_data}\SpecialCharTok{$}\NormalTok{hopkins)} +\FunctionTok{plot}\NormalTok{(selected)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-172-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-180-1.pdf} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Displaying which axes are necessary for which group} -\NormalTok{selected}\OperatorTok{$}\NormalTok{dim.list} +\DocumentationTok{\#\# Displaying which axes are necessary for which group} +\NormalTok{selected}\SpecialCharTok{$}\NormalTok{dim.list} \end{Highlighting} \end{Shaded} @@ -6706,8 +6678,8 @@ \section{\texorpdfstring{\texttt{select.axes}}{select.axes}}\label{select.axes}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Note how the whole space needs only 16 axes} -\CommentTok{\#\# but both groups need 22 and 23 axes} +\DocumentationTok{\#\# Note how the whole space needs only 16 axes} +\DocumentationTok{\#\# but both groups need 22 and 23 axes} \end{Highlighting} \end{Shaded} @@ -6721,9 +6693,9 @@ \section{\texorpdfstring{\texttt{set.root.time}}{set.root.time}}\label{set.root. \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# A random tree with no root.time} -\NormalTok{my\_tree \textless{}{-}}\StringTok{ }\KeywordTok{rtree}\NormalTok{(}\DecValTok{10}\NormalTok{)} -\NormalTok{my\_tree}\OperatorTok{$}\NormalTok{root.time }\CommentTok{\# is NULL} +\DocumentationTok{\#\# A random tree with no root.time} +\NormalTok{my\_tree }\OtherTok{\textless{}{-}} \FunctionTok{rtree}\NormalTok{(}\DecValTok{10}\NormalTok{)} +\NormalTok{my\_tree}\SpecialCharTok{$}\NormalTok{root.time }\CommentTok{\# is NULL} \end{Highlighting} \end{Shaded} @@ -6735,10 +6707,10 @@ \section{\texorpdfstring{\texttt{set.root.time}}{set.root.time}}\label{set.root. \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Adding an arbitrary root time} -\NormalTok{my\_tree\_arbitrary \textless{}{-}}\StringTok{ }\NormalTok{my\_tree} -\CommentTok{\#\# Setting the age of the root to 42} -\NormalTok{my\_tree\_arbitrary}\OperatorTok{$}\NormalTok{root.time \textless{}{-}}\StringTok{ }\DecValTok{42} +\DocumentationTok{\#\# Adding an arbitrary root time} +\NormalTok{my\_tree\_arbitrary }\OtherTok{\textless{}{-}}\NormalTok{ my\_tree} +\DocumentationTok{\#\# Setting the age of the root to 42} +\NormalTok{my\_tree\_arbitrary}\SpecialCharTok{$}\NormalTok{root.time }\OtherTok{\textless{}{-}} \DecValTok{42} \end{Highlighting} \end{Shaded} @@ -6746,9 +6718,9 @@ \section{\texorpdfstring{\texttt{set.root.time}}{set.root.time}}\label{set.root. \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Calculating the root time from the present} -\NormalTok{my\_tree\_aged \textless{}{-}}\StringTok{ }\NormalTok{my\_tree } -\NormalTok{my\_tree\_aged \textless{}{-}}\StringTok{ }\KeywordTok{set.root.time}\NormalTok{(my\_tree)} +\DocumentationTok{\#\# Calculating the root time from the present} +\NormalTok{my\_tree\_aged }\OtherTok{\textless{}{-}}\NormalTok{ my\_tree } +\NormalTok{my\_tree\_aged }\OtherTok{\textless{}{-}} \FunctionTok{set.root.time}\NormalTok{(my\_tree)} \end{Highlighting} \end{Shaded} @@ -6756,8 +6728,8 @@ \section{\texorpdfstring{\texttt{set.root.time}}{set.root.time}}\label{set.root. \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Caculating the root time from 42 Mya } -\NormalTok{my\_tree\_age \textless{}{-}}\StringTok{ }\KeywordTok{set.root.time}\NormalTok{(my\_tree, }\DataTypeTok{present =} \DecValTok{42}\NormalTok{)} +\DocumentationTok{\#\# Caculating the root time from 42 Mya } +\NormalTok{my\_tree\_age }\OtherTok{\textless{}{-}} \FunctionTok{set.root.time}\NormalTok{(my\_tree, }\AttributeTok{present =} \DecValTok{42}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -6774,27 +6746,27 @@ \section{\texorpdfstring{\texttt{slice.tree}}{slice.tree}}\label{slice.tree}} \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)} -\CommentTok{\#\# Generate a random ultrametric tree} -\NormalTok{tree \textless{}{-}}\StringTok{ }\KeywordTok{rcoal}\NormalTok{(}\DecValTok{20}\NormalTok{)} -\CommentTok{\#\# Add some node labels} -\NormalTok{tree}\OperatorTok{$}\NormalTok{node.label \textless{}{-}}\StringTok{ }\NormalTok{letters[}\DecValTok{1}\OperatorTok{:}\DecValTok{19}\NormalTok{]} -\CommentTok{\#\# Add its root time} -\NormalTok{tree}\OperatorTok{$}\NormalTok{root.time \textless{}{-}}\StringTok{ }\KeywordTok{max}\NormalTok{(}\KeywordTok{tree.age}\NormalTok{(tree)}\OperatorTok{$}\NormalTok{ages)} +\FunctionTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)} +\DocumentationTok{\#\# Generate a random ultrametric tree} +\NormalTok{tree }\OtherTok{\textless{}{-}} \FunctionTok{rcoal}\NormalTok{(}\DecValTok{20}\NormalTok{)} +\DocumentationTok{\#\# Add some node labels} +\NormalTok{tree}\SpecialCharTok{$}\NormalTok{node.label }\OtherTok{\textless{}{-}}\NormalTok{ letters[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{19}\NormalTok{]} +\DocumentationTok{\#\# Add its root time} +\NormalTok{tree}\SpecialCharTok{$}\NormalTok{root.time }\OtherTok{\textless{}{-}} \FunctionTok{max}\NormalTok{(}\FunctionTok{tree.age}\NormalTok{(tree)}\SpecialCharTok{$}\NormalTok{ages)} -\CommentTok{\#\# Slicing the tree at age 0.75} -\NormalTok{tree\_}\DecValTok{75}\NormalTok{ \textless{}{-}}\StringTok{ }\KeywordTok{slice.tree}\NormalTok{(tree, }\DataTypeTok{age =} \FloatTok{0.75}\NormalTok{, }\StringTok{"acctran"}\NormalTok{)} +\DocumentationTok{\#\# Slicing the tree at age 0.75} +\NormalTok{tree\_75 }\OtherTok{\textless{}{-}} \FunctionTok{slice.tree}\NormalTok{(tree, }\AttributeTok{age =} \FloatTok{0.75}\NormalTok{, }\StringTok{"acctran"}\NormalTok{)} -\CommentTok{\#\# Showing both trees} -\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =} \KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{))} -\KeywordTok{plot}\NormalTok{(tree, }\DataTypeTok{main =} \StringTok{"original tree"}\NormalTok{)} -\KeywordTok{axisPhylo}\NormalTok{() ; }\KeywordTok{nodelabels}\NormalTok{(tree}\OperatorTok{$}\NormalTok{node.label, }\DataTypeTok{cex =} \FloatTok{0.8}\NormalTok{)} -\KeywordTok{abline}\NormalTok{(}\DataTypeTok{v =}\NormalTok{ (}\KeywordTok{max}\NormalTok{(}\KeywordTok{tree.age}\NormalTok{(tree)}\OperatorTok{$}\NormalTok{ages) }\OperatorTok{{-}}\StringTok{ }\FloatTok{0.75}\NormalTok{), }\DataTypeTok{col =} \StringTok{"red"}\NormalTok{)} -\KeywordTok{plot}\NormalTok{(tree\_}\DecValTok{75}\NormalTok{, }\DataTypeTok{main =} \StringTok{"sliced tree"}\NormalTok{)} +\DocumentationTok{\#\# Showing both trees} +\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =} \FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{))} +\FunctionTok{plot}\NormalTok{(tree, }\AttributeTok{main =} \StringTok{"original tree"}\NormalTok{)} +\FunctionTok{axisPhylo}\NormalTok{() ; }\FunctionTok{nodelabels}\NormalTok{(tree}\SpecialCharTok{$}\NormalTok{node.label, }\AttributeTok{cex =} \FloatTok{0.8}\NormalTok{)} +\FunctionTok{abline}\NormalTok{(}\AttributeTok{v =}\NormalTok{ (}\FunctionTok{max}\NormalTok{(}\FunctionTok{tree.age}\NormalTok{(tree)}\SpecialCharTok{$}\NormalTok{ages) }\SpecialCharTok{{-}} \FloatTok{0.75}\NormalTok{), }\AttributeTok{col =} \StringTok{"red"}\NormalTok{)} +\FunctionTok{plot}\NormalTok{(tree\_75, }\AttributeTok{main =} \StringTok{"sliced tree"}\NormalTok{)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-177-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-185-1.pdf} \hypertarget{slide.nodes-and-remove.zero.brlen}{% \section{\texorpdfstring{\texttt{slide.nodes} and \texttt{remove.zero.brlen}}{slide.nodes and remove.zero.brlen}}\label{slide.nodes-and-remove.zero.brlen}} @@ -6809,23 +6781,23 @@ \section{\texorpdfstring{\texttt{slide.nodes} and \texttt{remove.zero.brlen}}{sl \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{set.seed}\NormalTok{(}\DecValTok{42}\NormalTok{)} -\CommentTok{\#\# Generating simple coalescent tree} -\NormalTok{tree \textless{}{-}}\StringTok{ }\KeywordTok{rcoal}\NormalTok{(}\DecValTok{5}\NormalTok{)} +\FunctionTok{set.seed}\NormalTok{(}\DecValTok{42}\NormalTok{)} +\DocumentationTok{\#\# Generating simple coalescent tree} +\NormalTok{tree }\OtherTok{\textless{}{-}} \FunctionTok{rcoal}\NormalTok{(}\DecValTok{5}\NormalTok{)} -\CommentTok{\#\# Sliding node 8 up and down} -\NormalTok{tree\_slide\_up \textless{}{-}}\StringTok{ }\KeywordTok{slide.nodes}\NormalTok{(}\DecValTok{8}\NormalTok{, tree, }\DataTypeTok{slide =} \FloatTok{0.075}\NormalTok{)} -\NormalTok{tree\_slide\_down \textless{}{-}}\StringTok{ }\KeywordTok{slide.nodes}\NormalTok{(}\DecValTok{8}\NormalTok{, tree, }\DataTypeTok{slide =} \FloatTok{{-}0.075}\NormalTok{)} +\DocumentationTok{\#\# Sliding node 8 up and down} +\NormalTok{tree\_slide\_up }\OtherTok{\textless{}{-}} \FunctionTok{slide.nodes}\NormalTok{(}\DecValTok{8}\NormalTok{, tree, }\AttributeTok{slide =} \FloatTok{0.075}\NormalTok{)} +\NormalTok{tree\_slide\_down }\OtherTok{\textless{}{-}} \FunctionTok{slide.nodes}\NormalTok{(}\DecValTok{8}\NormalTok{, tree, }\AttributeTok{slide =} \SpecialCharTok{{-}}\FloatTok{0.075}\NormalTok{)} -\CommentTok{\#\# Display the results} -\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =} \KeywordTok{c}\NormalTok{(}\DecValTok{3}\NormalTok{,}\DecValTok{1}\NormalTok{))} -\KeywordTok{plot}\NormalTok{(tree, }\DataTypeTok{main =} \StringTok{"original tree"}\NormalTok{) ; }\KeywordTok{axisPhylo}\NormalTok{() ; }\KeywordTok{nodelabels}\NormalTok{()} -\KeywordTok{plot}\NormalTok{(tree\_slide\_up, }\DataTypeTok{main =} \StringTok{"slide up!"}\NormalTok{) ; }\KeywordTok{axisPhylo}\NormalTok{() ; }\KeywordTok{nodelabels}\NormalTok{()} -\KeywordTok{plot}\NormalTok{(tree\_slide\_down, }\DataTypeTok{main =} \StringTok{"slide down!"}\NormalTok{) ; }\KeywordTok{axisPhylo}\NormalTok{() ; }\KeywordTok{nodelabels}\NormalTok{()} +\DocumentationTok{\#\# Display the results} +\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =} \FunctionTok{c}\NormalTok{(}\DecValTok{3}\NormalTok{,}\DecValTok{1}\NormalTok{))} +\FunctionTok{plot}\NormalTok{(tree, }\AttributeTok{main =} \StringTok{"original tree"}\NormalTok{) ; }\FunctionTok{axisPhylo}\NormalTok{() ; }\FunctionTok{nodelabels}\NormalTok{()} +\FunctionTok{plot}\NormalTok{(tree\_slide\_up, }\AttributeTok{main =} \StringTok{"slide up!"}\NormalTok{) ; }\FunctionTok{axisPhylo}\NormalTok{() ; }\FunctionTok{nodelabels}\NormalTok{()} +\FunctionTok{plot}\NormalTok{(tree\_slide\_down, }\AttributeTok{main =} \StringTok{"slide down!"}\NormalTok{) ; }\FunctionTok{axisPhylo}\NormalTok{() ; }\FunctionTok{nodelabels}\NormalTok{()} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-178-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-186-1.pdf} The \texttt{remove.zero.brlen} is a ``clever'' wrapping function that uses the \texttt{slide.nodes} function to stochastically remove zero branch lengths across a whole tree. This function will slide nodes up or down in successive postorder traversals (i.e.~going down the tree clade by clade) in order to minimise the number of nodes to slide while making sure there are no silly negative branch lengths produced! @@ -6833,21 +6805,21 @@ \section{\texorpdfstring{\texttt{slide.nodes} and \texttt{remove.zero.brlen}}{sl \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{set.seed}\NormalTok{(}\DecValTok{42}\NormalTok{)} -\CommentTok{\#\# Generating a tree} -\NormalTok{tree \textless{}{-}}\StringTok{ }\KeywordTok{rtree}\NormalTok{(}\DecValTok{20}\NormalTok{)} +\FunctionTok{set.seed}\NormalTok{(}\DecValTok{42}\NormalTok{)} +\DocumentationTok{\#\# Generating a tree} +\NormalTok{tree }\OtherTok{\textless{}{-}} \FunctionTok{rtree}\NormalTok{(}\DecValTok{20}\NormalTok{)} -\CommentTok{\#\# Adding some zero branch lengths (5)} -\NormalTok{tree}\OperatorTok{$}\NormalTok{edge.length[}\KeywordTok{sample}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\KeywordTok{Nedge}\NormalTok{(tree), }\DecValTok{5}\NormalTok{)] \textless{}{-}}\StringTok{ }\DecValTok{0} +\DocumentationTok{\#\# Adding some zero branch lengths (5)} +\NormalTok{tree}\SpecialCharTok{$}\NormalTok{edge.length[}\FunctionTok{sample}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\FunctionTok{Nedge}\NormalTok{(tree), }\DecValTok{5}\NormalTok{)] }\OtherTok{\textless{}{-}} \DecValTok{0} -\CommentTok{\#\# And now removing these zero branch lengths!} -\NormalTok{tree\_no\_zero \textless{}{-}}\StringTok{ }\KeywordTok{remove.zero.brlen}\NormalTok{(tree)} +\DocumentationTok{\#\# And now removing these zero branch lengths!} +\NormalTok{tree\_no\_zero }\OtherTok{\textless{}{-}} \FunctionTok{remove.zero.brlen}\NormalTok{(tree)} -\CommentTok{\#\# Exaggerating the removal (to make it visible)} -\NormalTok{tree\_exaggerated \textless{}{-}}\StringTok{ }\KeywordTok{remove.zero.brlen}\NormalTok{(tree, }\DataTypeTok{slide =} \DecValTok{1}\NormalTok{)} +\DocumentationTok{\#\# Exaggerating the removal (to make it visible)} +\NormalTok{tree\_exaggerated }\OtherTok{\textless{}{-}} \FunctionTok{remove.zero.brlen}\NormalTok{(tree, }\AttributeTok{slide =} \DecValTok{1}\NormalTok{)} -\CommentTok{\#\# Check the differences} -\KeywordTok{any}\NormalTok{(tree}\OperatorTok{$}\NormalTok{edge.length }\OperatorTok{==}\StringTok{ }\DecValTok{0}\NormalTok{)} +\DocumentationTok{\#\# Check the differences} +\FunctionTok{any}\NormalTok{(tree}\SpecialCharTok{$}\NormalTok{edge.length }\SpecialCharTok{==} \DecValTok{0}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -6857,7 +6829,7 @@ \section{\texorpdfstring{\texttt{slide.nodes} and \texttt{remove.zero.brlen}}{sl \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{any}\NormalTok{(tree\_no\_zero}\OperatorTok{$}\NormalTok{edge.length }\OperatorTok{==}\StringTok{ }\DecValTok{0}\NormalTok{)} +\FunctionTok{any}\NormalTok{(tree\_no\_zero}\SpecialCharTok{$}\NormalTok{edge.length }\SpecialCharTok{==} \DecValTok{0}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -6867,7 +6839,7 @@ \section{\texorpdfstring{\texttt{slide.nodes} and \texttt{remove.zero.brlen}}{sl \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{any}\NormalTok{(tree\_exaggerated}\OperatorTok{$}\NormalTok{edge.length }\OperatorTok{==}\StringTok{ }\DecValTok{0}\NormalTok{)} +\FunctionTok{any}\NormalTok{(tree\_exaggerated}\SpecialCharTok{$}\NormalTok{edge.length }\SpecialCharTok{==} \DecValTok{0}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -6877,15 +6849,15 @@ \section{\texorpdfstring{\texttt{slide.nodes} and \texttt{remove.zero.brlen}}{sl \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Display the results} -\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =} \KeywordTok{c}\NormalTok{(}\DecValTok{3}\NormalTok{,}\DecValTok{1}\NormalTok{))} -\KeywordTok{plot}\NormalTok{(tree, }\DataTypeTok{main =} \StringTok{"with zero edges"}\NormalTok{)} -\KeywordTok{plot}\NormalTok{(tree\_no\_zero, }\DataTypeTok{main =} \StringTok{"without zero edges!"}\NormalTok{)} -\KeywordTok{plot}\NormalTok{(tree\_exaggerated, }\DataTypeTok{main =} \StringTok{"with longer edges"}\NormalTok{)} +\DocumentationTok{\#\# Display the results} +\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =} \FunctionTok{c}\NormalTok{(}\DecValTok{3}\NormalTok{,}\DecValTok{1}\NormalTok{))} +\FunctionTok{plot}\NormalTok{(tree, }\AttributeTok{main =} \StringTok{"with zero edges"}\NormalTok{)} +\FunctionTok{plot}\NormalTok{(tree\_no\_zero, }\AttributeTok{main =} \StringTok{"without zero edges!"}\NormalTok{)} +\FunctionTok{plot}\NormalTok{(tree\_exaggerated, }\AttributeTok{main =} \StringTok{"with longer edges"}\NormalTok{)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-179-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-187-1.pdf} \hypertarget{tree.age}{% \section{\texorpdfstring{\texttt{tree.age}}{tree.age}}\label{tree.age}} @@ -6894,10 +6866,10 @@ \section{\texorpdfstring{\texttt{tree.age}}{tree.age}}\label{tree.age}} \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)} -\NormalTok{tree \textless{}{-}}\StringTok{ }\KeywordTok{rtree}\NormalTok{(}\DecValTok{10}\NormalTok{)} -\CommentTok{\#\# The tree age from a 10 tip tree} -\KeywordTok{tree.age}\NormalTok{(tree)} +\FunctionTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)} +\NormalTok{tree }\OtherTok{\textless{}{-}} \FunctionTok{rtree}\NormalTok{(}\DecValTok{10}\NormalTok{)} +\DocumentationTok{\#\# The tree age from a 10 tip tree} +\FunctionTok{tree.age}\NormalTok{(tree)} \end{Highlighting} \end{Shaded} @@ -6928,8 +6900,8 @@ \section{\texorpdfstring{\texttt{tree.age}}{tree.age}}\label{tree.age}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The ages starting from {-}100 units} -\KeywordTok{tree.age}\NormalTok{(tree, }\DataTypeTok{age =} \DecValTok{100}\NormalTok{)} +\DocumentationTok{\#\# The ages starting from {-}100 units} +\FunctionTok{tree.age}\NormalTok{(tree, }\AttributeTok{age =} \DecValTok{100}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -6960,8 +6932,8 @@ \section{\texorpdfstring{\texttt{tree.age}}{tree.age}}\label{tree.age}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The ages in terms of tip/node height} -\KeywordTok{tree.age}\NormalTok{(tree, }\DataTypeTok{order =} \StringTok{"present"}\NormalTok{)} +\DocumentationTok{\#\# The ages in terms of tip/node height} +\FunctionTok{tree.age}\NormalTok{(tree, }\AttributeTok{order =} \StringTok{"present"}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -7005,19 +6977,19 @@ \subsection{Using different character tokens in different situations}\label{usin \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{set.seed}\NormalTok{(}\DecValTok{42}\NormalTok{)} -\CommentTok{\#\# A random tree with 10 tips} -\NormalTok{tree \textless{}{-}}\StringTok{ }\KeywordTok{rcoal}\NormalTok{(}\DecValTok{10}\NormalTok{)} -\CommentTok{\#\# Setting up the parameters} -\NormalTok{my\_rates =}\StringTok{ }\KeywordTok{c}\NormalTok{(rgamma, }\DataTypeTok{rate =} \DecValTok{10}\NormalTok{, }\DataTypeTok{shape =} \DecValTok{5}\NormalTok{)} +\FunctionTok{set.seed}\NormalTok{(}\DecValTok{42}\NormalTok{)} +\DocumentationTok{\#\# A random tree with 10 tips} +\NormalTok{tree }\OtherTok{\textless{}{-}} \FunctionTok{rcoal}\NormalTok{(}\DecValTok{10}\NormalTok{)} +\DocumentationTok{\#\# Setting up the parameters} +\NormalTok{my\_rates }\OtherTok{=} \FunctionTok{c}\NormalTok{(rgamma, }\AttributeTok{rate =} \DecValTok{10}\NormalTok{, }\AttributeTok{shape =} \DecValTok{5}\NormalTok{)} -\CommentTok{\#\# Generating a bunch of trees} -\NormalTok{multiple\_trees \textless{}{-}}\StringTok{ }\KeywordTok{rmtree}\NormalTok{(}\DecValTok{5}\NormalTok{, }\DecValTok{10}\NormalTok{)} +\DocumentationTok{\#\# Generating a bunch of trees} +\NormalTok{multiple\_trees }\OtherTok{\textless{}{-}} \FunctionTok{rmtree}\NormalTok{(}\DecValTok{5}\NormalTok{, }\DecValTok{10}\NormalTok{)} -\CommentTok{\#\# A random Mk matrix (10*50)} -\NormalTok{matrix\_simple \textless{}{-}}\StringTok{ }\KeywordTok{sim.morpho}\NormalTok{(tree, }\DataTypeTok{characters =} \DecValTok{50}\NormalTok{, }\DataTypeTok{model =} \StringTok{"ER"}\NormalTok{, }\DataTypeTok{rates =}\NormalTok{ my\_rates,} - \DataTypeTok{invariant =} \OtherTok{FALSE}\NormalTok{)} -\NormalTok{matrix\_simple[}\DecValTok{1}\OperatorTok{:}\DecValTok{10}\NormalTok{, }\DecValTok{1}\OperatorTok{:}\DecValTok{10}\NormalTok{]} +\DocumentationTok{\#\# A random Mk matrix (10*50)} +\NormalTok{matrix\_simple }\OtherTok{\textless{}{-}} \FunctionTok{sim.morpho}\NormalTok{(tree, }\AttributeTok{characters =} \DecValTok{50}\NormalTok{, }\AttributeTok{model =} \StringTok{"ER"}\NormalTok{, }\AttributeTok{rates =}\NormalTok{ my\_rates,} + \AttributeTok{invariant =} \ConstantTok{FALSE}\NormalTok{)} +\NormalTok{matrix\_simple[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{10}\NormalTok{, }\DecValTok{1}\SpecialCharTok{:}\DecValTok{10}\NormalTok{]} \end{Highlighting} \end{Shaded} @@ -7041,15 +7013,15 @@ \subsection{Using different character tokens in different situations}\label{usin \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Modify the matrix to contain missing and special data} -\NormalTok{matrix\_complex \textless{}{-}}\StringTok{ }\NormalTok{matrix\_simple} -\CommentTok{\#\# Adding 50 random "{-}" tokens} -\NormalTok{matrix\_complex[}\KeywordTok{sample}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\KeywordTok{length}\NormalTok{(matrix\_complex), }\DecValTok{50}\NormalTok{)] \textless{}{-}}\StringTok{ "{-}"} -\CommentTok{\#\# Adding 50 random "?" tokens} -\NormalTok{matrix\_complex[}\KeywordTok{sample}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\KeywordTok{length}\NormalTok{(matrix\_complex), }\DecValTok{50}\NormalTok{)] \textless{}{-}}\StringTok{ "?"} -\CommentTok{\#\# Adding 50 random "0\%2" tokens} -\NormalTok{matrix\_complex[}\KeywordTok{sample}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\KeywordTok{length}\NormalTok{(matrix\_complex), }\DecValTok{50}\NormalTok{)] \textless{}{-}}\StringTok{ "0\%2"} -\NormalTok{matrix\_complex[}\DecValTok{1}\OperatorTok{:}\DecValTok{10}\NormalTok{,}\DecValTok{1}\OperatorTok{:}\DecValTok{10}\NormalTok{]} +\DocumentationTok{\#\# Modify the matrix to contain missing and special data} +\NormalTok{matrix\_complex }\OtherTok{\textless{}{-}}\NormalTok{ matrix\_simple} +\DocumentationTok{\#\# Adding 50 random "{-}" tokens} +\NormalTok{matrix\_complex[}\FunctionTok{sample}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\FunctionTok{length}\NormalTok{(matrix\_complex), }\DecValTok{50}\NormalTok{)] }\OtherTok{\textless{}{-}} \StringTok{"{-}"} +\DocumentationTok{\#\# Adding 50 random "?" tokens} +\NormalTok{matrix\_complex[}\FunctionTok{sample}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\FunctionTok{length}\NormalTok{(matrix\_complex), }\DecValTok{50}\NormalTok{)] }\OtherTok{\textless{}{-}} \StringTok{"?"} +\DocumentationTok{\#\# Adding 50 random "0\%2" tokens} +\NormalTok{matrix\_complex[}\FunctionTok{sample}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\FunctionTok{length}\NormalTok{(matrix\_complex), }\DecValTok{50}\NormalTok{)] }\OtherTok{\textless{}{-}} \StringTok{"0\%2"} +\NormalTok{matrix\_complex[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{10}\NormalTok{,}\DecValTok{1}\SpecialCharTok{:}\DecValTok{10}\NormalTok{]} \end{Highlighting} \end{Shaded} @@ -7078,12 +7050,12 @@ \subsection{Using different character tokens in different situations}\label{usin \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The specific token for the missing cases (note the "\textbackslash{}\textbackslash{}" for protecting the value)} -\NormalTok{special.tokens \textless{}{-}}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"missing"}\NormalTok{ =}\StringTok{ "}\CharTok{\textbackslash{}\textbackslash{}}\StringTok{?"}\NormalTok{)} +\DocumentationTok{\#\# The specific token for the missing cases (note the "\textbackslash{}\textbackslash{}" for protecting the value)} +\NormalTok{special.tokens }\OtherTok{\textless{}{-}} \FunctionTok{c}\NormalTok{(}\StringTok{"missing"} \OtherTok{=} \StringTok{"}\SpecialCharTok{\textbackslash{}\textbackslash{}}\StringTok{?"}\NormalTok{)} -\CommentTok{\#\# The behaviour for the missing cases (?)} -\NormalTok{special.behaviour \textless{}{-}}\StringTok{ }\KeywordTok{list}\NormalTok{(missing \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(x, y) }\KeywordTok{return}\NormalTok{(y))} -\CommentTok{\#\# Where x is the input value (here "?") and y is all the possible normal values for the character} +\DocumentationTok{\#\# The behaviour for the missing cases (?)} +\NormalTok{special.behaviour }\OtherTok{\textless{}{-}} \FunctionTok{list}\NormalTok{(missing }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(x, y) }\FunctionTok{return}\NormalTok{(y))} +\DocumentationTok{\#\# Where x is the input value (here "?") and y is all the possible normal values for the character} \end{Highlighting} \end{Shaded} @@ -7093,12 +7065,12 @@ \subsection{Using different character tokens in different situations}\label{usin \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Set a list of extra special tokens} -\NormalTok{my\_spec\_tokens \textless{}{-}}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"weirdtoken"}\NormalTok{ =}\StringTok{ "}\CharTok{\textbackslash{}\textbackslash{}}\StringTok{\%"}\NormalTok{)} +\DocumentationTok{\#\# Set a list of extra special tokens} +\NormalTok{my\_spec\_tokens }\OtherTok{\textless{}{-}} \FunctionTok{c}\NormalTok{(}\StringTok{"weirdtoken"} \OtherTok{=} \StringTok{"}\SpecialCharTok{\textbackslash{}\textbackslash{}}\StringTok{\%"}\NormalTok{)} -\CommentTok{\#\# Weird tokens are considered as state 0 and 3} -\NormalTok{my\_spec\_behaviours \textless{}{-}}\StringTok{ }\KeywordTok{list}\NormalTok{()} -\NormalTok{my\_spec\_behaviours}\OperatorTok{$}\NormalTok{weirdtoken \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(x,y) }\KeywordTok{return}\NormalTok{(}\KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{))} +\DocumentationTok{\#\# Weird tokens are considered as state 0 and 3} +\NormalTok{my\_spec\_behaviours }\OtherTok{\textless{}{-}} \FunctionTok{list}\NormalTok{()} +\NormalTok{my\_spec\_behaviours}\SpecialCharTok{$}\NormalTok{weirdtoken }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(x,y) }\FunctionTok{return}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{))} \end{Highlighting} \end{Shaded} @@ -7106,14 +7078,14 @@ \subsection{Using different character tokens in different situations}\label{usin \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The token for missing values:} -\NormalTok{default\_tokens \textless{}{-}}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"missing"}\NormalTok{ =}\StringTok{ "}\CharTok{\textbackslash{}\textbackslash{}}\StringTok{?"}\NormalTok{,} -\CommentTok{\#\# The token for inapplicable values: } - \StringTok{"inapplicable"}\NormalTok{ =}\StringTok{ "}\CharTok{\textbackslash{}\textbackslash{}}\StringTok{{-}"}\NormalTok{,} -\CommentTok{\#\# The token for polymorphisms:} - \StringTok{"polymorphism"}\NormalTok{ =}\StringTok{ "}\CharTok{\textbackslash{}\textbackslash{}}\StringTok{\&"}\NormalTok{,} -\CommentTok{\#\# The token for uncertainties:} - \StringTok{"uncertanity"}\NormalTok{ =}\StringTok{ "}\CharTok{\textbackslash{}\textbackslash{}}\StringTok{/"}\NormalTok{)} +\DocumentationTok{\#\# The token for missing values:} +\NormalTok{default\_tokens }\OtherTok{\textless{}{-}} \FunctionTok{c}\NormalTok{(}\StringTok{"missing"} \OtherTok{=} \StringTok{"}\SpecialCharTok{\textbackslash{}\textbackslash{}}\StringTok{?"}\NormalTok{,} +\DocumentationTok{\#\# The token for inapplicable values: } + \StringTok{"inapplicable"} \OtherTok{=} \StringTok{"}\SpecialCharTok{\textbackslash{}\textbackslash{}}\StringTok{{-}"}\NormalTok{,} +\DocumentationTok{\#\# The token for polymorphisms:} + \StringTok{"polymorphism"} \OtherTok{=} \StringTok{"}\SpecialCharTok{\textbackslash{}\textbackslash{}}\StringTok{\&"}\NormalTok{,} +\DocumentationTok{\#\# The token for uncertainties:} + \StringTok{"uncertanity"} \OtherTok{=} \StringTok{"}\SpecialCharTok{\textbackslash{}\textbackslash{}}\StringTok{/"}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -7121,14 +7093,14 @@ \subsection{Using different character tokens in different situations}\label{usin \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Treating missing data as all data values} -\NormalTok{default\_behaviour \textless{}{-}}\StringTok{ }\KeywordTok{list}\NormalTok{(missing \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(x,y) y,} -\CommentTok{\#\# Treating inapplicable data as all data values (like missing) } -\NormalTok{ inapplicable \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(x, y) y,} -\CommentTok{\#\# Treating polymorphisms as all values present:} -\NormalTok{ polymorphism \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(x,y) }\KeywordTok{strsplit}\NormalTok{(x, }\DataTypeTok{split =} \StringTok{"}\CharTok{\textbackslash{}\textbackslash{}}\StringTok{\&"}\NormalTok{)[[}\DecValTok{1}\NormalTok{]],} -\CommentTok{\#\# Treating uncertainties as all values present (like polymorphisms):} -\NormalTok{ uncertanity \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(x,y) }\KeywordTok{strsplit}\NormalTok{(x, }\DataTypeTok{split =} \StringTok{"}\CharTok{\textbackslash{}\textbackslash{}}\StringTok{\&"}\NormalTok{)[[}\DecValTok{1}\NormalTok{]])} +\DocumentationTok{\#\# Treating missing data as all data values} +\NormalTok{default\_behaviour }\OtherTok{\textless{}{-}} \FunctionTok{list}\NormalTok{(missing }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(x,y) y,} +\DocumentationTok{\#\# Treating inapplicable data as all data values (like missing) } +\NormalTok{ inapplicable }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(x, y) y,} +\DocumentationTok{\#\# Treating polymorphisms as all values present:} +\NormalTok{ polymorphism }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(x,y) }\FunctionTok{strsplit}\NormalTok{(x, }\AttributeTok{split =} \StringTok{"}\SpecialCharTok{\textbackslash{}\textbackslash{}}\StringTok{\&"}\NormalTok{)[[}\DecValTok{1}\NormalTok{]],} +\DocumentationTok{\#\# Treating uncertainties as all values present (like polymorphisms):} +\NormalTok{ uncertanity }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(x,y) }\FunctionTok{strsplit}\NormalTok{(x, }\AttributeTok{split =} \StringTok{"}\SpecialCharTok{\textbackslash{}\textbackslash{}}\StringTok{/"}\NormalTok{)[[}\DecValTok{1}\NormalTok{]])} \end{Highlighting} \end{Shaded} @@ -7136,11 +7108,11 @@ \subsection{Using different character tokens in different situations}\label{usin \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Running ancestral states} -\NormalTok{ancestral\_states \textless{}{-}}\StringTok{ }\KeywordTok{multi.ace}\NormalTok{(matrix\_complex, multiple\_trees,} - \DataTypeTok{special.tokens =}\NormalTok{ my\_spec\_tokens,} - \DataTypeTok{special.behaviours =}\NormalTok{ my\_spec\_behaviours,} - \DataTypeTok{verbose =} \OtherTok{TRUE}\NormalTok{)} +\DocumentationTok{\#\# Running ancestral states} +\NormalTok{ancestral\_states }\OtherTok{\textless{}{-}} \FunctionTok{multi.ace}\NormalTok{(matrix\_complex, multiple\_trees,} + \AttributeTok{special.tokens =}\NormalTok{ my\_spec\_tokens,} + \AttributeTok{special.behaviours =}\NormalTok{ my\_spec\_behaviours,} + \AttributeTok{verbose =} \ConstantTok{TRUE}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -7160,9 +7132,9 @@ \subsection{Using different character tokens in different situations}\label{usin \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# This outputs a list of ancestral parts of the matrices for each tree} -\CommentTok{\#\# For example, here\textquotesingle{}s the first one:} -\NormalTok{ancestral\_states[[}\DecValTok{1}\NormalTok{]][}\DecValTok{1}\OperatorTok{:}\DecValTok{9}\NormalTok{, }\DecValTok{1}\OperatorTok{:}\DecValTok{10}\NormalTok{]} +\DocumentationTok{\#\# This outputs a list of ancestral parts of the matrices for each tree} +\DocumentationTok{\#\# For example, here\textquotesingle{}s the first one:} +\NormalTok{ancestral\_states[[}\DecValTok{1}\NormalTok{]][}\DecValTok{1}\SpecialCharTok{:}\DecValTok{9}\NormalTok{, }\DecValTok{1}\SpecialCharTok{:}\DecValTok{10}\NormalTok{]} \end{Highlighting} \end{Shaded} @@ -7192,13 +7164,13 @@ \subsection{\texorpdfstring{Feeding the results to \texttt{char.diff} to get dis \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Running ancestral states} -\CommentTok{\#\# and outputing a list of combined matrices (tips and nodes)} -\NormalTok{ancestral\_states \textless{}{-}}\StringTok{ }\KeywordTok{multi.ace}\NormalTok{(matrix\_complex, multiple\_trees,} - \DataTypeTok{special.tokens =}\NormalTok{ my\_spec\_tokens,} - \DataTypeTok{special.behaviours =}\NormalTok{ my\_spec\_behaviours,} - \DataTypeTok{output =} \StringTok{"combined.matrix"}\NormalTok{,} - \DataTypeTok{verbose =} \OtherTok{TRUE}\NormalTok{)} +\DocumentationTok{\#\# Running ancestral states} +\DocumentationTok{\#\# and outputing a list of combined matrices (tips and nodes)} +\NormalTok{ancestral\_states }\OtherTok{\textless{}{-}} \FunctionTok{multi.ace}\NormalTok{(matrix\_complex, multiple\_trees,} + \AttributeTok{special.tokens =}\NormalTok{ my\_spec\_tokens,} + \AttributeTok{special.behaviours =}\NormalTok{ my\_spec\_behaviours,} + \AttributeTok{output =} \StringTok{"combined.matrix"}\NormalTok{,} + \AttributeTok{verbose =} \ConstantTok{TRUE}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -7220,8 +7192,8 @@ \subsection{\texorpdfstring{Feeding the results to \texttt{char.diff} to get dis \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Measuring the distances between rows using the MORD distance} -\NormalTok{distances \textless{}{-}}\StringTok{ }\KeywordTok{lapply}\NormalTok{(ancestral\_states, char.diff, }\DataTypeTok{method =} \StringTok{"mord"}\NormalTok{, }\DataTypeTok{by.col =} \OtherTok{FALSE}\NormalTok{)} +\DocumentationTok{\#\# Measuring the distances between rows using the MORD distance} +\NormalTok{distances }\OtherTok{\textless{}{-}} \FunctionTok{lapply}\NormalTok{(ancestral\_states, char.diff, }\AttributeTok{method =} \StringTok{"mord"}\NormalTok{, }\AttributeTok{by.col =} \ConstantTok{FALSE}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -7235,17 +7207,17 @@ \subsection{Running ancestral states estimations for continuous characters}\labe \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)} -\CommentTok{\#\# Creating three coalescent trees} -\NormalTok{my\_trees \textless{}{-}}\StringTok{ }\KeywordTok{replicate}\NormalTok{(}\DecValTok{3}\NormalTok{, }\KeywordTok{rcoal}\NormalTok{(}\DecValTok{15}\NormalTok{), }\DataTypeTok{simplify =} \OtherTok{FALSE}\NormalTok{)} -\CommentTok{\#\# Adding node labels} -\NormalTok{my\_trees \textless{}{-}}\StringTok{ }\KeywordTok{lapply}\NormalTok{(my\_trees, makeNodeLabel)} -\CommentTok{\#\# Making into a multiPhylo object} -\KeywordTok{class}\NormalTok{(my\_trees) \textless{}{-}}\StringTok{ "multiPhylo"} +\FunctionTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)} +\DocumentationTok{\#\# Creating three coalescent trees} +\NormalTok{my\_trees }\OtherTok{\textless{}{-}} \FunctionTok{replicate}\NormalTok{(}\DecValTok{3}\NormalTok{, }\FunctionTok{rcoal}\NormalTok{(}\DecValTok{15}\NormalTok{), }\AttributeTok{simplify =} \ConstantTok{FALSE}\NormalTok{)} +\DocumentationTok{\#\# Adding node labels} +\NormalTok{my\_trees }\OtherTok{\textless{}{-}} \FunctionTok{lapply}\NormalTok{(my\_trees, makeNodeLabel)} +\DocumentationTok{\#\# Making into a multiPhylo object} +\FunctionTok{class}\NormalTok{(my\_trees) }\OtherTok{\textless{}{-}} \StringTok{"multiPhylo"} -\CommentTok{\#\# Creating a matrix of continuous characters} -\NormalTok{data \textless{}{-}}\StringTok{ }\KeywordTok{space.maker}\NormalTok{(}\DataTypeTok{elements =} \DecValTok{15}\NormalTok{, }\DataTypeTok{dimensions =} \DecValTok{5}\NormalTok{, }\DataTypeTok{distribution =}\NormalTok{ rnorm,} - \DataTypeTok{elements.name =}\NormalTok{ my\_trees[[}\DecValTok{1}\NormalTok{]]}\OperatorTok{$}\NormalTok{tip.label)} +\DocumentationTok{\#\# Creating a matrix of continuous characters} +\NormalTok{data }\OtherTok{\textless{}{-}} \FunctionTok{space.maker}\NormalTok{(}\AttributeTok{elements =} \DecValTok{15}\NormalTok{, }\AttributeTok{dimensions =} \DecValTok{5}\NormalTok{, }\AttributeTok{distribution =}\NormalTok{ rnorm,} + \AttributeTok{elements.name =}\NormalTok{ my\_trees[[}\DecValTok{1}\NormalTok{]]}\SpecialCharTok{$}\NormalTok{tip.label)} \end{Highlighting} \end{Shaded} @@ -7254,43 +7226,31 @@ \subsection{Running ancestral states estimations for continuous characters}\labe \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Running multi.ace on continuous data} -\NormalTok{my\_ancestral\_states \textless{}{-}}\StringTok{ }\KeywordTok{multi.ace}\NormalTok{(data, my\_trees)} +\DocumentationTok{\#\# Running multi.ace on continuous data} +\NormalTok{my\_ancestral\_states }\OtherTok{\textless{}{-}} \FunctionTok{multi.ace}\NormalTok{(data, my\_trees)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced \end{verbatim} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# We end up with three matrices of node states estimates} -\KeywordTok{str}\NormalTok{(my\_ancestral\_states)} +\DocumentationTok{\#\# We end up with three matrices of node states estimates} +\FunctionTok{str}\NormalTok{(my\_ancestral\_states)} \end{Highlighting} \end{Shaded} @@ -7315,47 +7275,35 @@ \subsection{Running ancestral states estimations for continuous characters}\labe \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Running multi.ace on continuous data} -\NormalTok{my\_ancestral\_states \textless{}{-}}\StringTok{ }\KeywordTok{multi.ace}\NormalTok{(data, my\_trees, }\DataTypeTok{output =} \StringTok{"dispRity"}\NormalTok{)} +\DocumentationTok{\#\# Running multi.ace on continuous data} +\NormalTok{my\_ancestral\_states }\OtherTok{\textless{}{-}} \FunctionTok{multi.ace}\NormalTok{(data, my\_trees, }\AttributeTok{output =} \StringTok{"dispRity"}\NormalTok{)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced \end{verbatim} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# We end up with three matrices of node states estimates} -\KeywordTok{plot}\NormalTok{(my\_ancestral\_states)} +\DocumentationTok{\#\# We end up with three matrices of node states estimates} +\FunctionTok{plot}\NormalTok{(my\_ancestral\_states)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-194-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-202-1.pdf} You can also mix continuous and discrete characters together. By default the \texttt{multi.ace} detects which character is of which type and applies the correct estimations based on that. @@ -7363,46 +7311,34 @@ \subsection{Running ancestral states estimations for continuous characters}\labe \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Adding two discrete characters} -\NormalTok{data \textless{}{-}}\StringTok{ }\KeywordTok{as.data.frame}\NormalTok{(data)} -\NormalTok{data \textless{}{-}}\StringTok{ }\KeywordTok{cbind}\NormalTok{(data, }\StringTok{"new\_char"}\NormalTok{ =}\StringTok{ }\KeywordTok{as.character}\NormalTok{(}\KeywordTok{sample}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{2}\NormalTok{, }\DecValTok{15}\NormalTok{, }\DataTypeTok{replace =} \OtherTok{TRUE}\NormalTok{)))} -\NormalTok{data \textless{}{-}}\StringTok{ }\KeywordTok{cbind}\NormalTok{(data, }\StringTok{"new\_char2"}\NormalTok{ =}\StringTok{ }\KeywordTok{as.character}\NormalTok{(}\KeywordTok{sample}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{2}\NormalTok{, }\DecValTok{15}\NormalTok{, }\DataTypeTok{replace =} \OtherTok{TRUE}\NormalTok{)))} +\DocumentationTok{\#\# Adding two discrete characters} +\NormalTok{data }\OtherTok{\textless{}{-}} \FunctionTok{as.data.frame}\NormalTok{(data)} +\NormalTok{data }\OtherTok{\textless{}{-}} \FunctionTok{cbind}\NormalTok{(data, }\StringTok{"new\_char"} \OtherTok{=} \FunctionTok{as.character}\NormalTok{(}\FunctionTok{sample}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{2}\NormalTok{, }\DecValTok{15}\NormalTok{, }\AttributeTok{replace =} \ConstantTok{TRUE}\NormalTok{)))} +\NormalTok{data }\OtherTok{\textless{}{-}} \FunctionTok{cbind}\NormalTok{(data, }\StringTok{"new\_char2"} \OtherTok{=} \FunctionTok{as.character}\NormalTok{(}\FunctionTok{sample}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{2}\NormalTok{, }\DecValTok{15}\NormalTok{, }\AttributeTok{replace =} \ConstantTok{TRUE}\NormalTok{)))} -\CommentTok{\#\# Setting up different models for each characters} -\CommentTok{\#\# BM for all 5 continuous characters} -\CommentTok{\#\# and ER and ARD for the two discrete ones} -\NormalTok{my\_models \textless{}{-}}\StringTok{ }\KeywordTok{c}\NormalTok{(}\KeywordTok{rep}\NormalTok{(}\StringTok{"BM"}\NormalTok{, }\DecValTok{5}\NormalTok{), }\StringTok{"ER"}\NormalTok{, }\StringTok{"ARD"}\NormalTok{)} +\DocumentationTok{\#\# Setting up different models for each characters} +\DocumentationTok{\#\# BM for all 5 continuous characters} +\DocumentationTok{\#\# and ER and ARD for the two discrete ones} +\NormalTok{my\_models }\OtherTok{\textless{}{-}} \FunctionTok{c}\NormalTok{(}\FunctionTok{rep}\NormalTok{(}\StringTok{"BM"}\NormalTok{, }\DecValTok{5}\NormalTok{), }\StringTok{"ER"}\NormalTok{, }\StringTok{"ARD"}\NormalTok{)} -\CommentTok{\#\# Running the estimation with the specified models} -\NormalTok{my\_ancestral\_states \textless{}{-}}\StringTok{ }\KeywordTok{multi.ace}\NormalTok{(data, my\_trees, }\DataTypeTok{models =}\NormalTok{ my\_models)} +\DocumentationTok{\#\# Running the estimation with the specified models} +\NormalTok{my\_ancestral\_states }\OtherTok{\textless{}{-}} \FunctionTok{multi.ace}\NormalTok{(data, my\_trees, }\AttributeTok{models =}\NormalTok{ my\_models)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced - ## Warning in sqrt(1/out$hessian): NaNs produced \end{verbatim} @@ -7425,11 +7361,11 @@ \section{\texorpdfstring{Manipulating \texttt{dispRity} objects}{Manipulating di \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Loading the example data} -\KeywordTok{data}\NormalTok{(disparity)} +\DocumentationTok{\#\# Loading the example data} +\FunctionTok{data}\NormalTok{(disparity)} -\CommentTok{\#\# What is the class of the median\_centroids object?} -\KeywordTok{class}\NormalTok{(disparity)} +\DocumentationTok{\#\# What is the class of the median\_centroids object?} +\FunctionTok{class}\NormalTok{(disparity)} \end{Highlighting} \end{Shaded} @@ -7439,8 +7375,8 @@ \section{\texorpdfstring{Manipulating \texttt{dispRity} objects}{Manipulating di \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# What does the object contain?} -\KeywordTok{names}\NormalTok{(disparity)} +\DocumentationTok{\#\# What does the object contain?} +\FunctionTok{names}\NormalTok{(disparity)} \end{Highlighting} \end{Shaded} @@ -7450,7 +7386,7 @@ \section{\texorpdfstring{Manipulating \texttt{dispRity} objects}{Manipulating di \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Summarising it using the S3 method print.dispRity} +\DocumentationTok{\#\# Summarising it using the S3 method print.dispRity} \NormalTok{disparity} \end{Highlighting} \end{Shaded} @@ -7459,7 +7395,7 @@ \section{\texorpdfstring{Manipulating \texttt{dispRity} objects}{Manipulating di ## ---- dispRity object ---- ## 7 continuous (acctran) time subsets for 99 elements in one matrix with 97 dimensions with 1 phylogenetic tree ## 90, 80, 70, 60, 50 ... -## Data was bootstrapped 100 times (method:"full") and rarefied to 20, 15, 10, 5 elements. +## Rows were bootstrapped 100 times (method:"full") and rarefied to 20, 15, 10, 5 elements. ## Disparity was calculated as: c(median, centroids). \end{verbatim} @@ -7467,9 +7403,9 @@ \section{\texorpdfstring{Manipulating \texttt{dispRity} objects}{Manipulating di \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Display the full object} -\KeywordTok{print}\NormalTok{(disparity, }\DataTypeTok{all =} \OtherTok{TRUE}\NormalTok{)} -\CommentTok{\#\# This is more nearly \textasciitilde{} 5000 lines on my 13 inch laptop screen!} +\DocumentationTok{\#\# Display the full object} +\FunctionTok{print}\NormalTok{(disparity, }\AttributeTok{all =} \ConstantTok{TRUE}\NormalTok{)} +\DocumentationTok{\#\# This is more nearly \textasciitilde{} 5000 lines on my 13 inch laptop screen!} \end{Highlighting} \end{Shaded} @@ -7490,8 +7426,8 @@ \subsubsection{\texorpdfstring{\texttt{make.dispRity}}{make.dispRity}}\label{mak \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Creating an empty dispRity object} -\KeywordTok{make.dispRity}\NormalTok{()} +\DocumentationTok{\#\# Creating an empty dispRity object} +\FunctionTok{make.dispRity}\NormalTok{()} \end{Highlighting} \end{Shaded} @@ -7501,8 +7437,8 @@ \subsubsection{\texorpdfstring{\texttt{make.dispRity}}{make.dispRity}}\label{mak \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Creating an "empty" dispRity object with a matrix} -\NormalTok{(disparity\_obj \textless{}{-}}\StringTok{ }\KeywordTok{make.dispRity}\NormalTok{(}\KeywordTok{matrix}\NormalTok{(}\KeywordTok{rnorm}\NormalTok{(}\DecValTok{20}\NormalTok{), }\DecValTok{5}\NormalTok{, }\DecValTok{4}\NormalTok{)))} +\DocumentationTok{\#\# Creating an "empty" dispRity object with a matrix} +\NormalTok{(disparity\_obj }\OtherTok{\textless{}{-}} \FunctionTok{make.dispRity}\NormalTok{(}\FunctionTok{matrix}\NormalTok{(}\FunctionTok{rnorm}\NormalTok{(}\DecValTok{20}\NormalTok{), }\DecValTok{5}\NormalTok{, }\DecValTok{4}\NormalTok{)))} \end{Highlighting} \end{Shaded} @@ -7518,8 +7454,8 @@ \subsubsection{\texorpdfstring{\texttt{fill.dispRity}}{fill.dispRity}}\label{fil \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The dispRity object\textquotesingle{}s call is indeed empty} -\NormalTok{disparity\_obj}\OperatorTok{$}\NormalTok{call} +\DocumentationTok{\#\# The dispRity object\textquotesingle{}s call is indeed empty} +\NormalTok{disparity\_obj}\SpecialCharTok{$}\NormalTok{call} \end{Highlighting} \end{Shaded} @@ -7529,8 +7465,8 @@ \subsubsection{\texorpdfstring{\texttt{fill.dispRity}}{fill.dispRity}}\label{fil \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Filling an empty disparity object (that needs to contain at least a matrix)} -\NormalTok{(disparity\_obj \textless{}{-}}\StringTok{ }\KeywordTok{fill.dispRity}\NormalTok{(disparity\_obj))} +\DocumentationTok{\#\# Filling an empty disparity object (that needs to contain at least a matrix)} +\NormalTok{(disparity\_obj }\OtherTok{\textless{}{-}} \FunctionTok{fill.dispRity}\NormalTok{(disparity\_obj))} \end{Highlighting} \end{Shaded} @@ -7546,8 +7482,8 @@ \subsubsection{\texorpdfstring{\texttt{fill.dispRity}}{fill.dispRity}}\label{fil \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The dipRity object has now the correct minimal attributes} -\NormalTok{disparity\_obj}\OperatorTok{$}\NormalTok{call} +\DocumentationTok{\#\# The dipRity object has now the correct minimal attributes} +\NormalTok{disparity\_obj}\SpecialCharTok{$}\NormalTok{call} \end{Highlighting} \end{Shaded} @@ -7564,13 +7500,13 @@ \subsubsection{\texorpdfstring{\texttt{get.matrix}}{get.matrix}}\label{get.matri \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Extracting the matrix containing the coordinates of the elements at time 50} -\KeywordTok{str}\NormalTok{(}\KeywordTok{get.matrix}\NormalTok{(disparity, }\StringTok{"50"}\NormalTok{))} +\DocumentationTok{\#\# Extracting the matrix containing the coordinates of the elements at time 50} +\FunctionTok{str}\NormalTok{(}\FunctionTok{get.matrix}\NormalTok{(disparity, }\StringTok{"50"}\NormalTok{))} \end{Highlighting} \end{Shaded} \begin{verbatim} -## num [1:18, 1:97] -0.1036 0.4318 0.3371 0.0501 0.685 ... +## num [1:18, 1:97] -0.1 0.427 0.333 0.054 0.674 ... ## - attr(*, "dimnames")=List of 2 ## ..$ : chr [1:18] "Leptictis" "Dasypodidae" "n24" "Potamogalinae" ... ## ..$ : NULL @@ -7578,14 +7514,14 @@ \subsubsection{\texorpdfstring{\texttt{get.matrix}}{get.matrix}}\label{get.matri \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Extracting the 3rd bootstrapped matrix with the 2nd rarefaction level} -\CommentTok{\#\# (15 elements) from the second group (80 Mya)} -\KeywordTok{str}\NormalTok{(}\KeywordTok{get.matrix}\NormalTok{(disparity, }\DataTypeTok{subsets =} \DecValTok{1}\NormalTok{, }\DataTypeTok{bootstrap =} \DecValTok{3}\NormalTok{, }\DataTypeTok{rarefaction =} \DecValTok{2}\NormalTok{))} +\DocumentationTok{\#\# Extracting the 3rd bootstrapped matrix with the 2nd rarefaction level} +\DocumentationTok{\#\# (15 elements) from the second group (80 Mya)} +\FunctionTok{str}\NormalTok{(}\FunctionTok{get.matrix}\NormalTok{(disparity, }\AttributeTok{subsets =} \DecValTok{1}\NormalTok{, }\AttributeTok{bootstrap =} \DecValTok{3}\NormalTok{, }\AttributeTok{rarefaction =} \DecValTok{2}\NormalTok{))} \end{Highlighting} \end{Shaded} \begin{verbatim} -## num [1:15, 1:97] -0.12948 -0.57973 0.00361 0.27123 0.27123 ... +## num [1:15, 1:97] -0.134942 -0.571937 0.000589 0.266188 0.266188 ... ## - attr(*, "dimnames")=List of 2 ## ..$ : chr [1:15] "n15" "Maelestes" "n20" "n34" ... ## ..$ : NULL @@ -7598,8 +7534,8 @@ \subsubsection{\texorpdfstring{\texttt{n.subsets}}{n.subsets}}\label{n.subsets}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# How many subsets are in this object?} -\KeywordTok{n.subsets}\NormalTok{(disparity)} +\DocumentationTok{\#\# How many subsets are in this object?} +\FunctionTok{n.subsets}\NormalTok{(disparity)} \end{Highlighting} \end{Shaded} @@ -7614,8 +7550,8 @@ \subsubsection{\texorpdfstring{\texttt{name.subsets}}{name.subsets}}\label{name. \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# What are they called?} -\KeywordTok{name.subsets}\NormalTok{(disparity)} +\DocumentationTok{\#\# What are they called?} +\FunctionTok{name.subsets}\NormalTok{(disparity)} \end{Highlighting} \end{Shaded} @@ -7630,8 +7566,8 @@ \subsubsection{\texorpdfstring{\texttt{size.subsets}}{size.subsets}}\label{size. \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# How many elements are there in each subset?} -\KeywordTok{size.subsets}\NormalTok{(disparity)} +\DocumentationTok{\#\# How many elements are there in each subset?} +\FunctionTok{size.subsets}\NormalTok{(disparity)} \end{Highlighting} \end{Shaded} @@ -7647,11 +7583,11 @@ \subsubsection{\texorpdfstring{\texttt{get.subsets}}{get.subsets}}\label{get.sub \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Extracting all the data for the crown mammals} -\NormalTok{(crown\_mammals \textless{}{-}}\StringTok{ }\KeywordTok{get.subsets}\NormalTok{(disp\_crown\_stemBS, }\StringTok{"Group.crown"}\NormalTok{))} +\DocumentationTok{\#\# Extracting all the data for the crown mammals} +\NormalTok{(crown\_mammals }\OtherTok{\textless{}{-}} \FunctionTok{get.subsets}\NormalTok{(disp\_crown\_stemBS, }\StringTok{"Group.crown"}\NormalTok{))} -\CommentTok{\#\# The object keeps the properties of the parent object but is composed of only one subsets} -\KeywordTok{length}\NormalTok{(crown\_mammals}\OperatorTok{$}\NormalTok{subsets)} +\DocumentationTok{\#\# The object keeps the properties of the parent object but is composed of only one subsets} +\FunctionTok{length}\NormalTok{(crown\_mammals}\SpecialCharTok{$}\NormalTok{subsets)} \end{Highlighting} \end{Shaded} @@ -7662,8 +7598,8 @@ \subsubsection{\texorpdfstring{\texttt{combine.subsets}}{combine.subsets}}\label \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Combine the two first subsets in the dispRity data example} -\KeywordTok{combine.subsets}\NormalTok{(disparity, }\KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{))} +\DocumentationTok{\#\# Combine the two first subsets in the dispRity data example} +\FunctionTok{combine.subsets}\NormalTok{(disparity, }\FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{))} \end{Highlighting} \end{Shaded} @@ -7676,12 +7612,12 @@ \subsubsection{\texorpdfstring{\texttt{get.disparity}}{get.disparity}}\label{get \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Extracting the observed disparity (default)} -\KeywordTok{get.disparity}\NormalTok{(disparity)} +\DocumentationTok{\#\# Extracting the observed disparity (default)} +\FunctionTok{get.disparity}\NormalTok{(disparity)} -\CommentTok{\#\# Extracting the disparity from the bootstrapped values from the} -\CommentTok{\#\# 10th rarefaction level from the second subsets (80 Mya)} -\KeywordTok{get.disparity}\NormalTok{(disparity, }\DataTypeTok{observed =} \OtherTok{FALSE}\NormalTok{, }\DataTypeTok{subsets =} \DecValTok{2}\NormalTok{, }\DataTypeTok{rarefaction =} \DecValTok{10}\NormalTok{)} +\DocumentationTok{\#\# Extracting the disparity from the bootstrapped values from the} +\DocumentationTok{\#\# 10th rarefaction level from the second subsets (80 Mya)} +\FunctionTok{get.disparity}\NormalTok{(disparity, }\AttributeTok{observed =} \ConstantTok{FALSE}\NormalTok{, }\AttributeTok{subsets =} \DecValTok{2}\NormalTok{, }\AttributeTok{rarefaction =} \DecValTok{10}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -7692,17 +7628,17 @@ \subsubsection{\texorpdfstring{\texttt{scale.dispRity}}{scale.dispRity}}\label{s \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Getting the disparity values of the time subsets} -\KeywordTok{head}\NormalTok{(}\KeywordTok{summary}\NormalTok{(disparity))} +\DocumentationTok{\#\# Getting the disparity values of the time subsets} +\FunctionTok{head}\NormalTok{(}\FunctionTok{summary}\NormalTok{(disparity))} -\CommentTok{\#\# Scaling the same disparity values} -\KeywordTok{head}\NormalTok{(}\KeywordTok{summary}\NormalTok{(}\KeywordTok{scale.dispRity}\NormalTok{(disparity, }\DataTypeTok{scale =} \OtherTok{TRUE}\NormalTok{)))} +\DocumentationTok{\#\# Scaling the same disparity values} +\FunctionTok{head}\NormalTok{(}\FunctionTok{summary}\NormalTok{(}\FunctionTok{scale.dispRity}\NormalTok{(disparity, }\AttributeTok{scale =} \ConstantTok{TRUE}\NormalTok{)))} -\CommentTok{\#\# Scaling and centering:} -\KeywordTok{head}\NormalTok{(}\KeywordTok{summary}\NormalTok{(}\KeywordTok{scale.dispRity}\NormalTok{(disparity, }\DataTypeTok{scale =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{center =} \OtherTok{TRUE}\NormalTok{)))} +\DocumentationTok{\#\# Scaling and centering:} +\FunctionTok{head}\NormalTok{(}\FunctionTok{summary}\NormalTok{(}\FunctionTok{scale.dispRity}\NormalTok{(disparity, }\AttributeTok{scale =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{center =} \ConstantTok{TRUE}\NormalTok{)))} -\CommentTok{\#\# Rescaling the value by dividing by a maximum value} -\KeywordTok{head}\NormalTok{(}\KeywordTok{summary}\NormalTok{(}\KeywordTok{scale.dispRity}\NormalTok{(disparity, }\DataTypeTok{max =} \DecValTok{10}\NormalTok{)))} +\DocumentationTok{\#\# Rescaling the value by dividing by a maximum value} +\FunctionTok{head}\NormalTok{(}\FunctionTok{summary}\NormalTok{(}\FunctionTok{scale.dispRity}\NormalTok{(disparity, }\AttributeTok{max =} \DecValTok{10}\NormalTok{)))} \end{Highlighting} \end{Shaded} @@ -7713,11 +7649,11 @@ \subsubsection{\texorpdfstring{\texttt{sort.dispRity}}{sort.dispRity}}\label{sor \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Sorting the disparity subsets in inverse alphabetic order} -\KeywordTok{head}\NormalTok{(}\KeywordTok{summary}\NormalTok{(}\KeywordTok{sort}\NormalTok{(disparity, }\DataTypeTok{decreasing =} \OtherTok{TRUE}\NormalTok{)))} +\DocumentationTok{\#\# Sorting the disparity subsets in inverse alphabetic order} +\FunctionTok{head}\NormalTok{(}\FunctionTok{summary}\NormalTok{(}\FunctionTok{sort}\NormalTok{(disparity, }\AttributeTok{decreasing =} \ConstantTok{TRUE}\NormalTok{)))} -\CommentTok{\#\# Customised sorting} -\KeywordTok{head}\NormalTok{(}\KeywordTok{summary}\NormalTok{(}\KeywordTok{sort}\NormalTok{(disparity, }\DataTypeTok{sort =} \KeywordTok{c}\NormalTok{(}\DecValTok{7}\NormalTok{, }\DecValTok{1}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{4}\NormalTok{, }\DecValTok{5}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{6}\NormalTok{))))} +\DocumentationTok{\#\# Customised sorting} +\FunctionTok{head}\NormalTok{(}\FunctionTok{summary}\NormalTok{(}\FunctionTok{sort}\NormalTok{(disparity, }\AttributeTok{sort =} \FunctionTok{c}\NormalTok{(}\DecValTok{7}\NormalTok{, }\DecValTok{1}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{4}\NormalTok{, }\DecValTok{5}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{6}\NormalTok{))))} \end{Highlighting} \end{Shaded} @@ -7728,14 +7664,14 @@ \subsubsection{\texorpdfstring{\texttt{get.tree} \texttt{add.tree} and \texttt{r \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Getting the tree component of a dispRity object} -\KeywordTok{get.tree}\NormalTok{(disparity)} +\DocumentationTok{\#\# Getting the tree component of a dispRity object} +\FunctionTok{get.tree}\NormalTok{(disparity)} -\CommentTok{\#\# Removing the tree} -\KeywordTok{remove.tree}\NormalTok{(disparity)} +\DocumentationTok{\#\# Removing the tree} +\FunctionTok{remove.tree}\NormalTok{(disparity)} -\CommentTok{\#\# Adding a tree} -\KeywordTok{add.tree}\NormalTok{(disparity, }\DataTypeTok{tree =}\NormalTok{ BeckLee\_tree)} +\DocumentationTok{\#\# Adding a tree} +\FunctionTok{add.tree}\NormalTok{(disparity, }\AttributeTok{tree =}\NormalTok{ BeckLee\_tree)} \end{Highlighting} \end{Shaded} @@ -7745,36 +7681,36 @@ \subsubsection{\texorpdfstring{\texttt{get.tree} \texttt{add.tree} and \texttt{r \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Load the Beck \& Lee 2014 data} -\KeywordTok{data}\NormalTok{(BeckLee\_tree) ; }\KeywordTok{data}\NormalTok{(BeckLee\_mat99) ; }\KeywordTok{data}\NormalTok{(BeckLee\_ages)} +\DocumentationTok{\#\# Load the Beck \& Lee 2014 data} +\FunctionTok{data}\NormalTok{(BeckLee\_tree) ; }\FunctionTok{data}\NormalTok{(BeckLee\_mat99) ; }\FunctionTok{data}\NormalTok{(BeckLee\_ages)} -\CommentTok{\#\# Time binning (discrete method)} -\CommentTok{\#\# Generate two discrete time bins from 120 to 40 Ma every 20 Ma} -\NormalTok{time\_bins \textless{}{-}}\StringTok{ }\KeywordTok{chrono.subsets}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_mat99, }\DataTypeTok{tree =}\NormalTok{ BeckLee\_tree,} - \DataTypeTok{method =} \StringTok{"discrete"}\NormalTok{, }\DataTypeTok{time =} \KeywordTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{100}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{60}\NormalTok{),} - \DataTypeTok{inc.nodes =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{FADLAD =}\NormalTok{ BeckLee\_ages)} +\DocumentationTok{\#\# Time binning (discrete method)} +\DocumentationTok{\#\# Generate two discrete time bins from 120 to 40 Ma every 20 Ma} +\NormalTok{time\_bins }\OtherTok{\textless{}{-}} \FunctionTok{chrono.subsets}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_mat99, }\AttributeTok{tree =}\NormalTok{ BeckLee\_tree,} + \AttributeTok{method =} \StringTok{"discrete"}\NormalTok{, }\AttributeTok{time =} \FunctionTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{100}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{60}\NormalTok{),} + \AttributeTok{inc.nodes =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{FADLAD =}\NormalTok{ BeckLee\_ages)} -\CommentTok{\#\# Getting the subtrees all the way to the root} -\NormalTok{root\_subsets \textless{}{-}}\StringTok{ }\KeywordTok{get.tree}\NormalTok{(time\_bins, }\DataTypeTok{subsets =} \OtherTok{TRUE}\NormalTok{)} +\DocumentationTok{\#\# Getting the subtrees all the way to the root} +\NormalTok{root\_subsets }\OtherTok{\textless{}{-}} \FunctionTok{get.tree}\NormalTok{(time\_bins, }\AttributeTok{subsets =} \ConstantTok{TRUE}\NormalTok{)} -\CommentTok{\#\# Plotting the bin contents} -\NormalTok{old\_par \textless{}{-}}\StringTok{ }\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =} \KeywordTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{))} -\KeywordTok{plot}\NormalTok{(BeckLee\_tree, }\DataTypeTok{main =} \StringTok{"original tree"}\NormalTok{, }\DataTypeTok{show.tip.label =} \OtherTok{FALSE}\NormalTok{)} -\KeywordTok{axisPhylo}\NormalTok{()} -\KeywordTok{abline}\NormalTok{(}\DataTypeTok{v =}\NormalTok{ BeckLee\_tree}\OperatorTok{$}\NormalTok{root.time }\OperatorTok{{-}}\StringTok{ }\KeywordTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{100}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{60}\NormalTok{))} -\ControlFlowTok{for}\NormalTok{(i }\ControlFlowTok{in} \DecValTok{1}\OperatorTok{:}\DecValTok{3}\NormalTok{) \{} - \KeywordTok{plot}\NormalTok{(root\_subsets[[i]], }\DataTypeTok{main =} \KeywordTok{names}\NormalTok{(root\_subsets)[i],} - \DataTypeTok{show.tip.label =} \OtherTok{FALSE}\NormalTok{)} - \KeywordTok{axisPhylo}\NormalTok{()} +\DocumentationTok{\#\# Plotting the bin contents} +\NormalTok{old\_par }\OtherTok{\textless{}{-}} \FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =} \FunctionTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{))} +\FunctionTok{plot}\NormalTok{(BeckLee\_tree, }\AttributeTok{main =} \StringTok{"original tree"}\NormalTok{, }\AttributeTok{show.tip.label =} \ConstantTok{FALSE}\NormalTok{)} +\FunctionTok{axisPhylo}\NormalTok{()} +\FunctionTok{abline}\NormalTok{(}\AttributeTok{v =}\NormalTok{ BeckLee\_tree}\SpecialCharTok{$}\NormalTok{root.time }\SpecialCharTok{{-}} \FunctionTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{100}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{60}\NormalTok{))} +\ControlFlowTok{for}\NormalTok{(i }\ControlFlowTok{in} \DecValTok{1}\SpecialCharTok{:}\DecValTok{3}\NormalTok{) \{} + \FunctionTok{plot}\NormalTok{(root\_subsets[[i]], }\AttributeTok{main =} \FunctionTok{names}\NormalTok{(root\_subsets)[i],} + \AttributeTok{show.tip.label =} \ConstantTok{FALSE}\NormalTok{)} + \FunctionTok{axisPhylo}\NormalTok{()} \NormalTok{\}} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-210-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-218-1.pdf} \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{par}\NormalTok{(old\_par)} +\FunctionTok{par}\NormalTok{(old\_par)} \end{Highlighting} \end{Shaded} @@ -7782,27 +7718,27 @@ \subsubsection{\texorpdfstring{\texttt{get.tree} \texttt{add.tree} and \texttt{r \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Getting the subtrees all the way to the root} -\NormalTok{bin\_subsets \textless{}{-}}\StringTok{ }\KeywordTok{get.tree}\NormalTok{(time\_bins, }\DataTypeTok{subsets =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{to.root =} \OtherTok{FALSE}\NormalTok{)} +\DocumentationTok{\#\# Getting the subtrees all the way to the root} +\NormalTok{bin\_subsets }\OtherTok{\textless{}{-}} \FunctionTok{get.tree}\NormalTok{(time\_bins, }\AttributeTok{subsets =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{to.root =} \ConstantTok{FALSE}\NormalTok{)} -\CommentTok{\#\# Plotting the bin contents} -\NormalTok{old\_par \textless{}{-}}\StringTok{ }\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =} \KeywordTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{))} -\KeywordTok{plot}\NormalTok{(BeckLee\_tree, }\DataTypeTok{main =} \StringTok{"original tree"}\NormalTok{, }\DataTypeTok{show.tip.label =} \OtherTok{FALSE}\NormalTok{)} -\KeywordTok{axisPhylo}\NormalTok{()} -\KeywordTok{abline}\NormalTok{(}\DataTypeTok{v =}\NormalTok{ BeckLee\_tree}\OperatorTok{$}\NormalTok{root.time }\OperatorTok{{-}}\StringTok{ }\KeywordTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{100}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{60}\NormalTok{))} -\ControlFlowTok{for}\NormalTok{(i }\ControlFlowTok{in} \DecValTok{1}\OperatorTok{:}\DecValTok{3}\NormalTok{) \{} - \KeywordTok{plot}\NormalTok{(bin\_subsets[[i]], }\DataTypeTok{main =} \KeywordTok{names}\NormalTok{(bin\_subsets)[i],} - \DataTypeTok{show.tip.label =} \OtherTok{FALSE}\NormalTok{)} - \KeywordTok{axisPhylo}\NormalTok{()} +\DocumentationTok{\#\# Plotting the bin contents} +\NormalTok{old\_par }\OtherTok{\textless{}{-}} \FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =} \FunctionTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{))} +\FunctionTok{plot}\NormalTok{(BeckLee\_tree, }\AttributeTok{main =} \StringTok{"original tree"}\NormalTok{, }\AttributeTok{show.tip.label =} \ConstantTok{FALSE}\NormalTok{)} +\FunctionTok{axisPhylo}\NormalTok{()} +\FunctionTok{abline}\NormalTok{(}\AttributeTok{v =}\NormalTok{ BeckLee\_tree}\SpecialCharTok{$}\NormalTok{root.time }\SpecialCharTok{{-}} \FunctionTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{100}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{60}\NormalTok{))} +\ControlFlowTok{for}\NormalTok{(i }\ControlFlowTok{in} \DecValTok{1}\SpecialCharTok{:}\DecValTok{3}\NormalTok{) \{} + \FunctionTok{plot}\NormalTok{(bin\_subsets[[i]], }\AttributeTok{main =} \FunctionTok{names}\NormalTok{(bin\_subsets)[i],} + \AttributeTok{show.tip.label =} \ConstantTok{FALSE}\NormalTok{)} + \FunctionTok{axisPhylo}\NormalTok{()} \NormalTok{\}} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-211-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-219-1.pdf} \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{par}\NormalTok{(old\_par)} +\FunctionTok{par}\NormalTok{(old\_par)} \end{Highlighting} \end{Shaded} @@ -7810,20 +7746,20 @@ \subsubsection{\texorpdfstring{\texttt{get.tree} \texttt{add.tree} and \texttt{r \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# How many cumulated phylogenetic diversity in each bin?} -\KeywordTok{lapply}\NormalTok{(bin\_subsets, }\ControlFlowTok{function}\NormalTok{(tree) }\KeywordTok{sum}\NormalTok{(tree}\OperatorTok{$}\NormalTok{edge.length))} +\DocumentationTok{\#\# How many cumulated phylogenetic diversity in each bin?} +\FunctionTok{lapply}\NormalTok{(bin\_subsets, }\ControlFlowTok{function}\NormalTok{(tree) }\FunctionTok{sum}\NormalTok{(tree}\SpecialCharTok{$}\NormalTok{edge.length))} \end{Highlighting} \end{Shaded} \begin{verbatim} ## $`120 - 100` -## [1] 189.2802 +## [1] 189.2829 ## ## $`100 - 80` -## [1] 341.7199 +## [1] 341.7223 ## ## $`80 - 60` -## [1] 426.7492 +## [1] 426.7486 \end{verbatim} \hypertarget{disprity-object}{% @@ -7886,8 +7822,8 @@ \subsection{\texorpdfstring{\texttt{\$call}}{\$call}}\label{call}} \texttt{\$call\$disparity}: this is a \texttt{list} containing one element, \texttt{\$metric}, that is a \texttt{list} containing the different functions passed to the \texttt{metric} argument in \texttt{dispRity}. These are \texttt{call} elements and get modified each time the \texttt{dispRity} function is used (the first element is the first metric(s), the second, the second metric(s), etc.). \end{itemize} -\hypertarget{subsets}{% -\subsection{\texorpdfstring{\texttt{\$subsets}}{\$subsets}}\label{subsets}} +\hypertarget{subsets-1}{% +\subsection{\texorpdfstring{\texttt{\$subsets}}{\$subsets}}\label{subsets-1}} This element contain the eventual subsets of the multidimensional space. It is a \texttt{list} of subset names. @@ -7979,7 +7915,7 @@ \section{Data}\label{data}} \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{data}\NormalTok{(iris)} +\FunctionTok{data}\NormalTok{(iris)} \end{Highlighting} \end{Shaded} @@ -7987,10 +7923,10 @@ \section{Data}\label{data}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Separating the species} -\NormalTok{species \textless{}{-}}\StringTok{ }\NormalTok{iris[,}\DecValTok{5}\NormalTok{]} -\CommentTok{\#\# Which species?} -\KeywordTok{unique}\NormalTok{(species)} +\DocumentationTok{\#\# Separating the species} +\NormalTok{species }\OtherTok{\textless{}{-}}\NormalTok{ iris[,}\DecValTok{5}\NormalTok{]} +\DocumentationTok{\#\# Which species?} +\FunctionTok{unique}\NormalTok{(species)} \end{Highlighting} \end{Shaded} @@ -8001,9 +7937,9 @@ \section{Data}\label{data}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Separating the petal/sepal length} -\NormalTok{measurements \textless{}{-}}\StringTok{ }\NormalTok{iris[,}\DecValTok{1}\OperatorTok{:}\DecValTok{4}\NormalTok{]} -\KeywordTok{head}\NormalTok{(measurements)} +\DocumentationTok{\#\# Separating the petal/sepal length} +\NormalTok{measurements }\OtherTok{\textless{}{-}}\NormalTok{ iris[,}\DecValTok{1}\SpecialCharTok{:}\DecValTok{4}\NormalTok{]} +\FunctionTok{head}\NormalTok{(measurements)} \end{Highlighting} \end{Shaded} @@ -8021,14 +7957,14 @@ \section{Data}\label{data}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Ordinating the data} -\NormalTok{ordination \textless{}{-}}\StringTok{ }\KeywordTok{prcomp}\NormalTok{(measurements)} +\DocumentationTok{\#\# Ordinating the data} +\NormalTok{ordination }\OtherTok{\textless{}{-}} \FunctionTok{prcomp}\NormalTok{(measurements)} -\CommentTok{\#\# The petal{-}space} -\NormalTok{petal\_space \textless{}{-}}\StringTok{ }\NormalTok{ordination}\OperatorTok{$}\NormalTok{x} +\DocumentationTok{\#\# The petal{-}space} +\NormalTok{petal\_space }\OtherTok{\textless{}{-}}\NormalTok{ ordination}\SpecialCharTok{$}\NormalTok{x} -\CommentTok{\#\# Adding the elements names to the petal{-}space (the individuals IDs)} -\KeywordTok{rownames}\NormalTok{(petal\_space) \textless{}{-}}\StringTok{ }\DecValTok{1}\OperatorTok{:}\KeywordTok{nrow}\NormalTok{(petal\_space)} +\DocumentationTok{\#\# Adding the elements names to the petal{-}space (the individuals IDs)} +\FunctionTok{rownames}\NormalTok{(petal\_space) }\OtherTok{\textless{}{-}} \DecValTok{1}\SpecialCharTok{:}\FunctionTok{nrow}\NormalTok{(petal\_space)} \end{Highlighting} \end{Shaded} @@ -8039,21 +7975,21 @@ \section{Classic analysis}\label{classic-analysis}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Measuring the variance on each axis} -\NormalTok{axis\_variances \textless{}{-}}\StringTok{ }\KeywordTok{apply}\NormalTok{(petal\_space, }\DecValTok{2}\NormalTok{, var)} -\NormalTok{axis\_variances \textless{}{-}}\StringTok{ }\NormalTok{axis\_variances}\OperatorTok{/}\KeywordTok{sum}\NormalTok{(axis\_variances)} +\DocumentationTok{\#\# Measuring the variance on each axis} +\NormalTok{axis\_variances }\OtherTok{\textless{}{-}} \FunctionTok{apply}\NormalTok{(petal\_space, }\DecValTok{2}\NormalTok{, var)} +\NormalTok{axis\_variances }\OtherTok{\textless{}{-}}\NormalTok{ axis\_variances}\SpecialCharTok{/}\FunctionTok{sum}\NormalTok{(axis\_variances)} -\CommentTok{\#\# Graphical option} -\KeywordTok{par}\NormalTok{(}\DataTypeTok{bty =} \StringTok{"n"}\NormalTok{)} +\DocumentationTok{\#\# Graphical option} +\FunctionTok{par}\NormalTok{(}\AttributeTok{bty =} \StringTok{"n"}\NormalTok{)} -\CommentTok{\#\# A classic 2D ordination plot} -\KeywordTok{plot}\NormalTok{(petal\_space[, }\DecValTok{1}\NormalTok{], petal\_space[, }\DecValTok{2}\NormalTok{], }\DataTypeTok{col =}\NormalTok{ species,} - \DataTypeTok{xlab =} \KeywordTok{paste0}\NormalTok{(}\StringTok{"PC 1 ("}\NormalTok{, }\KeywordTok{round}\NormalTok{(axis\_variances[}\DecValTok{1}\NormalTok{], }\DecValTok{2}\NormalTok{), }\StringTok{")"}\NormalTok{),} - \DataTypeTok{ylab =} \KeywordTok{paste0}\NormalTok{(}\StringTok{"PC 2 ("}\NormalTok{, }\KeywordTok{round}\NormalTok{(axis\_variances[}\DecValTok{2}\NormalTok{], }\DecValTok{2}\NormalTok{), }\StringTok{")"}\NormalTok{))} +\DocumentationTok{\#\# A classic 2D ordination plot} +\FunctionTok{plot}\NormalTok{(petal\_space[, }\DecValTok{1}\NormalTok{], petal\_space[, }\DecValTok{2}\NormalTok{], }\AttributeTok{col =}\NormalTok{ species,} + \AttributeTok{xlab =} \FunctionTok{paste0}\NormalTok{(}\StringTok{"PC 1 ("}\NormalTok{, }\FunctionTok{round}\NormalTok{(axis\_variances[}\DecValTok{1}\NormalTok{], }\DecValTok{2}\NormalTok{), }\StringTok{")"}\NormalTok{),} + \AttributeTok{ylab =} \FunctionTok{paste0}\NormalTok{(}\StringTok{"PC 2 ("}\NormalTok{, }\FunctionTok{round}\NormalTok{(axis\_variances[}\DecValTok{2}\NormalTok{], }\DecValTok{2}\NormalTok{), }\StringTok{")"}\NormalTok{))} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-216-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-224-1.pdf} This shows the distribution of the different species in the petal-space along the two first axis of variation. This is a pretty standard way to visualise the multidimensional space and further analysis might be necessary to test wether the groups are different such as a linear discriminant analysis (LDA). @@ -8062,14 +7998,14 @@ \section{Classic analysis}\label{classic-analysis}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Plotting the two second axis of the petal{-}space} -\KeywordTok{plot}\NormalTok{(petal\_space[, }\DecValTok{3}\NormalTok{], petal\_space[, }\DecValTok{4}\NormalTok{], }\DataTypeTok{col =}\NormalTok{ species,} - \DataTypeTok{xlab =} \KeywordTok{paste0}\NormalTok{(}\StringTok{"PC 3 ("}\NormalTok{, }\KeywordTok{round}\NormalTok{(axis\_variances[}\DecValTok{3}\NormalTok{], }\DecValTok{2}\NormalTok{), }\StringTok{")"}\NormalTok{),} - \DataTypeTok{ylab =} \KeywordTok{paste0}\NormalTok{(}\StringTok{"PC 4 ("}\NormalTok{, }\KeywordTok{round}\NormalTok{(axis\_variances[}\DecValTok{4}\NormalTok{], }\DecValTok{2}\NormalTok{), }\StringTok{")"}\NormalTok{))} +\DocumentationTok{\#\# Plotting the two second axis of the petal{-}space} +\FunctionTok{plot}\NormalTok{(petal\_space[, }\DecValTok{3}\NormalTok{], petal\_space[, }\DecValTok{4}\NormalTok{], }\AttributeTok{col =}\NormalTok{ species,} + \AttributeTok{xlab =} \FunctionTok{paste0}\NormalTok{(}\StringTok{"PC 3 ("}\NormalTok{, }\FunctionTok{round}\NormalTok{(axis\_variances[}\DecValTok{3}\NormalTok{], }\DecValTok{2}\NormalTok{), }\StringTok{")"}\NormalTok{),} + \AttributeTok{ylab =} \FunctionTok{paste0}\NormalTok{(}\StringTok{"PC 4 ("}\NormalTok{, }\FunctionTok{round}\NormalTok{(axis\_variances[}\DecValTok{4}\NormalTok{], }\DecValTok{2}\NormalTok{), }\StringTok{")"}\NormalTok{))} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-217-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-225-1.pdf} Additionally, these two represented dimensions do not represent a biological reality \emph{per se}; i.e.~the values on the first dimension do not represent a continuous trait (e.g.~petal length), instead they just represent the ordinations of correlations between the data and some factors. @@ -8083,13 +8019,13 @@ \section{\texorpdfstring{A multidimensional approach with \texttt{dispRity}}{A m \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Creating the table that contain the elements and their attributes} -\NormalTok{petal\_subsets \textless{}{-}}\StringTok{ }\KeywordTok{custom.subsets}\NormalTok{(petal\_space, }\DataTypeTok{group =} \KeywordTok{list}\NormalTok{(} - \StringTok{"setosa"}\NormalTok{ =}\StringTok{ }\KeywordTok{which}\NormalTok{(species }\OperatorTok{==}\StringTok{ "setosa"}\NormalTok{),} - \StringTok{"versicolor"}\NormalTok{ =}\StringTok{ }\KeywordTok{which}\NormalTok{(species }\OperatorTok{==}\StringTok{ "versicolor"}\NormalTok{),} - \StringTok{"virginica"}\NormalTok{ =}\StringTok{ }\KeywordTok{which}\NormalTok{(species }\OperatorTok{==}\StringTok{ "virginica"}\NormalTok{)))} +\DocumentationTok{\#\# Creating the table that contain the elements and their attributes} +\NormalTok{petal\_subsets }\OtherTok{\textless{}{-}} \FunctionTok{custom.subsets}\NormalTok{(petal\_space, }\AttributeTok{group =} \FunctionTok{list}\NormalTok{(} + \StringTok{"setosa"} \OtherTok{=} \FunctionTok{which}\NormalTok{(species }\SpecialCharTok{==} \StringTok{"setosa"}\NormalTok{),} + \StringTok{"versicolor"} \OtherTok{=} \FunctionTok{which}\NormalTok{(species }\SpecialCharTok{==} \StringTok{"versicolor"}\NormalTok{),} + \StringTok{"virginica"} \OtherTok{=} \FunctionTok{which}\NormalTok{(species }\SpecialCharTok{==} \StringTok{"virginica"}\NormalTok{)))} -\CommentTok{\#\# Visualising the dispRity object content} +\DocumentationTok{\#\# Visualising the dispRity object content} \NormalTok{petal\_subsets} \end{Highlighting} \end{Shaded} @@ -8110,8 +8046,8 @@ \subsection{Bootstrapping the data}\label{bootstrapping-the-data}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Bootstrapping the data} -\NormalTok{(petal\_bootstrapped \textless{}{-}}\StringTok{ }\KeywordTok{boot.matrix}\NormalTok{(petal\_subsets))} +\DocumentationTok{\#\# Bootstrapping the data} +\NormalTok{(petal\_bootstrapped }\OtherTok{\textless{}{-}} \FunctionTok{boot.matrix}\NormalTok{(petal\_subsets))} \end{Highlighting} \end{Shaded} @@ -8119,7 +8055,7 @@ \subsection{Bootstrapping the data}\label{bootstrapping-the-data}} ## ---- dispRity object ---- ## 3 customised subsets for 150 elements in one matrix with 4 dimensions: ## setosa, versicolor, virginica. -## Data was bootstrapped 100 times (method:"full"). +## Rows were bootstrapped 100 times (method:"full"). \end{verbatim} \hypertarget{calculating-disparity}{% @@ -8135,9 +8071,9 @@ \subsection{Calculating disparity}\label{calculating-disparity}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Calculating disparity as the median distance between each elements and} -\CommentTok{\#\# the centroid of the petal{-}space} -\NormalTok{(petal\_disparity \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(petal\_bootstrapped, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(median, centroids)))} +\DocumentationTok{\#\# Calculating disparity as the median distance between each elements and} +\DocumentationTok{\#\# the centroid of the petal{-}space} +\NormalTok{(petal\_disparity }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(petal\_bootstrapped, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(median, centroids)))} \end{Highlighting} \end{Shaded} @@ -8145,7 +8081,7 @@ \subsection{Calculating disparity}\label{calculating-disparity}} ## ---- dispRity object ---- ## 3 customised subsets for 150 elements in one matrix with 4 dimensions: ## setosa, versicolor, virginica. -## Data was bootstrapped 100 times (method:"full"). +## Rows were bootstrapped 100 times (method:"full"). ## Disparity was calculated as: c(median, centroids). \end{verbatim} @@ -8159,8 +8095,8 @@ \subsection{Summarising the results (plot)}\label{summarising-the-results-plot}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Displaying the summary of the calculated disparity} -\KeywordTok{summary}\NormalTok{(petal\_disparity)} +\DocumentationTok{\#\# Displaying the summary of the calculated disparity} +\FunctionTok{summary}\NormalTok{(petal\_disparity)} \end{Highlighting} \end{Shaded} @@ -8175,15 +8111,15 @@ \subsection{Summarising the results (plot)}\label{summarising-the-results-plot}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Graphical options} -\KeywordTok{par}\NormalTok{(}\DataTypeTok{bty =} \StringTok{"n"}\NormalTok{)} +\DocumentationTok{\#\# Graphical options} +\FunctionTok{par}\NormalTok{(}\AttributeTok{bty =} \StringTok{"n"}\NormalTok{)} -\CommentTok{\#\# Plotting the disparity in the petal\_space} -\KeywordTok{plot}\NormalTok{(petal\_disparity)} +\DocumentationTok{\#\# Plotting the disparity in the petal\_space} +\FunctionTok{plot}\NormalTok{(petal\_disparity)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-222-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-230-1.pdf} Now contrary to simply plotting the two first axis of the PCA where we saw that the species have a different position in the two first petal-space, we can now also see that they occupy this space clearly differently! @@ -8194,8 +8130,8 @@ \subsection{Testing hypothesis}\label{testing-hypothesis}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Running a PERMANOVA} -\KeywordTok{test.dispRity}\NormalTok{(petal\_disparity, }\DataTypeTok{test =}\NormalTok{ adonis.dispRity)} +\DocumentationTok{\#\# Running a PERMANOVA} +\FunctionTok{test.dispRity}\NormalTok{(petal\_disparity, }\AttributeTok{test =}\NormalTok{ adonis.dispRity)} \end{Highlighting} \end{Shaded} @@ -8212,13 +8148,12 @@ \subsection{Testing hypothesis}\label{testing-hypothesis}} \begin{verbatim} ## Permutation test for adonis under reduced model -## Terms added sequentially (first to last) ## Permutation: free ## Number of permutations: 999 ## ## vegan::adonis2(formula = dist(matrix) ~ group, method = "euclidean") ## Df SumOfSqs R2 F Pr(>F) -## group 2 592.07 0.86894 487.33 0.001 *** +## Model 2 592.07 0.86894 487.33 0.001 *** ## Residual 147 89.30 0.13106 ## Total 149 681.37 1.00000 ## --- @@ -8227,8 +8162,8 @@ \subsection{Testing hypothesis}\label{testing-hypothesis}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Post{-}hoc testing of the differences between species (corrected for multiple tests)} -\KeywordTok{test.dispRity}\NormalTok{(petal\_disparity, }\DataTypeTok{test =}\NormalTok{ t.test, }\DataTypeTok{correction =} \StringTok{"bonferroni"}\NormalTok{)} +\DocumentationTok{\#\# Post{-}hoc testing of the differences between species (corrected for multiple tests)} +\FunctionTok{test.dispRity}\NormalTok{(petal\_disparity, }\AttributeTok{test =}\NormalTok{ t.test, }\AttributeTok{correction =} \StringTok{"bonferroni"}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -8268,25 +8203,25 @@ \subsubsection{Setting up a multidimensional null-hypothesis}\label{setting-up-a \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Testing against a uniform distribution} -\NormalTok{disparity\_uniform \textless{}{-}}\StringTok{ }\KeywordTok{null.test}\NormalTok{(petal\_disparity, }\DataTypeTok{replicates =} \DecValTok{200}\NormalTok{,} - \DataTypeTok{null.distrib =}\NormalTok{ runif, }\DataTypeTok{scale =} \OtherTok{FALSE}\NormalTok{)} -\KeywordTok{plot}\NormalTok{(disparity\_uniform)} +\DocumentationTok{\#\# Testing against a uniform distribution} +\NormalTok{disparity\_uniform }\OtherTok{\textless{}{-}} \FunctionTok{null.test}\NormalTok{(petal\_disparity, }\AttributeTok{replicates =} \DecValTok{200}\NormalTok{,} + \AttributeTok{null.distrib =}\NormalTok{ runif, }\AttributeTok{scale =} \ConstantTok{FALSE}\NormalTok{)} +\FunctionTok{plot}\NormalTok{(disparity\_uniform)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-224-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-232-1.pdf} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Testing against a normal distribution} -\NormalTok{disparity\_normal \textless{}{-}}\StringTok{ }\KeywordTok{null.test}\NormalTok{(petal\_disparity, }\DataTypeTok{replicates =} \DecValTok{200}\NormalTok{,} - \DataTypeTok{null.distrib =}\NormalTok{ rnorm, }\DataTypeTok{scale =} \OtherTok{TRUE}\NormalTok{)} -\KeywordTok{plot}\NormalTok{(disparity\_normal)} +\DocumentationTok{\#\# Testing against a normal distribution} +\NormalTok{disparity\_normal }\OtherTok{\textless{}{-}} \FunctionTok{null.test}\NormalTok{(petal\_disparity, }\AttributeTok{replicates =} \DecValTok{200}\NormalTok{,} + \AttributeTok{null.distrib =}\NormalTok{ rnorm, }\AttributeTok{scale =} \ConstantTok{TRUE}\NormalTok{)} +\FunctionTok{plot}\NormalTok{(disparity\_normal)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-225-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-233-1.pdf} In both cases we can see that our petal-space is not entirely normal or uniform. This is expected because of the simplicity of these parameters. @@ -8311,32 +8246,32 @@ \subsection{The morphospace}\label{the-morphospace}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Loading demo and the package data} -\KeywordTok{library}\NormalTok{(dispRity)} +\DocumentationTok{\#\# Loading demo and the package data} +\FunctionTok{library}\NormalTok{(dispRity)} -\CommentTok{\#\# Setting the random seed for repeatability} -\KeywordTok{set.seed}\NormalTok{(}\DecValTok{123}\NormalTok{)} +\DocumentationTok{\#\# Setting the random seed for repeatability} +\FunctionTok{set.seed}\NormalTok{(}\DecValTok{123}\NormalTok{)} -\CommentTok{\#\# Loading the ordinated matrix/morphospace:} -\KeywordTok{data}\NormalTok{(BeckLee\_mat50)} -\KeywordTok{data}\NormalTok{(BeckLee\_mat99)} -\KeywordTok{head}\NormalTok{(BeckLee\_mat50[,}\DecValTok{1}\OperatorTok{:}\DecValTok{5}\NormalTok{])} +\DocumentationTok{\#\# Loading the ordinated matrix/morphospace:} +\FunctionTok{data}\NormalTok{(BeckLee\_mat50)} +\FunctionTok{data}\NormalTok{(BeckLee\_mat99)} +\FunctionTok{head}\NormalTok{(BeckLee\_mat50[,}\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{])} \end{Highlighting} \end{Shaded} \begin{verbatim} -## [,1] [,2] [,3] [,4] [,5] -## Cimolestes -0.5613001 0.06006259 0.08414761 -0.2313084 -0.18825039 -## Maelestes -0.4186019 -0.12186005 0.25556379 0.2737995 -0.28510479 -## Batodon -0.8337640 0.28718501 -0.10594610 -0.2381511 -0.07132646 -## Bulaklestes -0.7708261 -0.07629583 0.04549285 -0.4951160 -0.39962626 -## Daulestes -0.8320466 -0.09559563 0.04336661 -0.5792351 -0.37385914 -## Uchkudukodon -0.5074468 -0.34273248 0.40410310 -0.1223782 -0.34857351 +## [,1] [,2] [,3] [,4] [,5] +## Cimolestes -0.5613001 0.06006259 0.08414761 -0.2313084 0.18825039 +## Maelestes -0.4186019 -0.12186005 0.25556379 0.2737995 0.28510479 +## Batodon -0.8337640 0.28718501 -0.10594610 -0.2381511 0.07132646 +## Bulaklestes -0.7708261 -0.07629583 0.04549285 -0.4951160 0.39962626 +## Daulestes -0.8320466 -0.09559563 0.04336661 -0.5792351 0.37385914 +## Uchkudukodon -0.5074468 -0.34273248 0.40410310 -0.1223782 0.34857351 \end{verbatim} \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{dim}\NormalTok{(BeckLee\_mat50)} +\FunctionTok{dim}\NormalTok{(BeckLee\_mat50)} \end{Highlighting} \end{Shaded} @@ -8346,11 +8281,11 @@ \subsection{The morphospace}\label{the-morphospace}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The morphospace contains 50 taxa and has 48 dimensions (or axes)} +\DocumentationTok{\#\# The morphospace contains 50 taxa and has 48 dimensions (or axes)} -\CommentTok{\#\# Showing a list of first and last occurrences data for some fossils} -\KeywordTok{data}\NormalTok{(BeckLee\_ages)} -\KeywordTok{head}\NormalTok{(BeckLee\_ages)} +\DocumentationTok{\#\# Showing a list of first and last occurrences data for some fossils} +\FunctionTok{data}\NormalTok{(BeckLee\_ages)} +\FunctionTok{head}\NormalTok{(BeckLee\_ages)} \end{Highlighting} \end{Shaded} @@ -8366,14 +8301,14 @@ \subsection{The morphospace}\label{the-morphospace}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Plotting a phylogeny} -\KeywordTok{data}\NormalTok{(BeckLee\_tree)} -\KeywordTok{plot}\NormalTok{(BeckLee\_tree, }\DataTypeTok{cex =} \FloatTok{0.7}\NormalTok{)} -\KeywordTok{axisPhylo}\NormalTok{(}\DataTypeTok{root =} \DecValTok{140}\NormalTok{)} +\DocumentationTok{\#\# Plotting a phylogeny} +\FunctionTok{data}\NormalTok{(BeckLee\_tree)} +\FunctionTok{plot}\NormalTok{(BeckLee\_tree, }\AttributeTok{cex =} \FloatTok{0.7}\NormalTok{)} +\FunctionTok{axisPhylo}\NormalTok{(}\AttributeTok{root =} \DecValTok{140}\NormalTok{)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-226-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-234-1.pdf} \begin{quote} You can have an even nicer looking tree if you use the \texttt{strap} package! @@ -8381,12 +8316,12 @@ \subsection{The morphospace}\label{the-morphospace}} \begin{Shaded} \begin{Highlighting}[] -\ControlFlowTok{if}\NormalTok{(}\OperatorTok{!}\KeywordTok{require}\NormalTok{(strap)) }\KeywordTok{install.packages}\NormalTok{(}\StringTok{"strap"}\NormalTok{)} -\NormalTok{strap}\OperatorTok{::}\KeywordTok{geoscalePhylo}\NormalTok{(BeckLee\_tree, }\DataTypeTok{cex.tip =} \FloatTok{0.7}\NormalTok{, }\DataTypeTok{cex.ts =} \FloatTok{0.6}\NormalTok{)} +\ControlFlowTok{if}\NormalTok{(}\SpecialCharTok{!}\FunctionTok{require}\NormalTok{(strap)) }\FunctionTok{install.packages}\NormalTok{(}\StringTok{"strap"}\NormalTok{)} +\NormalTok{strap}\SpecialCharTok{::}\FunctionTok{geoscalePhylo}\NormalTok{(BeckLee\_tree, }\AttributeTok{cex.tip =} \FloatTok{0.7}\NormalTok{, }\AttributeTok{cex.ts =} \FloatTok{0.6}\NormalTok{)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-227-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-235-1.pdf} \hypertarget{setting-up-your-own-data}{% \subsection{Setting up your own data}\label{setting-up-your-own-data}} @@ -8427,39 +8362,39 @@ \subsection{Setting up your own data}\label{setting-up-your-own-data}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Functions to get simulate a PCO looking like matrix from a tree} -\NormalTok{i.need.a.matrix \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(tree) \{} -\NormalTok{ matrix \textless{}{-}}\StringTok{ }\KeywordTok{space.maker}\NormalTok{(}\DataTypeTok{elements =} \KeywordTok{Ntip}\NormalTok{(tree), }\DataTypeTok{dimensions =} \KeywordTok{Ntip}\NormalTok{(tree), }\DataTypeTok{distribution =}\NormalTok{ rnorm,} - \DataTypeTok{scree =} \KeywordTok{rev}\NormalTok{(}\KeywordTok{cumsum}\NormalTok{(}\KeywordTok{rep}\NormalTok{(}\DecValTok{1}\OperatorTok{/}\KeywordTok{Ntip}\NormalTok{(tree), }\KeywordTok{Ntip}\NormalTok{(tree)))))} - \KeywordTok{rownames}\NormalTok{(matrix) \textless{}{-}}\StringTok{ }\NormalTok{tree}\OperatorTok{$}\NormalTok{tip.label} - \KeywordTok{return}\NormalTok{(matrix)} +\DocumentationTok{\#\# Functions to get simulate a PCO looking like matrix from a tree} +\NormalTok{i.need.a.matrix }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(tree) \{} +\NormalTok{ matrix }\OtherTok{\textless{}{-}} \FunctionTok{space.maker}\NormalTok{(}\AttributeTok{elements =} \FunctionTok{Ntip}\NormalTok{(tree), }\AttributeTok{dimensions =} \FunctionTok{Ntip}\NormalTok{(tree), }\AttributeTok{distribution =}\NormalTok{ rnorm,} + \AttributeTok{scree =} \FunctionTok{rev}\NormalTok{(}\FunctionTok{cumsum}\NormalTok{(}\FunctionTok{rep}\NormalTok{(}\DecValTok{1}\SpecialCharTok{/}\FunctionTok{Ntip}\NormalTok{(tree), }\FunctionTok{Ntip}\NormalTok{(tree)))))} + \FunctionTok{rownames}\NormalTok{(matrix) }\OtherTok{\textless{}{-}}\NormalTok{ tree}\SpecialCharTok{$}\NormalTok{tip.label} + \FunctionTok{return}\NormalTok{(matrix)} \NormalTok{\}} -\CommentTok{\#\# Function to simulate a tree} -\NormalTok{i.need.a.tree \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(matrix) \{} -\NormalTok{ tree \textless{}{-}}\StringTok{ }\KeywordTok{rtree}\NormalTok{(}\KeywordTok{nrow}\NormalTok{(matrix))} -\NormalTok{ tree}\OperatorTok{$}\NormalTok{root.time \textless{}{-}}\StringTok{ }\KeywordTok{max}\NormalTok{(}\KeywordTok{tree.age}\NormalTok{(tree)}\OperatorTok{$}\NormalTok{age)} -\NormalTok{ tree}\OperatorTok{$}\NormalTok{tip.label \textless{}{-}}\StringTok{ }\KeywordTok{rownames}\NormalTok{(matrix)} -\NormalTok{ tree}\OperatorTok{$}\NormalTok{node.label \textless{}{-}}\StringTok{ }\KeywordTok{paste0}\NormalTok{(}\StringTok{"n"}\NormalTok{, }\DecValTok{1}\OperatorTok{:}\NormalTok{(}\KeywordTok{nrow}\NormalTok{(matrix)}\OperatorTok{{-}}\DecValTok{1}\NormalTok{))} - \KeywordTok{return}\NormalTok{(tree)} +\DocumentationTok{\#\# Function to simulate a tree} +\NormalTok{i.need.a.tree }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(matrix) \{} +\NormalTok{ tree }\OtherTok{\textless{}{-}} \FunctionTok{rtree}\NormalTok{(}\FunctionTok{nrow}\NormalTok{(matrix))} +\NormalTok{ tree}\SpecialCharTok{$}\NormalTok{root.time }\OtherTok{\textless{}{-}} \FunctionTok{max}\NormalTok{(}\FunctionTok{tree.age}\NormalTok{(tree)}\SpecialCharTok{$}\NormalTok{age)} +\NormalTok{ tree}\SpecialCharTok{$}\NormalTok{tip.label }\OtherTok{\textless{}{-}} \FunctionTok{rownames}\NormalTok{(matrix)} +\NormalTok{ tree}\SpecialCharTok{$}\NormalTok{node.label }\OtherTok{\textless{}{-}} \FunctionTok{paste0}\NormalTok{(}\StringTok{"n"}\NormalTok{, }\DecValTok{1}\SpecialCharTok{:}\NormalTok{(}\FunctionTok{nrow}\NormalTok{(matrix)}\SpecialCharTok{{-}}\DecValTok{1}\NormalTok{))} + \FunctionTok{return}\NormalTok{(tree)} \NormalTok{\}} -\CommentTok{\#\# Function to simulate some "node" data} -\NormalTok{i.need.node.data \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(matrix, tree) \{} -\NormalTok{ matrix\_node \textless{}{-}}\StringTok{ }\KeywordTok{space.maker}\NormalTok{(}\DataTypeTok{elements =} \KeywordTok{Nnode}\NormalTok{(tree), }\DataTypeTok{dimensions =} \KeywordTok{ncol}\NormalTok{(matrix),} - \DataTypeTok{distribution =}\NormalTok{ rnorm, }\DataTypeTok{scree =} \KeywordTok{apply}\NormalTok{(matrix, }\DecValTok{2}\NormalTok{, var))} - \ControlFlowTok{if}\NormalTok{(}\OperatorTok{!}\KeywordTok{is.null}\NormalTok{(tree}\OperatorTok{$}\NormalTok{node.label)) \{} - \KeywordTok{rownames}\NormalTok{(matrix\_node) \textless{}{-}}\StringTok{ }\NormalTok{tree}\OperatorTok{$}\NormalTok{node.label} +\DocumentationTok{\#\# Function to simulate some "node" data} +\NormalTok{i.need.node.data }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(matrix, tree) \{} +\NormalTok{ matrix\_node }\OtherTok{\textless{}{-}} \FunctionTok{space.maker}\NormalTok{(}\AttributeTok{elements =} \FunctionTok{Nnode}\NormalTok{(tree), }\AttributeTok{dimensions =} \FunctionTok{ncol}\NormalTok{(matrix),} + \AttributeTok{distribution =}\NormalTok{ rnorm, }\AttributeTok{scree =} \FunctionTok{apply}\NormalTok{(matrix, }\DecValTok{2}\NormalTok{, var))} + \ControlFlowTok{if}\NormalTok{(}\SpecialCharTok{!}\FunctionTok{is.null}\NormalTok{(tree}\SpecialCharTok{$}\NormalTok{node.label)) \{} + \FunctionTok{rownames}\NormalTok{(matrix\_node) }\OtherTok{\textless{}{-}}\NormalTok{ tree}\SpecialCharTok{$}\NormalTok{node.label} \NormalTok{ \} }\ControlFlowTok{else}\NormalTok{ \{} - \KeywordTok{rownames}\NormalTok{(matrix\_node) \textless{}{-}}\StringTok{ }\KeywordTok{paste0}\NormalTok{(}\StringTok{"n"}\NormalTok{, }\DecValTok{1}\OperatorTok{:}\NormalTok{(}\KeywordTok{nrow}\NormalTok{(matrix)}\OperatorTok{{-}}\DecValTok{1}\NormalTok{))} + \FunctionTok{rownames}\NormalTok{(matrix\_node) }\OtherTok{\textless{}{-}} \FunctionTok{paste0}\NormalTok{(}\StringTok{"n"}\NormalTok{, }\DecValTok{1}\SpecialCharTok{:}\NormalTok{(}\FunctionTok{nrow}\NormalTok{(matrix)}\SpecialCharTok{{-}}\DecValTok{1}\NormalTok{))} \NormalTok{ \}} - \KeywordTok{return}\NormalTok{(}\KeywordTok{rbind}\NormalTok{(matrix, matrix\_node))} + \FunctionTok{return}\NormalTok{(}\FunctionTok{rbind}\NormalTok{(matrix, matrix\_node))} \NormalTok{\}} -\CommentTok{\#\# Function to simulate some "FADLAD" data} -\NormalTok{i.need.FADLAD \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(tree) \{} -\NormalTok{ tree\_ages \textless{}{-}}\StringTok{ }\KeywordTok{tree.age}\NormalTok{(tree)[}\DecValTok{1}\OperatorTok{:}\KeywordTok{Ntip}\NormalTok{(tree),]} - \KeywordTok{return}\NormalTok{(}\KeywordTok{data.frame}\NormalTok{(}\DataTypeTok{FAD =}\NormalTok{ tree\_ages[,}\DecValTok{1}\NormalTok{], }\DataTypeTok{LAD =}\NormalTok{ tree\_ages[,}\DecValTok{1}\NormalTok{], }\DataTypeTok{row.names =}\NormalTok{ tree\_ages[,}\DecValTok{2}\NormalTok{]))} +\DocumentationTok{\#\# Function to simulate some "FADLAD" data} +\NormalTok{i.need.FADLAD }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(tree) \{} +\NormalTok{ tree\_ages }\OtherTok{\textless{}{-}} \FunctionTok{tree.age}\NormalTok{(tree)[}\DecValTok{1}\SpecialCharTok{:}\FunctionTok{Ntip}\NormalTok{(tree),]} + \FunctionTok{return}\NormalTok{(}\FunctionTok{data.frame}\NormalTok{(}\AttributeTok{FAD =}\NormalTok{ tree\_ages[,}\DecValTok{1}\NormalTok{], }\AttributeTok{LAD =}\NormalTok{ tree\_ages[,}\DecValTok{1}\NormalTok{], }\AttributeTok{row.names =}\NormalTok{ tree\_ages[,}\DecValTok{2}\NormalTok{]))} \NormalTok{\}} \end{Highlighting} \end{Shaded} @@ -8468,9 +8403,9 @@ \subsection{Setting up your own data}\label{setting-up-your-own-data}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Aaaaah I don\textquotesingle{}t have FADLAD data!} -\NormalTok{my\_FADLAD \textless{}{-}}\StringTok{ }\KeywordTok{i.need.FADLAD}\NormalTok{(tree)} -\CommentTok{\#\# Sorted.} +\DocumentationTok{\#\# Aaaaah I don\textquotesingle{}t have FADLAD data!} +\NormalTok{my\_FADLAD }\OtherTok{\textless{}{-}} \FunctionTok{i.need.FADLAD}\NormalTok{(tree)} +\DocumentationTok{\#\# Sorted.} \end{Highlighting} \end{Shaded} @@ -8478,17 +8413,17 @@ \subsection{Setting up your own data}\label{setting-up-your-own-data}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# A matrix with tip data} -\NormalTok{my\_matrix \textless{}{-}}\StringTok{ }\NormalTok{BeckLee\_mat50} +\DocumentationTok{\#\# A matrix with tip data} +\NormalTok{my\_matrix }\OtherTok{\textless{}{-}}\NormalTok{ BeckLee\_mat50} -\CommentTok{\#\# A phylogenetic tree } -\NormalTok{my\_tree \textless{}{-}}\StringTok{ }\NormalTok{BeckLee\_tree} +\DocumentationTok{\#\# A phylogenetic tree } +\NormalTok{my\_tree }\OtherTok{\textless{}{-}}\NormalTok{ BeckLee\_tree} -\CommentTok{\#\# A matrix with tip and node data} -\NormalTok{my\_tip\_node\_matrix \textless{}{-}}\StringTok{ }\NormalTok{BeckLee\_mat99} +\DocumentationTok{\#\# A matrix with tip and node data} +\NormalTok{my\_tip\_node\_matrix }\OtherTok{\textless{}{-}}\NormalTok{ BeckLee\_mat99} -\CommentTok{\#\# A table of first and last occurrences data (FADLAD)} -\NormalTok{my\_fadlad \textless{}{-}}\StringTok{ }\NormalTok{BeckLee\_ages} +\DocumentationTok{\#\# A table of first and last occurrences data (FADLAD)} +\NormalTok{my\_fadlad }\OtherTok{\textless{}{-}}\NormalTok{ BeckLee\_ages} \end{Highlighting} \end{Shaded} @@ -8507,13 +8442,13 @@ \subsection{Splitting the morphospace through time}\label{splitting-the-morphosp \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Creating the vector of time bins ages} -\NormalTok{time\_bins \textless{}{-}}\StringTok{ }\KeywordTok{rev}\NormalTok{(}\KeywordTok{seq}\NormalTok{(}\DataTypeTok{from =} \DecValTok{0}\NormalTok{, }\DataTypeTok{to =} \DecValTok{100}\NormalTok{, }\DataTypeTok{by =} \DecValTok{20}\NormalTok{))} +\DocumentationTok{\#\# Creating the vector of time bins ages} +\NormalTok{time\_bins }\OtherTok{\textless{}{-}} \FunctionTok{rev}\NormalTok{(}\FunctionTok{seq}\NormalTok{(}\AttributeTok{from =} \DecValTok{0}\NormalTok{, }\AttributeTok{to =} \DecValTok{100}\NormalTok{, }\AttributeTok{by =} \DecValTok{20}\NormalTok{))} -\CommentTok{\#\# Splitting the morphospace using the chrono.subsets function} -\NormalTok{binned\_morphospace \textless{}{-}}\StringTok{ }\KeywordTok{chrono.subsets}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ my\_matrix, }\DataTypeTok{tree =}\NormalTok{ my\_tree,} - \DataTypeTok{method =} \StringTok{"discrete"}\NormalTok{, }\DataTypeTok{time =}\NormalTok{ time\_bins, }\DataTypeTok{inc.nodes =} \OtherTok{FALSE}\NormalTok{,} - \DataTypeTok{FADLAD =}\NormalTok{ my\_fadlad)} +\DocumentationTok{\#\# Splitting the morphospace using the chrono.subsets function} +\NormalTok{binned\_morphospace }\OtherTok{\textless{}{-}} \FunctionTok{chrono.subsets}\NormalTok{(}\AttributeTok{data =}\NormalTok{ my\_matrix, }\AttributeTok{tree =}\NormalTok{ my\_tree,} + \AttributeTok{method =} \StringTok{"discrete"}\NormalTok{, }\AttributeTok{time =}\NormalTok{ time\_bins, }\AttributeTok{inc.nodes =} \ConstantTok{FALSE}\NormalTok{,} + \AttributeTok{FADLAD =}\NormalTok{ my\_fadlad)} \end{Highlighting} \end{Shaded} @@ -8523,8 +8458,8 @@ \subsection{Splitting the morphospace through time}\label{splitting-the-morphosp \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Printing the class of the object} -\KeywordTok{class}\NormalTok{(binned\_morphospace)} +\DocumentationTok{\#\# Printing the class of the object} +\FunctionTok{class}\NormalTok{(binned\_morphospace)} \end{Highlighting} \end{Shaded} @@ -8534,8 +8469,8 @@ \subsection{Splitting the morphospace through time}\label{splitting-the-morphosp \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Printing the content of the object} -\KeywordTok{str}\NormalTok{(binned\_morphospace)} +\DocumentationTok{\#\# Printing the content of the object} +\FunctionTok{str}\NormalTok{(binned\_morphospace)} \end{Highlighting} \end{Shaded} @@ -8576,7 +8511,7 @@ \subsection{Splitting the morphospace through time}\label{splitting-the-morphosp \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{names}\NormalTok{(binned\_morphospace)} +\FunctionTok{names}\NormalTok{(binned\_morphospace)} \end{Highlighting} \end{Shaded} @@ -8586,7 +8521,7 @@ \subsection{Splitting the morphospace through time}\label{splitting-the-morphosp \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Printing the object as a dispRity class} +\DocumentationTok{\#\# Printing the object as a dispRity class} \NormalTok{binned\_morphospace} \end{Highlighting} \end{Shaded} @@ -8610,12 +8545,12 @@ \subsection{Bootstrapping the data}\label{bootstrapping-the-data-1}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Getting the minimum number of rows (i.e. taxa) in the time subsets} -\NormalTok{minimum\_size \textless{}{-}}\StringTok{ }\KeywordTok{min}\NormalTok{(}\KeywordTok{size.subsets}\NormalTok{(binned\_morphospace))} +\DocumentationTok{\#\# Getting the minimum number of rows (i.e. taxa) in the time subsets} +\NormalTok{minimum\_size }\OtherTok{\textless{}{-}} \FunctionTok{min}\NormalTok{(}\FunctionTok{size.subsets}\NormalTok{(binned\_morphospace))} -\CommentTok{\#\# Bootstrapping each time subset 100 times and rarefying them } -\NormalTok{rare\_bin\_morphospace \textless{}{-}}\StringTok{ }\KeywordTok{boot.matrix}\NormalTok{(binned\_morphospace, }\DataTypeTok{bootstraps =} \DecValTok{100}\NormalTok{,} - \DataTypeTok{rarefaction =}\NormalTok{ minimum\_size)} +\DocumentationTok{\#\# Bootstrapping each time subset 100 times and rarefying them } +\NormalTok{rare\_bin\_morphospace }\OtherTok{\textless{}{-}} \FunctionTok{boot.matrix}\NormalTok{(binned\_morphospace, }\AttributeTok{bootstraps =} \DecValTok{100}\NormalTok{,} + \AttributeTok{rarefaction =}\NormalTok{ minimum\_size)} \end{Highlighting} \end{Shaded} @@ -8643,29 +8578,29 @@ \subsection{Calculating disparity}\label{calculating-disparity-1}} \begin{Shaded} \begin{Highlighting}[] -\NormalTok{my\_test \textless{}{-}}\StringTok{ }\KeywordTok{test.metric}\NormalTok{(my\_matrix, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, dispRity}\OperatorTok{::}\NormalTok{variances), }\DataTypeTok{shifts =} \KeywordTok{c}\NormalTok{(}\StringTok{"random"}\NormalTok{, }\StringTok{"size"}\NormalTok{))} -\KeywordTok{summary}\NormalTok{(my\_test)} +\NormalTok{my\_test }\OtherTok{\textless{}{-}} \FunctionTok{test.metric}\NormalTok{(my\_matrix, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, dispRity}\SpecialCharTok{::}\NormalTok{variances), }\AttributeTok{shifts =} \FunctionTok{c}\NormalTok{(}\StringTok{"random"}\NormalTok{, }\StringTok{"size"}\NormalTok{))} +\FunctionTok{summary}\NormalTok{(my\_test)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% slope -## random 2.41 2.51 2.56 2.50 2.54 2.51 2.52 2.53 2.53 2.52 0.0006434981 -## size.increase 2.23 2.19 2.25 2.33 2.31 2.35 2.43 2.44 2.48 2.52 0.0036071419 -## size.hollowness 2.40 2.56 2.56 2.60 2.63 2.64 2.60 2.58 2.55 2.52 0.0006032204 +## random 2.53 2.50 2.56 2.50 2.54 2.51 2.52 2.53 2.53 2.52 0.0003234646 +## size.increase 2.23 2.17 2.25 2.26 2.31 2.35 2.39 2.47 2.50 2.52 0.0037712409 +## size.hollowness 2.40 2.50 2.59 2.65 2.63 2.62 2.60 2.57 2.55 2.52 0.0008954035 ## p_value R^2(adj) -## random 3.046683e-02 0.12638784 -## size.increase 4.009847e-16 0.90601561 -## size.hollowness 1.324664e-01 0.04783366 +## random 9.689431e-02 0.06301936 +## size.increase 1.016309e-17 0.93443767 +## size.hollowness 6.630162e-02 0.08377594 \end{verbatim} \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{plot}\NormalTok{(my\_test)} +\FunctionTok{plot}\NormalTok{(my\_test)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-234-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-242-1.pdf} We see that changes in the inner size (see \citet{moms} for more details) is actually picked up by the sum of variances but not random changes or outer changes. Which is a good thing! @@ -8677,8 +8612,8 @@ \subsection{Calculating disparity}\label{calculating-disparity-1}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Calculating disparity for the bootstrapped and rarefied data} -\NormalTok{disparity \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(rare\_bin\_morphospace , }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, dispRity}\OperatorTok{::}\NormalTok{variances))} +\DocumentationTok{\#\# Calculating disparity for the bootstrapped and rarefied data} +\NormalTok{disparity }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(rare\_bin\_morphospace , }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, dispRity}\SpecialCharTok{::}\NormalTok{variances))} \end{Highlighting} \end{Shaded} @@ -8687,8 +8622,8 @@ \subsection{Calculating disparity}\label{calculating-disparity-1}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Summarising the disparity results} -\KeywordTok{summary}\NormalTok{(disparity)} +\DocumentationTok{\#\# Summarising the disparity results} +\FunctionTok{summary}\NormalTok{(disparity)} \end{Highlighting} \end{Shaded} @@ -8717,8 +8652,8 @@ \subsection{Plotting the results}\label{plotting-the-results}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Graphical options} -\KeywordTok{quartz}\NormalTok{(}\DataTypeTok{width =} \DecValTok{10}\NormalTok{, }\DataTypeTok{height =} \DecValTok{5}\NormalTok{) ; }\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =}\NormalTok{ (}\KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{)), }\DataTypeTok{bty =} \StringTok{"n"}\NormalTok{)} +\DocumentationTok{\#\# Graphical options} +\FunctionTok{quartz}\NormalTok{(}\AttributeTok{width =} \DecValTok{10}\NormalTok{, }\AttributeTok{height =} \DecValTok{5}\NormalTok{) ; }\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =}\NormalTok{ (}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{)), }\AttributeTok{bty =} \StringTok{"n"}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -8729,14 +8664,14 @@ \subsection{Plotting the results}\label{plotting-the-results}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Plotting the bootstrapped and rarefied results} -\KeywordTok{plot}\NormalTok{(disparity, }\DataTypeTok{type =} \StringTok{"continuous"}\NormalTok{, }\DataTypeTok{main =} \StringTok{"bootstrapped results"}\NormalTok{)} -\KeywordTok{plot}\NormalTok{(disparity, }\DataTypeTok{type =} \StringTok{"continuous"}\NormalTok{, }\DataTypeTok{main =} \StringTok{"rarefied results"}\NormalTok{,} - \DataTypeTok{rarefaction =}\NormalTok{ minimum\_size)} +\DocumentationTok{\#\# Plotting the bootstrapped and rarefied results} +\FunctionTok{plot}\NormalTok{(disparity, }\AttributeTok{type =} \StringTok{"continuous"}\NormalTok{, }\AttributeTok{main =} \StringTok{"bootstrapped results"}\NormalTok{)} +\FunctionTok{plot}\NormalTok{(disparity, }\AttributeTok{type =} \StringTok{"continuous"}\NormalTok{, }\AttributeTok{main =} \StringTok{"rarefied results"}\NormalTok{,} + \AttributeTok{rarefaction =}\NormalTok{ minimum\_size)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-237-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-245-1.pdf} Nice. The curves look pretty similar. @@ -8755,9 +8690,9 @@ \subsection{Testing differences}\label{testing-differences}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Testing the differences between bins in the bootstrapped dataset.} -\KeywordTok{test.dispRity}\NormalTok{(disparity, }\DataTypeTok{test =}\NormalTok{ wilcox.test, }\DataTypeTok{comparison =} \StringTok{"sequential"}\NormalTok{,} - \DataTypeTok{correction =} \StringTok{"bonferroni"}\NormalTok{)} +\DocumentationTok{\#\# Testing the differences between bins in the bootstrapped dataset.} +\FunctionTok{test.dispRity}\NormalTok{(disparity, }\AttributeTok{test =}\NormalTok{ wilcox.test, }\AttributeTok{comparison =} \StringTok{"sequential"}\NormalTok{,} + \AttributeTok{correction =} \StringTok{"bonferroni"}\NormalTok{)} \end{Highlighting} \end{Shaded} @@ -8779,9 +8714,9 @@ \subsection{Testing differences}\label{testing-differences}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Testing the differences between bins in the rarefied dataset.} -\KeywordTok{test.dispRity}\NormalTok{(disparity, }\DataTypeTok{test =}\NormalTok{ wilcox.test, }\DataTypeTok{comparison =} \StringTok{"sequential"}\NormalTok{,} - \DataTypeTok{correction =} \StringTok{"bonferroni"}\NormalTok{, }\DataTypeTok{rarefaction =}\NormalTok{ minimum\_size)} +\DocumentationTok{\#\# Testing the differences between bins in the rarefied dataset.} +\FunctionTok{test.dispRity}\NormalTok{(disparity, }\AttributeTok{test =}\NormalTok{ wilcox.test, }\AttributeTok{comparison =} \StringTok{"sequential"}\NormalTok{,} + \AttributeTok{correction =} \StringTok{"bonferroni"}\NormalTok{, }\AttributeTok{rarefaction =}\NormalTok{ minimum\_size)} \end{Highlighting} \end{Shaded} @@ -8838,14 +8773,14 @@ \section{Before starting}\label{before-starting-1}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Loading geomorph} -\KeywordTok{library}\NormalTok{(geomorph)} +\DocumentationTok{\#\# Loading geomorph} +\FunctionTok{library}\NormalTok{(geomorph)} -\CommentTok{\#\# Loading the plethodon dataset} -\KeywordTok{data}\NormalTok{(plethodon)} +\DocumentationTok{\#\# Loading the plethodon dataset} +\FunctionTok{data}\NormalTok{(plethodon)} -\CommentTok{\#\# Running a simple Procrustes superimposition} -\NormalTok{gpa\_plethodon \textless{}{-}}\StringTok{ }\KeywordTok{gpagen}\NormalTok{(plethodon}\OperatorTok{$}\NormalTok{land)} +\DocumentationTok{\#\# Running a simple Procrustes superimposition} +\NormalTok{gpa\_plethodon }\OtherTok{\textless{}{-}} \FunctionTok{gpagen}\NormalTok{(plethodon}\SpecialCharTok{$}\NormalTok{land)} \end{Highlighting} \end{Shaded} @@ -8859,10 +8794,10 @@ \section{Before starting}\label{before-starting-1}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Making a geomorph data frame object with the species and sites attributes} -\NormalTok{gdf\_plethodon \textless{}{-}}\StringTok{ }\KeywordTok{geomorph.data.frame}\NormalTok{(gpa\_plethodon,} - \DataTypeTok{species =}\NormalTok{ plethodon}\OperatorTok{$}\NormalTok{species,} - \DataTypeTok{site =}\NormalTok{ plethodon}\OperatorTok{$}\NormalTok{site)} +\DocumentationTok{\#\# Making a geomorph data frame object with the species and sites attributes} +\NormalTok{gdf\_plethodon }\OtherTok{\textless{}{-}} \FunctionTok{geomorph.data.frame}\NormalTok{(gpa\_plethodon,} + \AttributeTok{species =}\NormalTok{ plethodon}\SpecialCharTok{$}\NormalTok{species,} + \AttributeTok{site =}\NormalTok{ plethodon}\SpecialCharTok{$}\NormalTok{site)} \end{Highlighting} \end{Shaded} @@ -8870,8 +8805,8 @@ \section{Before starting}\label{before-starting-1}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# You can replace the gdf\_plethodon by your own geomorph data frame!} -\NormalTok{my\_geomorph\_data \textless{}{-}}\StringTok{ }\NormalTok{gdf\_plethodon} +\DocumentationTok{\#\# You can replace the gdf\_plethodon by your own geomorph data frame!} +\NormalTok{my\_geomorph\_data }\OtherTok{\textless{}{-}}\NormalTok{ gdf\_plethodon} \end{Highlighting} \end{Shaded} @@ -8892,8 +8827,8 @@ \subsection{The morphospace}\label{the-morphospace-1}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The morphospace} -\NormalTok{morphospace \textless{}{-}}\StringTok{ }\KeywordTok{geomorph.ordination}\NormalTok{(gdf\_plethodon)} +\DocumentationTok{\#\# The morphospace} +\NormalTok{morphospace }\OtherTok{\textless{}{-}} \FunctionTok{geomorph.ordination}\NormalTok{(gdf\_plethodon)} \end{Highlighting} \end{Shaded} @@ -8901,7 +8836,7 @@ \subsection{The morphospace}\label{the-morphospace-1}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The dispRity object} +\DocumentationTok{\#\# The dispRity object} \NormalTok{morphospace} \end{Highlighting} \end{Shaded} @@ -8914,16 +8849,16 @@ \subsection{The morphospace}\label{the-morphospace-1}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Plotting the morphospace} -\KeywordTok{plot}\NormalTok{(morphospace)} +\DocumentationTok{\#\# Plotting the morphospace} +\FunctionTok{plot}\NormalTok{(morphospace)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-242-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-250-1.pdf} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Note that this only displays the two last groups (site.Allo and site.Symp) since they overlap!} +\DocumentationTok{\#\# Note that this only displays the two last groups (site.Allo and site.Symp) since they overlap!} \end{Highlighting} \end{Shaded} @@ -8939,25 +8874,25 @@ \section{Calculating disparity}\label{calculating-disparity-2}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Defining a the procrustes variance metric} -\CommentTok{\#\# (as in geomorph::morphol.disparity)} -\NormalTok{proc.var \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(matrix) \{}\KeywordTok{sum}\NormalTok{(matrix}\OperatorTok{\^{}}\DecValTok{2}\NormalTok{)}\OperatorTok{/}\KeywordTok{nrow}\NormalTok{(matrix)\}} +\DocumentationTok{\#\# Defining a the procrustes variance metric} +\DocumentationTok{\#\# (as in geomorph::morphol.disparity)} +\NormalTok{proc.var }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(matrix) \{}\FunctionTok{sum}\NormalTok{(matrix}\SpecialCharTok{\^{}}\DecValTok{2}\NormalTok{)}\SpecialCharTok{/}\FunctionTok{nrow}\NormalTok{(matrix)\}} \end{Highlighting} \end{Shaded} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# The size metric} -\NormalTok{test\_size \textless{}{-}}\StringTok{ }\KeywordTok{test.metric}\NormalTok{(morphospace, }\DataTypeTok{metric =}\NormalTok{ proc.var,} - \DataTypeTok{shifts =} \KeywordTok{c}\NormalTok{(}\StringTok{"random"}\NormalTok{, }\StringTok{"size"}\NormalTok{))} -\KeywordTok{plot}\NormalTok{(test\_size)} -\KeywordTok{summary}\NormalTok{(test\_size)} +\DocumentationTok{\#\# The size metric} +\NormalTok{test\_size }\OtherTok{\textless{}{-}} \FunctionTok{test.metric}\NormalTok{(morphospace, }\AttributeTok{metric =}\NormalTok{ proc.var,} + \AttributeTok{shifts =} \FunctionTok{c}\NormalTok{(}\StringTok{"random"}\NormalTok{, }\StringTok{"size"}\NormalTok{))} +\FunctionTok{plot}\NormalTok{(test\_size)} +\FunctionTok{summary}\NormalTok{(test\_size)} -\CommentTok{\#\# The position metric} -\NormalTok{test\_position \textless{}{-}}\StringTok{ }\KeywordTok{test.metric}\NormalTok{(morphospace, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(mean, displacements),} - \DataTypeTok{shifts =} \KeywordTok{c}\NormalTok{(}\StringTok{"random"}\NormalTok{, }\StringTok{"position"}\NormalTok{))} -\KeywordTok{plot}\NormalTok{(test\_position)} -\KeywordTok{summary}\NormalTok{(test\_position)} +\DocumentationTok{\#\# The position metric} +\NormalTok{test\_position }\OtherTok{\textless{}{-}} \FunctionTok{test.metric}\NormalTok{(morphospace, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(mean, displacements),} + \AttributeTok{shifts =} \FunctionTok{c}\NormalTok{(}\StringTok{"random"}\NormalTok{, }\StringTok{"position"}\NormalTok{))} +\FunctionTok{plot}\NormalTok{(test\_position)} +\FunctionTok{summary}\NormalTok{(test\_position)} \end{Highlighting} \end{Shaded} @@ -8972,9 +8907,9 @@ \section{Calculating disparity}\label{calculating-disparity-2}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Bootstrapped disparity} -\NormalTok{disparity\_size \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(}\KeywordTok{boot.matrix}\NormalTok{(morphospace), }\DataTypeTok{metric =}\NormalTok{ proc.var)} -\NormalTok{disparity\_position \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(}\KeywordTok{boot.matrix}\NormalTok{(morphospace), }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(mean, displacements))} +\DocumentationTok{\#\# Bootstrapped disparity} +\NormalTok{disparity\_size }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(}\FunctionTok{boot.matrix}\NormalTok{(morphospace), }\AttributeTok{metric =}\NormalTok{ proc.var)} +\NormalTok{disparity\_position }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(}\FunctionTok{boot.matrix}\NormalTok{(morphospace), }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(mean, displacements))} \end{Highlighting} \end{Shaded} @@ -8988,25 +8923,25 @@ \section{Analyse the results}\label{analyse-the-results}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Plotting the results} -\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =} \KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{))} -\KeywordTok{plot}\NormalTok{(disparity\_size, }\DataTypeTok{main =} \StringTok{"group sizes"}\NormalTok{, }\DataTypeTok{las =} \DecValTok{2}\NormalTok{, }\DataTypeTok{xlab =} \StringTok{""}\NormalTok{)} -\KeywordTok{plot}\NormalTok{(disparity\_position, }\DataTypeTok{main =} \StringTok{"group positions"}\NormalTok{, }\DataTypeTok{las =} \DecValTok{2}\NormalTok{, }\DataTypeTok{xlab =} \StringTok{""}\NormalTok{)} +\DocumentationTok{\#\# Plotting the results} +\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =} \FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{))} +\FunctionTok{plot}\NormalTok{(disparity\_size, }\AttributeTok{main =} \StringTok{"group sizes"}\NormalTok{, }\AttributeTok{las =} \DecValTok{2}\NormalTok{, }\AttributeTok{xlab =} \StringTok{""}\NormalTok{)} +\FunctionTok{plot}\NormalTok{(disparity\_position, }\AttributeTok{main =} \StringTok{"group positions"}\NormalTok{, }\AttributeTok{las =} \DecValTok{2}\NormalTok{, }\AttributeTok{xlab =} \StringTok{""}\NormalTok{)} \end{Highlighting} \end{Shaded} -\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-246-1.pdf} +\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-254-1.pdf} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Summarising the results} -\KeywordTok{summary}\NormalTok{(disparity\_size)} +\DocumentationTok{\#\# Summarising the results} +\FunctionTok{summary}\NormalTok{(disparity\_size)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## subsets n obs bs.median 2.5% 25% 75% 97.5% -## 1 species.Jord 20 0.005 0.005 0.004 0.005 0.005 0.006 +## 1 species.Jord 20 0.005 0.005 0.004 0.005 0.005 0.005 ## 2 species.Teyah 20 0.005 0.005 0.004 0.005 0.005 0.006 ## 3 site.Allo 20 0.004 0.004 0.003 0.003 0.004 0.004 ## 4 site.Symp 20 0.006 0.006 0.006 0.006 0.006 0.007 @@ -9014,16 +8949,16 @@ \section{Analyse the results}\label{analyse-the-results}} \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{summary}\NormalTok{(disparity\_position)} +\FunctionTok{summary}\NormalTok{(disparity\_position)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## subsets n obs bs.median 2.5% 25% 75% 97.5% -## 1 species.Jord 20 1.096 1.122 1.067 1.101 1.171 1.380 -## 2 species.Teyah 20 1.070 1.105 1.033 1.065 1.143 1.345 -## 3 site.Allo 20 1.377 1.407 1.315 1.381 1.448 1.530 -## 4 site.Symp 20 1.168 1.221 1.148 1.187 1.269 1.458 +## 1 species.Jord 20 1.096 1.122 1.069 1.104 1.168 1.404 +## 2 species.Teyah 20 1.070 1.095 1.029 1.070 1.146 1.320 +## 3 site.Allo 20 1.377 1.415 1.311 1.369 1.464 1.526 +## 4 site.Symp 20 1.168 1.220 1.158 1.190 1.270 1.498 \end{verbatim} Just from looking at the data, we can guess that there is not much difference in terms of morphospace occupancy and position for the species but there is on for the sites (allopatric or sympatric). @@ -9031,55 +8966,55 @@ \section{Analyse the results}\label{analyse-the-results}} \begin{Shaded} \begin{Highlighting}[] -\CommentTok{\#\# Testing the differences} -\KeywordTok{test.dispRity}\NormalTok{(disparity\_size, }\DataTypeTok{test =}\NormalTok{ wilcox.test, }\DataTypeTok{correction =} \StringTok{"bonferroni"}\NormalTok{)} +\DocumentationTok{\#\# Testing the differences} +\FunctionTok{test.dispRity}\NormalTok{(disparity\_size, }\AttributeTok{test =}\NormalTok{ wilcox.test, }\AttributeTok{correction =} \StringTok{"bonferroni"}\NormalTok{)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## [[1]] ## statistic: W -## species.Jord : species.Teyah 3803 -## species.Jord : site.Allo 9922 -## species.Jord : site.Symp 14 -## species.Teyah : site.Allo 9927 -## species.Teyah : site.Symp 238 +## species.Jord : species.Teyah 3842 +## species.Jord : site.Allo 9919 +## species.Jord : site.Symp 7 +## species.Teyah : site.Allo 9939 +## species.Teyah : site.Symp 155 ## site.Allo : site.Symp 0 ## ## [[2]] ## p.value -## species.Jord : species.Teyah 2.076623e-02 -## species.Jord : site.Allo 1.572891e-32 -## species.Jord : site.Symp 2.339811e-33 -## species.Teyah : site.Allo 1.356528e-32 -## species.Teyah : site.Symp 1.657077e-30 +## species.Jord : species.Teyah 2.808435e-02 +## species.Jord : site.Allo 1.718817e-32 +## species.Jord : site.Symp 1.896841e-33 +## species.Teyah : site.Allo 9.504256e-33 +## species.Teyah : site.Symp 1.507734e-31 ## site.Allo : site.Symp 1.537286e-33 \end{verbatim} \begin{Shaded} \begin{Highlighting}[] -\KeywordTok{test.dispRity}\NormalTok{(disparity\_position, }\DataTypeTok{test =}\NormalTok{ wilcox.test, }\DataTypeTok{correction =} \StringTok{"bonferroni"}\NormalTok{)} +\FunctionTok{test.dispRity}\NormalTok{(disparity\_position, }\AttributeTok{test =}\NormalTok{ wilcox.test, }\AttributeTok{correction =} \StringTok{"bonferroni"}\NormalTok{)} \end{Highlighting} \end{Shaded} \begin{verbatim} ## [[1]] ## statistic: W -## species.Jord : species.Teyah 6536 -## species.Jord : site.Allo 204 -## species.Jord : site.Symp 1473 -## species.Teyah : site.Allo 103 -## species.Teyah : site.Symp 1042 -## site.Allo : site.Symp 9288 +## species.Jord : species.Teyah 6639 +## species.Jord : site.Allo 262 +## species.Jord : site.Symp 1386 +## species.Teyah : site.Allo 91 +## species.Teyah : site.Symp 981 +## site.Allo : site.Symp 9373 ## ## [[2]] ## p.value -## species.Jord : species.Teyah 1.053318e-03 -## species.Jord : site.Allo 6.238014e-31 -## species.Jord : site.Symp 4.137900e-17 -## species.Teyah : site.Allo 3.289139e-32 -## species.Teyah : site.Symp 2.433117e-21 -## site.Allo : site.Symp 6.679158e-25 +## species.Jord : species.Teyah 3.744848e-04 +## species.Jord : site.Allo 3.288928e-30 +## species.Jord : site.Symp 6.326430e-18 +## species.Teyah : site.Allo 2.309399e-32 +## species.Teyah : site.Symp 5.609280e-22 +## site.Allo : site.Symp 7.278818e-26 \end{verbatim} So by applying the tests we see a difference in terms of position between each groups and differences in size between groups but between the species. diff --git a/tests/testthat/test-multi.ace.R b/tests/testthat/test-multi.ace.R index f6a1b0a7..b96e7c0b 100755 --- a/tests/testthat/test-multi.ace.R +++ b/tests/testthat/test-multi.ace.R @@ -354,31 +354,31 @@ test_that("multi.ace works", { my_models <- c(rep("ER", 25), rep("SYM", 25)) ## Output details - set.seed(8) - matrix_test <- sim.morpho(rcoal(6), characters = 10, model = "ER", rates = c(rgamma, rate = 10, shape = 5), invariant = FALSE) - tree_test <- rmtree(2, 6) - matrix_complex <- matrix_test - matrix_complex[sample(1:length(matrix_complex), 5)] <- "-" - matrix_complex[sample(1:length(matrix_complex), 5)] <- "0%2" - matrix_complex[sample(1:length(matrix_complex), 5)] <- "?" - results <- multi.ace(data = matrix_complex, - tree = tree_test, - models = "ER", - threshold = TRUE, - special.tokens = c("weird" = "%"), - special.behaviours = list(weirdtoken = function(x,y) return(c(1,2))), - brlen.multiplier = rnorm(10), - verbose = FALSE, - parallel = FALSE, - output = "matrix", - estimation.details = c("loglikelihood", "transition_matrix")) - expect_is(results, "list") - expect_equal(names(results), c("estimations", "details")) - expect_is(results$estimations, "list") - expect_is(results$estimations[[1]], "matrix") - expect_is(results$details[[1]]$transition_matrix[[9]], "matrix") - expect_equal(rownames(results$details[[1]]$transition_matrix[[9]]), c("0","1","2")) - expect_is(results$details[[2]]$loglikelihood[[1]], "numeric") + # set.seed(8) + # matrix_test <- sim.morpho(rcoal(6), characters = 10, model = "ER", rates = c(rgamma, rate = 10, shape = 5), invariant = FALSE) + # tree_test <- rmtree(2, 6) + # matrix_complex <- matrix_test + # matrix_complex[sample(1:length(matrix_complex), 5)] <- "-" + # matrix_complex[sample(1:length(matrix_complex), 5)] <- "0%2" + # matrix_complex[sample(1:length(matrix_complex), 5)] <- "?" + # results <- multi.ace(data = matrix_complex, + # tree = tree_test, + # models = "ER", + # threshold = TRUE, + # special.tokens = c("weird" = "%"), + # special.behaviours = list(weirdtoken = function(x,y) return(c(1,2))), + # brlen.multiplier = rnorm(10), + # verbose = FALSE, + # parallel = FALSE, + # output = "matrix", + # estimation.details = c("loglikelihood", "transition_matrix")) + # expect_is(results, "list") + # expect_equal(names(results), c("estimations", "details")) + # expect_is(results$estimations, "list") + # expect_is(results$estimations[[1]], "matrix") + # expect_is(results$details[[1]]$transition_matrix[[9]], "matrix") + # expect_equal(rownames(results$details[[1]]$transition_matrix[[9]]), c("0","1","2")) + # expect_is(results$details[[2]]$loglikelihood[[1]], "numeric")