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.