hello,
The following paragraph is my stan code.
I ran 2-chain with 2-cores and iteration 150000 times.
It took around 69 hrs.
I really want to know how can I speeding up my code.
Thank you.
data
{
int <lower=0> n;//206
int <lower=0> N;//2695
cov_matrix[3] S;
vector<lower=0>[n] stage;//early stage and advanced stage
int<lower=0> ID[N];
vector[N] observetime;
vector[N] log10ca125;
}
parameters
{
real u1; // sigma
real<lower=0> u2; // sigma_stage
real u11; // beta1
real<lower=0> u12; // beta1_stage
real beta2; //beta2
real beta3; //beta3
real delta; //skewness parameters of random error
vector[3] deltab; //skewness parameters of random effect
matrix<lower=0>[n,3] wb; //wb = |X_0b|~|N(0,1)|
cov_matrix[3] cov;
matrix[n,3] b; //random effect
real<lower=3> nu; //degree of freedom
vector<lower=0>[n] ue; //latent random variables generated by ST distribution
vector<lower=0>[N] w;
vector[N] Y_pred;
}
transformed parameters
{
vector[n] beta1; // Stage info for extra random effects mean
vector<lower=0>[n] sigma; // Standard deviation
matrix[n,3] mub;//mean of random effect matrix
real d1;
real<lower=0> mue;
//----------------------------------------
vector[n] p1;
vector[n] p2;
vector[n] p3;
//----------------------------------------
vector[N] dm;
vector[N] mu;
vector[N] aau;
vector[N] res;
vector[N] sue;
real sten;
//----------------------------------------
beta1 = u11 + u12 * stage;
sigma = exp(u1 + u2 * stage);
for(i in 1:3)
{
mub[,i] = deltab[i] * (wb[,i] - sqrt(2/3.14159));
}
//means of error term (ST distribution)
mue = exp(lgamma(0.5*(nu-1)) -lgamma(0.5*nu))*sqrt(nu/3.14159);
d1 = nu/2;
sten = sqrt(10);
// Mixture of nonlinear mixed-effects models with two components using ST distribution
p1 = beta1 + b[,1];
p2 = beta2 + b[,2];
p3 = beta3 + b[,3];
sue = sqrt(ue[ID]);
aau = sue .* sigma[ID];
dm = ( p1[ID] + p2[ID] .* observetime + p3[ID] .* observetime .* observetime)/log(10);
mu = dm + delta*(w-mue);
res = log10ca125 - mu;
}
//----------------------------------------
model
{
//degree of freedom
nu ~ exponential(0.1);
// Linear regression
u1 ~ normal(0,sten);
u2 ~ normal(0,sten);
u11 ~ normal(0,sten);
u12 ~ normal(0,sten);
//skewness parameters
delta ~ normal(0,sten); //random error
deltab ~ normal(0,sten); //random effect
//Random effects of response model
for(i in 1:3)
wb[,i] ~ normal(0,1);
//Variance-covariance matrix
cov ~ inv_wishart(3,S);
//random effect
for(s in 1:n)
b[s,] ~ multi_normal(mub[s,],cov);
//Latent random variables generated by ST distribution
ue ~ inv_gamma(d1,d1);
w ~ normal(0,sue);
//Coefficients
beta2 ~ normal(0,sten);
beta3 ~ normal(0,sten);
//Generate ST random variable y from the SN tandom variable z.
log10ca125 ~ normal(mu, aau);
Y_pred ~ normal(mu, aau);
}