Gaussian CAR


Hy Stan Team!

I have an error in my code which I can’t fix by myself. The message was "Rejecting initial value:"
But I already remove my Inits for Stan create it for itself

my code:
car_code_x_hm <-“
data {
int<lower=0> N; # number of observations
int<lower=0> K; # number of covariates
vector[N] y; # target variable
matrix[N,N] W; # weight matrix
matrix[N,(K+1)] X; # covariates
transformed data {
vector[N] zeros;
vector[N] ones;
matrix[N,N] D;
vector[N] W_rowsums;
for (n in 1:N) {
W_rowsums[n] = sum(W[n, ]);
D = diag_matrix(W_rowsums);
zeros <- rep_vector(0, N);
ones <- rep_vector(1, N);
parameters {
vector[N] car; # phis in literature
real<lower=0> tau; # precision
real<lower=0, upper=1> phi; # spatial correlation
vector[(K+1)] beta; # intercept and coefficients
model {
car ~ multi_normal_prec(zeros, tau*(D - phi * W));
tau ~ gamma(1, 1); # prior sigma
phi ~ beta(2, 2); # prior phi
for (k in 1:(K+1)){
beta[k] ~ normal(0, 1); # prior beta
y ~ normal(X*beta + car,ones);

This code was inspired in a Poisson-CAR, but I have a Normal-CAR:

Tks a lot team!


I’m way behind in cleaning up unanswered posts.

Try running with one chain and multi-core off (if you’re in R) so that you can see the warning messages. You’ll also need RStan 2.16. If you’re using CmdStan, you should be seeing an additional message.

Rejection is when indexes go out of bounds or some function evaluates to an exception or not-a-number of some negative infinity value gets added to the log density. You can also debug by printing as you go.