Rejecting initial value

Hi everyone, this is my first post in the community and I am totally new to R. I am sorry to bother you guys and please tell me if there is anything else I need to provide.
I am basically trying to build a hierarchical model. But after reading the stan file, it continues to report ‘rejecting initial value’.
Here is the Stan code:

data {
  int<lower=0> N;
  int<lower=1> M;
  int<lower=1> C;
  row_vector[M] X[N];
  int<lower=0,upper=1> Y[N];
  int<lower=1,upper=C> A[N];
}


parameters {
  real mu[M];
  real<lower=0> sigma[M];
  vector[M] beta[C];
}


model {
  for (m in 1:M){
    mu[m] ~ normal(0,10);
    for (c in 1:C)
    beta[c,m] ~ normal(mu[m],sigma[m]);
  }
  for (n in 1:N)
  Y[n] ~ bernoulli(inv_logit(X[n] * beta[A[n]]));
}

And my data:

# csv attached below
heart <- read.csv("heart_failure_clinical_records_dataset.csv")
for (n in 1:299) {
    if(heart$age[n]<=50){
        heart$age[n]<-1
    }else if(heart$age[n]<=60 & heart$age[n]>50){
        heart$age[n]<-2
    }else if(heart$age[n]<=70 & heart$age[n]>60){
        heart$age[n]<-3
    }else if(heart$age[n]<=80 & heart$age[n]>70){
        heart$age[n]<-4
    }else if(heart$age[n]<=100 & heart$age[n]>80){
        heart$age[n]<-5
    }
}

dataH <-
  list(
    N = 299,
    M = 11,
    X = cbind(
      heart$anaemia,
      heart$creatinine_phosphokinase,
      heart$diabetes,
      heart$ejection_fraction,
      heart$high_blood_pressure,
      heart$platelets,
      heart$serum_creatinine,
      heart$serum_sodium,
      heart$sex,
      heart$smoking,
      heart$time
    ),
    Y = heart$DEATH_EVENT,
    C = 5,
    A = heart$age
  )

And the data file is here:
heart_failure_clinical_records_dataset.csv (12.0 KB)
I am quite frustrated and I have tried to modify my lower and upper bounds but did not work. I will trully appreciate if you guys could help me solve this problem.

Hi and welcome.

Failure to initialize usually means the random draws of initial values happen to fall in regions with zero probability, this is likely when the model is high dimensional and most of the parameters space has very low probability (even if it’s not strictly zero it may be rounded off due to the variable precision).

The Stan error may tell you more precisely which variables have zero (something along the lines of log p(x) = -inf), and if you know a value that will have positive probabilities you can initialize the chain with that value – like the data dictionary you can pass an “init” dictionary.

You can also simulate some data under known parameters to test that everything is working as expected under better-known conditions. Another alternative is reducing M and N (and the data, accordingly) to make the model more manageable and make sure there are no other errors.
If everything is working as expected I’d try finding an point in parameter space that has nonzero likelihood and initialize the chain with that (sometimes you can just just start the chain a few times and it will randomly find a suitable initial point).