An open API service indexing awesome lists of open source software.

https://github.com/epiforecasts/stanedit

Edit stan models from R
https://github.com/epiforecasts/stanedit

probabilistic-programming stan

Last synced: 8 months ago
JSON representation

Edit stan models from R

Awesome Lists containing this project

README

          

---
output: github_document
---

## Edit stan models using R

This package facilitates editing of stan model code using R. This includes adding/removing blocks, extracting variable names, and inserting/removing lines.

Development of this package was inspired by the `` class in the [rbi](https://github.com/sbfnk/rbi) package.

## Installation

The stable version of the package can be installed using
```{r eval=FALSE}
install.packages("stanedit", repos = "https://epiforecasts.r-universe.dev/")
```

The development version can be installed using `pak`
```{r eval=FALSE}
pak::pak("epiforecasts/stanedit")
```

## Example

First we load a stan model and prepare it for editing using the functionality in this package.

```{r}
library("stanedit")
model_file_name <- system.file(package = "stanedit", "regression.stan")
reg <- stanedit(filename = model_file_name)
reg
```

Let's say we want to add standard normal priors for alpha and beta.
We can do this using

```{r}
insert_lines(reg,
lines = c(
"alpha ~ std_normal();",
"beta ~ std_normal();"
),
at_end_of = "model"
)
```

## Contributors

All contributions to this project are gratefully acknowledged using the [`allcontributors` package](https://github.com/ropensci/allcontributors) following the [all-contributors](https://allcontributors.org) specification. Contributions of any kind are welcome!

sbfnk