Skip to content

Commit

Permalink
Put model in README
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau-lilly committed Nov 18, 2021
1 parent 9a59f5a commit 9ca9706
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 10 deletions.
21 changes: 19 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,24 @@ remotes::install_github("ropensci/jagstargets")

## Usage

First, write a [`_targets.R` file](https://books.ropensci.org/targets/walkthrough.html) that loads your packages, defines a function to generate JAGS data, and lists a pipeline of targets. The target list can call target factories like [`tar_jags()`](https://docs.ropensci.org/jagstargets/reference/tar_jags.html) as well as ordinary targets with [`tar_target()`](https://docs.ropensci.org/targets/reference/tar_target.html). The following minimal example is simple enough to contain entirely within the `_targets.R` file, but for larger projects, you may wish to store functions in separate files as in the [`targets-stan`](https://github.com/wlandau/targets-stan) example.
Begin with one or more models: for example, the simple regression model below with response variable $y$ and covariate $x$.

<center>
<img src="./man/figures/model.gif">
</center>

Next, write a JAGS model file for each model like the `model.jags` file below.

```jags
model {
for (i in 1:n) {
y[i] ~ dnorm(x[i] * beta, 1)
}
beta ~ dnorm(0, 1)
}
```

To begin a reproducible analysis pipeline with this model, write a [`_targets.R` file](https://books.ropensci.org/targets/walkthrough.html) that loads your packages, defines a function to generate JAGS data, and lists a pipeline of targets. The target list can call target factories like [`tar_jags()`](https://docs.ropensci.org/jagstargets/reference/tar_jags.html) as well as ordinary targets with [`tar_target()`](https://docs.ropensci.org/targets/reference/tar_target.html). The following minimal example is simple enough to contain entirely within the `_targets.R` file, but for larger projects, you may wish to store functions in separate files as in the [`targets-stan`](https://github.com/wlandau/targets-stan) example.

```{r, eval = FALSE}
# _targets.R
Expand All @@ -74,7 +91,7 @@ generate_data <- function() {
list(
tar_jags(
example,
jags_files = "x.jags", # You provide this file.
jags_files = "model.jags", # You provide this file.
parameters.to.save = "beta",
data = generate_data()
)
Expand Down
38 changes: 30 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,30 @@ remotes::install_github("ropensci/jagstargets")

## Usage

First, write a [`_targets.R`
file](https://books.ropensci.org/targets/walkthrough.html) that loads
your packages, defines a function to generate JAGS data, and lists a
pipeline of targets. The target list can call target factories like
Begin with one or more models: for example, the simple regression model
below with response variable *y* and covariate *x*.

<center>
<img src="./man/figures/model.gif">
</center>

Next, write a JAGS model file for each model like the `model.jags` file
below.

``` jags
model {
for (i in 1:n) {
y[i] ~ dnorm(x[i] * beta, 1)
}
beta ~ dnorm(0, 1)
}
```

To begin a reproducible analysis pipeline with this model, write a
[`_targets.R` file](https://books.ropensci.org/targets/walkthrough.html)
that loads your packages, defines a function to generate JAGS data, and
lists a pipeline of targets. The target list can call target factories
like
[`tar_jags()`](https://docs.ropensci.org/jagstargets/reference/tar_jags.html)
as well as ordinary targets with
[`tar_target()`](https://docs.ropensci.org/targets/reference/tar_target.html).
Expand All @@ -106,7 +126,7 @@ generate_data <- function() {
list(
tar_jags(
example,
jags_files = "x.jags", # You provide this file.
jags_files = "model.jags", # You provide this file.
parameters.to.save = "beta",
data = generate_data()
)
Expand Down Expand Up @@ -173,15 +193,17 @@ citation("jagstargets")
#>
#> To cite package 'jagstargets' in publications use:
#>
#> William Michael Landau (NA). jagstargets: Targets for JAGS Workflows.
#> https://docs.ropensci.org/jagstargets/,
#> William Michael Landau (2021). jagstargets: Targets for JAGS
#> Workflows. https://docs.ropensci.org/jagstargets/,
#> https://github.com/ropensci/jagstargets.
#>
#> A BibTeX entry for LaTeX users is
#>
#> @Manual{,
#> title = {jagstargets: Targets for JAGS Workflows},
#> author = {William Michael Landau},
#> note = {https://docs.ropensci.org/jagstargets/, https://github.com/ropensci/jagstargets},
#> year = {2021},
#> note = {https://docs.ropensci.org/jagstargets/,
#> https://github.com/ropensci/jagstargets},
#> }
```
Binary file added man/figures/model.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9ca9706

Please sign in to comment.