How to calculate the 99% confidence interval for the slope in a linear regression model in python?

前端 未结 2 489
一向
一向 2020-12-16 03:16

We have following linear regression: y ~ b0 + b1 * x1 + b2 * x2. I know that regress function in Matlab does calculate it, but numpy\'s linalg.lstsq doesn\'t (https://docs.s

2条回答
  •  粉色の甜心
    2020-12-16 04:00

    You can use scipy's linear regression, which does calculate the r/p value and standard error : http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.stats.linregress.html

    EDIT : as underlines by Brian, I had the code from scipy documentation:

    from scipy import stats
    import numpy as np
    x = np.random.random(10)
    y = np.random.random(10)
     slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
    
    confidence_interval = 2.58*std_err
    

提交回复
热议问题