Hi
I am trying to fit a multistate model using Bayesian methods.
Most of the data are for exactly observed transition times. The likelihoods for various observation schemes are on page 9 of https://cran.r-project.org/web/packages/msm/vignettes/msm-manual.pdf.
I have coded some of these likelihoods into the function MarkovLH.
Am I properly using these likelihoods in the code below with the target += line?
functions{
real MarkovLH(int LHtype, real t1, real t2, real t3, real lam1, real lam2, real lam3){
real L;
real logL;
if (LHtype==1){
L=(exp((lam1+lam2)*t1)*lam1)*(exp((lam3)*t2)*lam3);
} else if (LHtype==2){
L=exp((lam3)*t1)*lam3;
}
logL=log(L);
return logL;
}
}
data {
int <lower=0> N;
int <lower=0> LHtype;
vector[N] grp;
vector[N] t1;
vector[N] t2;
vector[N] t3;
}
parameters {
real<lower=0> lambda [3];
real bet [3];
}
model {
for (i in 1:N){
target += MarkovLH(LHtype[i], t1[i], t2[i], t3[i], lambda[1]*exp(bet[1]*grp[i]), lambda[2]*exp(bet[2]*grp[i]), lambda[3]*exp(bet[3]*grp[i]) );
}
lambda ~ gamma(0.001, 0.001);
bet ~ normal(0, 100);
}