Howdy. Has anyone else run into an error from the Stan parser when trying to fit a negative binomial distributional model where there is a rate offset and there are missing values in the predictors?
I am using brms version 2.17.0. I can fit the following without problems:
x <- rnorm(300, 0, 1)
d <- rpois(300, 200)
mu <- exp(-2 + 0.1*x + log(d))
shape <- exp(0 + 0.5*x)
y <- rnbinom(300, mu=mu, size=shape)
hist(y)
d1 <- cbind.data.frame(y,x,d)
str(d1)
bf1 <- bf(y | rate(d) ~ 1 + x, shape ~ 1 + x) + negbinomial()
m1 <- brm(bf1, data=d1, cores=4)
m1
However, if I create a new variable from x
that has missing values, I get an error from the Stan parser.
d1$x2 <- c(d1$x[1:250],rep(NA,50))
bf2 <- bf(y | rate(d) ~ 1 + mi(x2), shape ~ 1 + mi(x2)) + negbinomial()
bfm <- bf(x2 | mi() ~ 1) + gaussian()
m2 <- brm(bf2 + bfm, data=d1, cores=4)
m2
Which results in the following error:
Setting 'rescor' to FALSE by default for this model
Compiling Stan program...
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
No matches for:
vector * vector
Available argument signatures for operator*:
real * real
vector * real
row_vector * real
matrix * real
row_vector * vector
vector * row_vector
matrix * vector
row_vector * matrix
matrix * matrix
real * vector
real * row_vector
real * matrix
Expression is ill formed.
error in 'model73f449196074_40cd6aa6d7c4092e190360a11e6a94dc' at line 62, column 81
-------------------------------------------------
60: shape_y[n] = exp(shape_y[n]);
61: }
62: target += neg_binomial_2_log_lpmf(Y_y | mu_y + log_denom_y, shape_y * denom_y);
^
63: target += normal_lpdf(Yl_x2 | mu_x2, sigma_x2);
-------------------------------------------------
Error in stanc(file = file, model_code = model_code, model_name = model_name, :
failed to parse Stan model '40cd6aa6d7c4092e190360a11e6a94dc' due to the above error.
Note that this model results in the same error:
bf3 <- bf(y | rate(d) ~ 1 + mi(x2), shape ~ 1 + x) + negbinomial()
bfm2 <- bf(x2 | mi() ~ 1) + gaussian()
m3 <- brm(bf3 + bfm2, data=d1, cores=4)
m3
So, it doesn’t require missings in the predictor for the shape parameter to get the error.
Is this a bug, or am I missing something? Thanks!