---
title: "Example models"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteIndexEntry{Example models}
  %\usepackage[utf8]{inputenc}
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(comment = NA,
                      eval = greta:::check_tf_version("message"),
                      cache = TRUE)
library (greta)
```

## Common models

Below are a few examples of common statistical models implemented in greta.

<hr>

```{r child='../inst/examples/linear.Rmd'}
```

<hr>

```{r child='../inst/examples/multiple_linear.Rmd'}
```

<hr>

```{r child='../inst/examples/multiple_linear_warpbreaks.Rmd'}
```

<hr>

```{r child='../inst/examples/multiple_linear_multilogit.Rmd'}
```

<hr>

```{r child='../inst/examples/multiple_linear_lasso.Rmd'}
```

<hr>

```{r child='../inst/examples/hierarchical_linear.Rmd'}
```

<hr>

```{r child='../inst/examples/hierarchical_linear_slopes.Rmd'}
```

## Common Bayesian priors

The following examples show some common Bayesian priors of which some induce sparsity.

<hr>

```{r child='../inst/examples/linear_uninformative.Rmd'}
```

<hr>

```{r child='../inst/examples/linear_ridge.Rmd'}
```

<hr>

```{r child='../inst/examples/linear_lasso.Rmd'}
```

<hr>

```{r child='../inst/examples/linear_horseshoe.Rmd'}
```

<hr>

```{r child='../inst/examples/linear_finnish_horseshoe.Rmd'}
```

## Advanced Bayesian models

Below are some more advanced examples implemented in greta.

<hr>

```{r child='../inst/examples/hierarchical_linear_general.Rmd'}
```

<hr>

```{r child='../inst/examples/hierarchical_linear_marginal.Rmd'}
```

<hr>

```{r child='../inst/examples/bayesian_neural_network.Rmd'}
```

<hr>

```{r child='../inst/examples/factor_analysis.Rmd'}
```

## BUGS models

The BUGS project provide a number of example models written in the BUGS modelling language. These models will run in WinBUGS and OpenBUGS, and likely also in JAGS. The [Stan wiki](https://github.com/stan-dev/example-models/wiki/BUGS-Examples-Sorted-Alphabetically) provides Stan implementations of these models.

The following sections provide greta implementations of some of these example models, alongside the BUGS code from [WinBUGS examples volume 2](https://www.mrc-bsu.cam.ac.uk/wp-content/uploads/WinBUGS_Vol2.pdf) (pdf) and Stan code and an R version of the data from the [Stan example models wiki](https://github.com/stan-dev/example-models/wiki). 

<hr>

```{r child='../inst/examples/air.Rmd'}
```

<hr>

```{r child='../inst/examples/beetles.Rmd'}
```

## Stan models

The following few code examples show how Stan code can be translated in equivalent greta models.

<hr>

```{r child='../inst/examples/lightspeed.Rmd'}
```

<hr>

```{r child='../inst/examples/eight_schools.Rmd'}
```

## Ecological models

Here we provide some examples of common ecological models. We begin with a basic logistic regression often used in species distribution modelling to estimate species probability of presence. We then provide increasingly complex species distribution models, beginning with modelling observation error directly, and moving on to models for multiple species: independently but concurrently modelled species, partially pooled coefficients, repeated measures, and sub-models.

<hr>

```{r child='../inst/examples/logistic.Rmd'}
```

<hr>

```{r child='../inst/examples/poisson.Rmd'}
```

<hr>

```{r child='../inst/examples/logistic_error_term.Rmd'}
```

<hr>

```{r child='../inst/examples/multispecies_independent.Rmd'}
```

<hr>
```{r child='../inst/examples/multispecies_partial_pool.Rmd'}
```

<hr>

```{r child='../inst/examples/multilevel.Rmd'}
```

<hr>

```{r child='../inst/examples/cjs.Rmd'}
```

<hr>
