# How can I use the same function call to sample from posterior when data exists and only sample from prior when not?

**URL:** <https://discourse.mc-stan.org/t/how-can-i-use-the-same-function-call-to-sample-from-posterior-when-data-exists-and-only-sample-from-prior-when-not/41685>\
**Category:** brms\
**Created:** [October 22, 2026, 1:38am UTC](https://discourse.mc-stan.org/t/how-can-i-use-the-same-function-call-to-sample-from-posterior-when-data-exists-and-only-sample-from-prior-when-not/41685 "2026-10-22T01:38:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ischmidt20](https://avatars.discourse-cdn.com/v4/letter/i/85f322/32.png) [@ischmidt20](https://discourse.mc-stan.org/u/ischmidt20)\
**Post date:** [October 22, 2026, 1:38am UTC](https://discourse.mc-stan.org/t/how-can-i-use-the-same-function-call-to-sample-from-posterior-when-data-exists-and-only-sample-from-prior-when-not/41685/1 "2026-10-22T01:38:22Z")

</div>

I have a brms model where sometimes there is no data, in which case I want brms to sample from the prior just as it normally would the posterior.

Previously, I had code like this:

```no-highlight
cond <- ...

if (sum(cond) == 0) {
  samplePrior <- "only"
  cond <- TRUE
} else {
  samplePrior <- "no"
}

model <- brm(
  y ~ . + 0,
  data = X[cond,],
  samplePrior = samplePrior,
  backend = "cmdstanr",
  ...
)

```

This worked as of one year ago, or maybe two years. Now, I get:

> Error in `validate_data()`:  
> ! All observations in the data were removed presumably because of NA values.  
> Run `rlang::last_trace()` to see where the error occurred.  
> Warning message:  
> Rows containing NAs were excluded from the model.

How can I dynamically sample from just the prior when I have no data to pass to the model?
