Linear Regression Confidence Intervals in SQL

I use fairly straightforward SQL to calculate the regression (intercept and tilt) coefficients of some (x, y) data points using least squares. This gives me a good line of best fit data. However, we would like to see 95% and 5% confidence intervals for the line of best fit (curves below).

link text http://www.curvefit.com/2a03be60.gif

This means that the true line has a 95% probability of being below the upper curve and a 95% probability of being above the lower curve. How can I calculate these curves? I already read wikipedia etc. And I did some search queries, but I did not find any clear mathematical equations so that they could be calculated.

Edit: here is the gist of what I have now.

--sample data create table #lr (x real not null, y real not null) insert into #lr values (0,1) insert into #lr values (4,9) insert into #lr values (2,5) insert into #lr values (3,7) declare @slope real declare @intercept real --calculate slope and intercept select @slope = ((count(*) * sum(x*y)) - (sum(x)*sum(y)))/ ((count(*) * sum(Power(x,2)))-Power(Sum(x),2)), @intercept = avg(y) - ((count(*) * sum(x*y)) - (sum(x)*sum(y)))/ ((count(*) * sum(Power(x,2)))-Power(Sum(x),2)) * avg(x) from #lr 

Thanks in advance.

+6
math sql statistics
source share
3 answers

The equation for the width of the confidence interval as f (x) is given here in the section "Confidence Interval at Set Values"

http://www.weibull.com/DOEWeb/confidence_intervals_in_simple_linear_regression.htm

The page will also guide you through the calculation example.

+1
source share

Try this site and scroll down to the middle. For each point in your line of best fit, you know your Z, your sample size, and your deviation std.

http://www.stat.yale.edu/Courses/1997-98/101/confint.htm

0
source share

@PowerUser: he needs to use equations for two variables, not for installations with one variable.

Matt: If I had an old textbook on statistics, I could tell you what you want; Unfortunately, I do not have it, and I do not have my notes from my high school course. On the other hand, from what I remember, he can only have material for the confidence interval of the slope of the regression line ...

In any case, this page, hopefully, will have some help: http://www.stat.yale.edu/Courses/1997-98/101/linregin.htm .

0
source share

All Articles