---
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.
```{r child='../inst/examples/linear.Rmd'}
```
```{r child='../inst/examples/multiple_linear.Rmd'}
```
```{r child='../inst/examples/multiple_linear_warpbreaks.Rmd'}
```
```{r child='../inst/examples/multiple_linear_multilogit.Rmd'}
```
```{r child='../inst/examples/multiple_linear_lasso.Rmd'}
```
```{r child='../inst/examples/hierarchical_linear.Rmd'}
```
```{r child='../inst/examples/hierarchical_linear_slopes.Rmd'}
```
```{r child='../inst/examples/hierarchical_linear_slopes_corr.Rmd'}
```
## Common Bayesian priors
The following examples show some common Bayesian priors of which some induce sparsity.
```{r child='../inst/examples/linear_uninformative.Rmd'}
```
```{r child='../inst/examples/linear_ridge.Rmd'}
```
```{r child='../inst/examples/linear_lasso.Rmd'}
```
```{r child='../inst/examples/linear_horseshoe.Rmd'}
```
```{r child='../inst/examples/linear_finnish_horseshoe.Rmd'}
```
## Advanced Bayesian models
Below are some more advanced examples implemented in greta.
```{r child='../inst/examples/hierarchical_linear_general.Rmd'}
```
```{r child='../inst/examples/hierarchical_linear_marginal.Rmd'}
```
```{r child='../inst/examples/bayesian_neural_network.Rmd'}
```
```{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://citeseerx.ist.psu.edu/document?repid=rep1&type=pdf&doi=56b11079d6495501c84932c0a7a372ca6bc370ae) (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).
```{r child='../inst/examples/air.Rmd'}
```
```{r child='../inst/examples/beetles.Rmd'}
```
## Stan models
The following few code examples show how Stan code can be translated in equivalent greta models.
```{r child='../inst/examples/lightspeed.Rmd'}
```
```{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.
```{r child='../inst/examples/logistic.Rmd'}
```
```{r child='../inst/examples/poisson.Rmd'}
```
```{r child='../inst/examples/logistic_error_term.Rmd'}
```
```{r child='../inst/examples/multispecies_independent.Rmd'}
```
```{r child='../inst/examples/multispecies_partial_pool.Rmd'}
```
```{r child='../inst/examples/multilevel.Rmd'}
```
```{r child='../inst/examples/cjs.Rmd'}
```