If I want to fit a model that :
y=x_{1t}+x_{2t}+p_t+s_t
x_{1t},x_{2t}, p_{t}, s_t are latent variables. have distribution:
x_{it+1} \sim N([1-exp(-\kappa_i\Delta t)]\mu_i+exp(-\kappa_i)x_{it},\frac{\sigma_i^2}{2\kappa_i}[1-exp(-2\kappa_i\Delta t)]), \qquad (i=1,2)
p_t \sim N([1-exp(-\kappa_p\Delta t)]\mu_p+exp(-\kappa_p)p_{t},\frac{\sigma_p^2}{2\kappa_p}[1-exp(-2\kappa_p\Delta t)])
s_t is a stochastic volatility
The code is :
data {
int<lower=0> T; //the number of sample
real y1[T]; //data
}
parameters {
//parameters for mu
real mu1; //the mean for x1
real mu2; //the mean for x2
real mup; //the mean for p
real muh; //the mean for h
//parameters for sigma
real<lower=0> sigma1; //the standard deviation(sd) for x1
real<lower=0> sigma2; //the sd for x2
real<lower=0> sigmap; //the sd for p
real<lower=0> sigmah; //the sd for h
//parameters for kappa
real<lower=0> kappa1;
real<lower=0> kappa2;
real<lower=0> kappap;
vector<lower=0>[K] sigy1;
real<lower=-1,upper=1> phi_h;
//parameter for intercept
real cr;
// latent variables
vector[T] x1; //latent variabe vector x1
vector[T] x2; //latent variabe vector x2
vector[T] p; //latent variabe vector p
vector[T] h; //latent variabe vector h
vector[T] ep; //latent variabe vector ep
}
transformed parameters{
real<lower=0> sigr1;
real<lower=0> sigr2;
real<lower=0> sigp;
vector[T] my1;
sigr1=sigma1*sqrt((1-exp(-2*kappa1/52))/(2*kappa1));
sigr2=sigma2*sqrt((1-exp(-2*kappa2/52))/(2*kappa2));
sigp=sigmap*sqrt((1-exp(-2*kappap/52))/(2*kappap));
for (t in 1:T){
my1[t]= cr+x1[t]+x2[t]+p[t]+ep[t];
}
model{
//set priors
mu1 ~ normal(0,5);
mu2 ~ normal(0,5);
muh ~ normal(0,5);
mup ~ normal(0,5);
sigma1 ~ normal(0,1);
sigma2 ~ normal(0,1);
sigmap ~ normal(0,1);
sigmah ~ normal(0,1);
kappa1 ~ normal(0,10);
kappa2 ~ normal(0,10);
kappap ~ normal(0,10);
phi_h ~ uniform(-1, 1);
cr ~ normal(0,10);
sigy1 ~ normal(0,0.1);
//first value of latent variables
x1[1] ~ normal(0,5);
x2[1] ~ normal(0,5);
p[1] ~ normal(0,5);
h[1] ~ normal(muh, sigmah/sqrt(1-phi_h^2));
ep[1] ~ normal(0, exp(h[1] / 2));
for (t in 2:T){
x1[t]~normal((1-exp(-kappa1/52))*mu1+exp(-kappa1/52)*x1[t-1],sigr1);
x2[t]~normal((1-exp(-kappa2/52))*mu2+exp(-kappa2/52)*x2[t-1],sigr2);
p[t] ~ normal((1-exp(-kappap/52))*mup+exp(-kappap/52)*p[t-1],sigp);
h[t] ~ normal(muh + phi_h * (h[t - 1] - muh), sigmah);
ep[t] ~ normal(0, exp(h[t] / 2));
}
for(t in 1:T){
y1[t] ~ normal(my1[t],sigdr);
}
}
My questions are:
This model doesn’t have a stable solution. how can I get a stable solution, whether I need to set an initial value for SDE? Can this model be identified?