# Weibull Distribution in RSTAN

**URL:** <https://discourse.mc-stan.org/t/weibull-distribution-in-rstan/23102>\
**Category:** Modeling\
**Created:** [June 21, 2021, 8:20am UTC](https://discourse.mc-stan.org/t/weibull-distribution-in-rstan/23102 "2021-06-21T08:20:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DrDinhLuong](https://avatars.discourse-cdn.com/v4/letter/d/e68b1a/32.png) [@DrDinhLuong](https://discourse.mc-stan.org/u/DrDinhLuong)\
**Post date:** [June 21, 2021, 8:20am UTC](https://discourse.mc-stan.org/t/weibull-distribution-in-rstan/23102/1 "2021-06-21T08:20:58Z")

</div>

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](https://en.wikipedia.org/wiki/Weibull_distribution)  
Please teach me how to write with this problem…

---

<div class="post-metadata">

**Author:** ![aakhmetz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/aakhmetz/32/18672_2.png) [@aakhmetz](https://discourse.mc-stan.org/u/aakhmetz)\
**Post date:** [June 21, 2021, 10:57am UTC](https://discourse.mc-stan.org/t/weibull-distribution-in-rstan/23102/2 "2021-06-21T10:57:40Z")

</div>

We did this actually in one of our earlier works: [Jupyter Notebook Viewer](https://nbviewer.jupyter.org/github/aakhmetz/WuhanIncubationPeriod2020/blob/master/scripts/A.%20MCMC%20simulations%20in%20Stan.ipynb) - 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](https://github.com/aakhmetz/COVID19IncubationPeriod)

---

<div class="post-metadata">

**Author:** ![DrDinhLuong](https://avatars.discourse-cdn.com/v4/letter/d/e68b1a/32.png) [@DrDinhLuong](https://discourse.mc-stan.org/u/DrDinhLuong)\
**Post date:** [June 21, 2021, 3:31pm UTC](https://discourse.mc-stan.org/t/weibull-distribution-in-rstan/23102/3 "2021-06-21T15:31:16Z")

</div>

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
