--- title: "DImodels" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{DImodels} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) ``` ```{r setup} library(DImodels) ``` # Getting Started with `DImodels` The `DImodels` package is designed to make fitting Diversity-Interactions models easier. Diversity-Interactions (DI) models (Kirwan et al 2009) are a set of tools for analysing and interpreting data from experiments that explore the effects of species diversity (from a pool of *S* species) on community-level responses. Data suitable for DI models will include (at least) for each experimental unit: a response recorded at a point in time, and a set of proportions of *S* species $p_1$, $p_2$, ..., $p_S$ from a point in time prior to the recording of the response. The proportions sum to 1 for each experimental unit. __Main changes in the package from version 1.3.2 to version 1.3.3__ - A `contrast_matrix()` function is introduced that creates contrast matrices using species proportions which can be passed onto the `contrasts_DI()` function to test for contrasts using a DI model object. - A `compare_communities()` function is added which allows for pairwise comparisons between various specific communities and assigns compact letter displays (CLD) to each community. - All the parameters used for fitting a `DImodel` are stacked onto the model object as attributes and can be accessed using the `attributes()` and `attr()` functions. __Main changes in the package from version 1.3.1 to version 1.3.2__ - The `predict()` function now allows predicting the response for species communities that do not sum to 1, but with a warning notifying the user about this. - General bug fixes __Main changes in the package from version 1.3 to version 1.3.1__ - A `fortify()` function method has been added to supplement the data fitted to a linear model with model fit statistics. - A `describe_model()` function is added which can be used to get a short text summary of any DI model. - Meta-data about a DI model can be accessed via the `attributes()` function. __Main changes in the package from version 1.2 to version 1.3__ - The `DI()` and `autoDI()` functions now have an additional parameter called `ID` which enables the user to group the species identity effects (see examples below). - The `predict()` function now has flexibility to calculate confidence and prediction intervals for the predicted values. __Main changes in the package from version 1.1 to version 1.2__ - There are two new functions added to the package: - `predict()`: Make predictions from a fitted DI model without having to worry about theta, and the interaction terms in the data. - `contrasts_DI()`: Create contrasts for a DI model. __Main changes in the package from version 1.0 to version 1.1__ - `DI_data_prepare()` is now superseded by `DI_data()` (see examples below) ## `DImodels` installation and load The `DImodels` package is installed from CRAN and loaded in the typical way. ```{r, eval = FALSE} install.packages("DImodels") library("DImodels") ``` ## Accessing an introduction to Diversity-Introductions models It is recommended that users unfamiliar with Diversity-Interactions (DI) models read the introduction to `DImodels`, before using the package. Run the following code to access the documentation. ```{r, eval = FALSE} ?DImodels ``` ## Datasets included in the DImodels package There are seven example datasets included in the `DImodels` package: `Bell`, `sim1`, `sim2`, `sim3`, `sim4`, `sim5`, `Switzerland`. Details about each of these datasets is available in their associated help files, run this code, for example: ```{r, eval = FALSE} ?sim3 ``` In this vignette, we will describe the `sim3` dataset and show a worked analysis of it. ## The sim3 dataset The `sim3` dataset was simulated from a functional group (FG) Diversity-Interactions model. There were nine species in the pool, and it was assumed that species 1 to 5 come from functional group 1, species 6 and 7 from functional group 2 and species 8 and 9 from functional group 3, where species in the same functional group are assumed to have similar traits. The following equation was used to simulate the data. $$ y = \sum_{i=1}^{9}\beta_ip_i + \omega_{11}\sum_{\substack{i,j = 1 \\ i