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.
math sql statistics
Matt howells
source share