I admit that this felt wrong to me. So just to check my understanding is right:

Before rejections we have:

\pi(\theta | y) \propto \pi(y | \theta) \pi(\theta)

After rejections we have

\pi(\theta | y) \propto \frac{L(\theta)}{R} \pi(y | \theta) \frac{f(y)}{L(\theta)} \pi(\theta) = \frac{f(y)}{R} \pi(y | \theta) \pi(\theta)

And since \frac{f(y)}{R} is a constant, the overall posterior is the same whether we take rejection into account or not.

Also I did check empirically with a simple example and indeed, despite heavy rejections the ranks are uniformâ€¦ So my intuition was once again proven bad :-) Now I canâ€™t explain why I thought it was a problem in some of my SBC runs, where heavy rejections were accompanied by bad histogramsâ€¦

Anyway, thanks for clarifying!

##
Little example to test

```
library(SBC)
library(cmdstanr)
stan_code <- "
data {
int<lower=0> N;
real y[N];
}
parameters {
real mu;
}
model {
mu ~ normal(0, 2);
y ~ normal(mu, 1);
}
generated quantities {
real mu_ = normal_rng(0, 2);
real y_[N];
for(n in 1:N) {
y_[n] = normal_rng(mu, 1);
}
}
"
n_datasets = 1000 # total number of simulated parameter sets from theta
N = 10
thin = 3
data <- list(N=N, y=as.vector(1:N))
model <- cmdstan_model(write_stan_file(stan_code))
sbc_obj <- SBCModel$new(name = "simple_test", stan_model = model)
hyperpriors <- list("mu"=function(){rnorm(1, 0, 2)})
theta_prior <- sbc_obj$sample_theta_tilde(list("mu"), n_datasets, hyperpriors)
sampled_y <- sbc_obj$sample_y_tilde(theta_prior , data=data)
theta_post <- sbc_obj$sample_theta_bar_y(sampled_y, data=data, pars=list("mu"), fit_iter = 200 * thin)
rank <- calculate_rank(theta_prior, theta_post, thin = thin) # thinning factor of 3
plot_hist(rank, "mu")
```

```
reject <- rowSums(sampled_y) < 0
rank_reject <- calculate_rank(theta_prior[!reject, , drop = FALSE ], theta_post[!reject,,, drop = FALSE ], thin = thin) # thinning factor of 3
plot_hist(rank_reject, "mu")
```