I’m working with pipeline crack depths measured by an inspection tool. The tool error is normally distributed with a nonzero bias, and it cannot report a value <= 0 since that doesn’t make sense. As such, the tool measurements follow a truncated normal distribution.

The minimal example below (written in R) attempts to recover the bias and SD of the error distribution. It works reasonably well for 500 cracks, but for 15 cracks, it complains about divergent transitions after warmup. I’ve reparameterized other models following the Neal’s Funnel example before, but am not sure how to go about it here.

Interestingly, the same model without the `T[-trueVal[i],]`

truncation does not complain about divergent transitions, but it overestimates the bias and underestimates the SD as expected.

Attached is the accompanying pairs plot, which shows there is a problem, but again I’m not sure how to solve it.

Any help is appreciated.

Thanks!

```
rm(list = ls())
library(rstan)
library(truncnorm)
measBias <- 0.2
measSD <- 1.2
N <- 15
modelStr <- "
data {
int<lower=0> N;
real measVal[N];
real trueVal[N];
}
parameters {
real measBias;
real<lower=0> measSD;
}
model {
real error[N];
for (i in 1:N) {
error[i] = measVal[i] - trueVal[i];
error[i] ~ normal(measBias, measSD) T[-trueVal[i],];
}
}
"
stanModel <- stan_model(model_code = modelStr)
trueVal <- qlnorm(p = (1:N)/(N+1), meanlog = -0.112, sdlog = 0.472) # equivalent to mean = 1, SD = 0.5
measVal <- rtruncnorm(n = 1, a = 0, mean = trueVal + measBias, sd = measSD)
stanData <- list(N = N, trueVal = trueVal, measVal = measVal)
result <- sampling(stanModel, data = stanData, iter = 500,
chains = 1, cores = 1)
```