Custom likelihood of spatial survival model.pdf (231.0 KB)

Hello! I am writing the codes of my spatial survival model in Stan. The likelihood function of my model is attached (where Xj is the white noise and Xj ∼ N (0, sigma) ).

I defined the likelihood of the attached model for exponential distribution as follows in the Stan software, but

I have trouble coding and executing the model and I do not know exactly how to consider the censoring variable (in the codes, censor. status variable indicates right censorship) in the definition of likelihood and model. Can anyone help me?

```
functions {
real newweibul_log (vector time,vector censor.status,vector age, matrix kernel,vector x,vector p, int n_g,int province, real beta0,real beta, real sigma, vector lam) {
matrix [province,n_g] lambda;
vector [province] z;
vector [province] a;
matrix [province,num_elements(time)] L;
real L_i;
for (k in 1:province) {
for (j in 1:n_g) {
lambda [k,j] = kernel [k,j] * exp (x[j]);
}
z[k] = sum(lambda[k,]) * p[k];
a[k] = z[k]/sum(z);
}
for (i in 1:num_elements(time)){
log(lam[i]) = beta0 + beta1 * age[i];
}
for (k in 1:province) {
for (i in 1:num_elements(time)) {
L [k,i] = ((a[k]* lam [i] * exp( - lam [i] * time[i])) ^ censor.status[i]) * ((a[k]*exp(-lam [i]*time[i]))^ (1-censor.status[i]));
}
}
L_i = sum(log(L));
return L_i;
}
}
data {
int <lower=0> province;
int <lower=0> n_grid;
int <lower=0> N;
vector <lower=0> [province] p;
vector [N] time;
vector [N] age;
vector [n_grid] x;
matrix [province,n_grid] kernel;
//vector<lower=0, upper=1> [N] censor.status;
}
parameters{
real <lower=0> sigma;
real beta0;
real beta;
real lambdaa;
real a;
}
transformed parameters{
real time_ratio;
time_ratio = exp(beta);
}
model{
for (j in 1:n_grid){
x ~ normal(0,5);
}
beta0 ~ normal( 0, 100);
beta ~ normal( 0, 100);
// real alpha;
//real bettta;
//alpha < - 1;
//bettta < - 1;
sigma ~ gamma(1, 1);
//mu ~ normal( 0, 100);
//real alpha0;
// real bettta0;
// alpha0 < - 1;
// bettta0 < - 1;
lambdaa ~ gamma(1, 1);
for (i in 1:N) {
time[i] ~ newweibul ( beta0, beta, lambdaa[i], a[k]) ;
}
}
```

Regards,

Eisa