---
title: "Frequently Asked Questions"
author: "ssdtools Team"
date: "`r Sys.Date()`"
bibliography: references.bib
csl: my-style.csl
latex_engine: MathJax
mainfont: Arial
mathfont: Courier
output: rmarkdown::html_vignette
#output: rmarkdown::pdf_document
vignette: >
  %\VignetteIndexEntry{Frequently Asked Questions}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---
  
```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```


## How can I plot the model averaged fit with individual fits?

```{r, fig.width = 5, fig.height = 5}
library(ssdtools)

dist <- ssd_fit_dists(ssddata::ccme_boron)
ssd_plot_cdf(dist, average = NA)
```

## How do I fit distributions to multiple groups such taxa and/or chemicals?

An elegant approach using some tidyverse packages is demonstrated below.

```{r, message=FALSE}
library(ssddata)
library(ssdtools)
library(ggplot2)
library(dplyr)
library(tidyr)
library(purrr)

boron_preds <- nest(ccme_boron, data = c(Chemical, Species, Conc, Units)) %>%
  mutate(
    Fit = map(data, ssd_fit_dists, dists = "lnorm"),
    Prediction = map(Fit, predict)
  ) %>%
  unnest(Prediction)
```

The resultant data and predictions can then be plotted as follows.
```{r, fig.width = 5, fig.height = 5}
ssd_plot(ccme_boron, boron_preds, xlab = "Concentration (mg/L)", ci = FALSE) +
  facet_wrap(~Group)
```

<div id="refs"></div>

```{r, results = "asis", echo = FALSE}
cat(licensing_md())
```

