Weibull Distribution in RSTAN

I want to develop stan(rstan) code for weibull distribution. With input data:

  • tStart_Exposure
  • tEnd_Exposure
  • tSymptom_Onset.
    I didn’t develop issue with ffiting a Weibull distribuiton.
    I refer to from Wiki Weibull distribution - Wikipedia
    Please teach me how to write with this problem…

We did this actually in one of our earlier works: Jupyter Notebook Viewer - please see Weibull distribution (EL and ER are your exposure times, SL and SR are the onsets). The code is there, but, excuse me, I don’t have time to teach somebody.

ps: source on github

1 Like

Other way, I wrote in here,

Weibull Distribution

"data {
int<lower = 1> N; // number of records
vector<lower = 0>[N] EL;
vector<lower = 0>[N] ER;
vector<lower = 0>[N] SL;
vector<lower = 0>[N] SR;
}

parameters {
real<lower = 0> alphaW; // Shape parameter of weibull distributed incubation period
real<lower = 0> sigmaW; // Scale parameter of weibull distributed incubation period
vector<lower = 0, upper = 1>[N] uE_W; // Uniform value for sampling between start and end exposure
vector<lower = 0, upper = 1>[N] uS_W; // Uniform value for sampling between early and late symptom
}

transformed parameters{
vector[N] tE_W; // moment of infection
tE_W = EL + uE_W .* (ER - EL);
tS_W = SL + uS_W .* (SR - SL);
}

model{
// Contribution to likelihood of incubation period
target += weibull_lpdf(tS_W - tE_W | alphaInc, sigmaInc);
}

generated quantities {
// likelihood for calculation of looIC
vector[N] log_lik;
int k =1;
while (k < N+1) {
log_lik[k] = weibull_lpdf(tS_W[k] - tE_W[k] | alphaW, sigmaW);
k = k+1;
}
}
"
Please help me