regression-multivariate-linear icon indicating copy to clipboard operation
regression-multivariate-linear copied to clipboard

Prediction with confidence interval

Open jospueyo opened this issue 2 years ago • 2 comments

Hello.

Is there an option to get the confidence interval in mlr.predict()?

If not, might you be interested in a pull request implementing this?

jospueyo avatar May 02 '23 10:05 jospueyo

Hi @jospueyo , we do not currently have any method to compute the confidence interval in this library. Could you explain what you would like to implement exactly (what algorithm would you use to compute it)?

It would be ideal if you could link an article explaining the algorithm. Thanks!

opatiny avatar Jun 08 '23 12:06 opatiny

Hi @opatiny, thanks for your answer.

Currently, I'm using a function from jstat library to calculate the student's T distribution based on the degress of freedom of the mlr. Then, I used a simplified method to estimate the confidence interval. I'm sorry but I don't have a reference for this, I just asked to a colleague in the statistics department.

const mlr = new MLR(x, y)

const prediction = mlr.predict([0.5, 0.5])

// first arg is the confidence level and second arg i degress of freedom 
const Z_095 =  jstat.studentt.inv(0.025, 97);
const interval = Z_095 * mlr.stdError / Math.sqrt(x.length) 

const ci = [
   prediction[0],
   prediction[0] + interval,
   prediction[0] - interval
]

So, at this moment, including this in mlr would add a dependence to jstat.

jospueyo avatar Jun 09 '23 06:06 jospueyo