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:
http://mc-stan.org/users/documentation/case-studies/mbjoseph-CARStan.html
Tks a lot team!