# Simulating data using CmdStanR

**URL:** <https://discourse.mc-stan.org/t/simulating-data-using-cmdstanr/24554>\
**Category:** CmdStan\
**Created:** [September 23, 2021, 11:30pm UTC](https://discourse.mc-stan.org/t/simulating-data-using-cmdstanr/24554 "2021-09-23T23:30:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcdotson](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/marcdotson/32/18613_2.png) [@marcdotson](https://discourse.mc-stan.org/u/marcdotson)\
**Post date:** [September 23, 2021, 11:30pm UTC](https://discourse.mc-stan.org/t/simulating-data-using-cmdstanr/24554/1 "2021-09-23T23:30:29Z")

</div>

I’ve been toying with transferring my workflow from RStan to CmdStanR. However, I don’t see an obvious way to simulate data using CmdStanR.

Using RStan I can use

```
sim_data <- stan(
  file = generate_data.stan,
  data = sim_values,
  iter = 1,
  chains = 1,
  algorithm = "Fixed_param"
)

```

to simulate data, but I don’t see an equivalent to `algorithm = "Fixed_param"` in CmdStanR’s `$sample()` or a way to use `$generate_quantities()` without starting with fitted parameters.

---

<div class="post-metadata">

**Author:** ![dmuck](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/dmuck/32/10223_2.png) [@dmuck](https://discourse.mc-stan.org/u/dmuck)\
**Post date:** [September 24, 2021, 12:32am UTC](https://discourse.mc-stan.org/t/simulating-data-using-cmdstanr/24554/2 "2021-09-24T00:32:18Z")

</div>

The equivalent to `algorithm = "Fixed_param"` in cmdstanr can be specified inside `$sample()` by setting `fixed_param = TRUE`. e.g.,

```
sim_data <- model$sample(data = data, fixed_param = TRUE)

```

See the documentation [here](https://mc-stan.org/cmdstanr/reference/model-method-sample.html).

---

<div class="post-metadata">

**Author:** ![marcdotson](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/marcdotson/32/18613_2.png) [@marcdotson](https://discourse.mc-stan.org/u/marcdotson)\
**Post date:** [September 24, 2021, 4:23pm UTC](https://discourse.mc-stan.org/t/simulating-data-using-cmdstanr/24554/3 "2021-09-24T16:23:51Z")

</div>

Ah, right in front of me. Thank you!
