Dear fellow stan users:
My model is a 2-component mixture of normal with a constraint such that the overall mean is modelled by a cyclic b-spline.
I am trying to model hour of day temporal effect where my y_it (i=1:13, t=1:24, in other words, there are 13 IID observations per hour of day) is simulated from
##simulate a single day total PNC
TT = rep(1:24)
T = length(TT)
N = 13
##first mixture component hourly temporal effect
sinT = 0.5*sin(2*pi*TT/24)
##second mixture component hourly temporal effect
cosT = 0.5*cos(2*pi*TT/24)+10
mu <-matrix(c(sinT, cosT),T,2);
sigma <- c(0.1);
set.seed(100)
lambda = runif(1,0,1) ## when simulating the data, mixture weights are not time-dependent but when modelling the
##dynamic processes, we allow mixture weights to be time dependent to capture the correlation between observations.
##simulate component indicator
z <-matrix(0, 13, T)
for(i in 1:T){
z[,i] <- rbinom(N, 1, lambda) + 1;
}
y <- matrix(0, N, T)
set.seed(100)
for(i in 1:T){
y[,i] <- mu[i,z[,i]] + rnorm(N,0, sigma)
}
I would like to estimate time-dependent mixing proportions theta (a vector of 24 elements), time-dependent location mu (a vector of 24 elements ) and a global sigma.
Specifically, I want to use a cyclic B-spline to capture the hourly temporal effect and I rather than modelling mixture component as 2 cyclic B-spline, I model the overall mean
that is theta[t] * mu[t,1] +(1-theta[t]) * mu[t,2] = f(x_t) where f(x_t) = B_T (cyclic bspline basis with 6 bases) * theta_cyclic (its corresponding spline coefficients to be estimated as well).
In addition, I impose a second-order penalty prior on theta_cyclic to ensure that the spline fit is not too wiggly.
With all the above specification, my model cannot run and it gives the following error message:
Initialization between (-2, 2) failed after 100 attempts.
Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.
I am assuming it has something to do with my highly constrained parameters or there are something I overlook?
Any suggestions would be greatly appreciate it.
Thanks, in advancedata.r (1.5 KB)
classical_gauss_mix.stan (3.8 KB)
bspline basis construction function.r (3.8 KB)
last file contains the functions for constructing cyclic bspline basis functions and 2nd order penalty prior for theta_cyclic parameters.
[edit: escaped code blocks]