# Prediction Interval in the Generated Quantities block

I am working a very basic Bayes Lasso model and I have included the code here. While the code is working just fine, I was wondering if there is any way I can include a line of code that will provide me with the pointwise 95% prediction interval in the generated quantity block. I am guessing there is the computationally strenuous way of defining the prediction interval. But I was wondering if there is a piece of STAN code that just computes the pointwise prediction interval automatically. Thank you in advance.

``````data {
int<lower=1> N; // Number of data points in training set
int<lower=1> M; // Number of covariates
int<lower=1> N2; // Number of obs to predict in test set
matrix[N, M] X;
matrix[N2, M] X2pred;
int<lower=0,upper=1> y[N];
}
parameters {
vector[M] beta;
real<lower=0> sigma;
}
model {
beta ~ double_exponential(0, sigma);
sigma ~ inv_gamma(0.1,0.1);
y ~ bernoulli_logit(X * beta);
}
generated quantities{
int<lower=0,upper=1> y_post[N2];
y_post = bernoulli_logit_rng(X2pred*beta);
}
``````
1 Like

Hi, since nobody else answered, I will give it a try:

The main confusion is IMHO that you want prediction intervals for each iteration. I don’t think you can do this easily. Instead, I think you want to make a single prediction in the generated quantitites (as you do) and then just use the 95% interval of those from the fit output as the prediction interval.

Does that make sense or am I missing something?

1 Like

Thank you for your input. Actually I did figure out the situation and you are right we can get the 95% prediction interval from the fit output. It was a matter of miscommunication among the people involved in the project.