Hello, I have a simple univariable non-linear model with an exponent applied to the observed data. The model fails to fit with the following error:
Chain 16 Rejecting initial value:
Chain 16 Error evaluating the log probability at the initial value.
Chain 16 Exception: normal_lpdf: Location parameter[1] is nan, but must be finite! (in '/var/folders/v5/hz8q76_n1g1b7v_bmyfcp1qw0000gn/T/RtmpB3NTJV/model-f277aef2b02.stan', line 42, column 4 to column 42)
The model is written in brms:
brm(bf(log(NTDratio) ~ a + b1 * Age ^ b2, b1 + b2 + a ~ 1, nl = TRUE), family = gaussian(), Data %>% mutate(Age = Age - mean(Age)), backend = 'cmdstan', chains = 16, cores = 8, silent = 2, refresh = 0, iter = 8000,
normalize = F, control = list(adapt_delta = .95, max_treedepth = 15),
prior = c(
prior(student_t(3, 0, 1), class = 'b', nlpar = 'a'),
prior(student_t(3, 0, 1), class = 'b', nlpar = 'b1'),
prior(normal(0, 3), class = 'b', nlpar = 'b2', lb = 1)
))
and this is the related stan code:
data {
int<lower=1> N; // total number of observations
vector[N] Y; // response variable
int<lower=1> K_b1; // number of population-level effects
matrix[N, K_b1] X_b1; // population-level design matrix
int<lower=1> K_b2; // number of population-level effects
matrix[N, K_b2] X_b2; // population-level design matrix
int<lower=1> K_a; // number of population-level effects
matrix[N, K_a] X_a; // population-level design matrix
// covariate vectors for non-linear functions
vector[N] C_1;
int prior_only; // should the likelihood be ignored?
}
transformed data {
}
parameters {
vector[K_b1] b_b1; // population-level effects
vector<lower=1>[K_b2] b_b2; // population-level effects
vector[K_a] b_a; // population-level effects
real<lower=0> sigma; // residual SD
}
transformed parameters {
}
model {
// likelihood including constants
if (!prior_only) {
// initialize linear predictor term
vector[N] nlp_b1 = X_b1 * b_b1;
// initialize linear predictor term
vector[N] nlp_b2 = X_b2 * b_b2;
// initialize linear predictor term
vector[N] nlp_a = X_a * b_a;
// initialize non-linear predictor term
vector[N] mu;
for (n in 1:N) {
// compute non-linear predictor values
mu[n] = nlp_a[n] + nlp_b1[n] * C_1[n] ^ nlp_b2[n];
}
target += normal_lpdf(Y | mu, sigma);
}
// priors including constants
target += student_t_lpdf(b_b1 | 3, 0, 1);
target += normal_lpdf(b_b2 | 0, 3)
- 1 * normal_lccdf(1 | 0, 3);
target += student_t_lpdf(b_a | 3, 0, 1);
target += student_t_lpdf(sigma | 3, 0, 2.5)
- 1 * student_t_lccdf(0 | 3, 0, 2.5);
}
By my understanding, all parameters should be supported in the real line so I donât understand which combination of them is creating problems. Of note, the dataset is very small (20 obs).