# How to find the standard deviation s of simple linear regression coefficients Alpha and Beta in Matlab?

I have data and I need to do a linear regression on the data to obtain

y=Alpha*x+Beta

Alpha and Beta are estimators given by the regression, polyfit can give me those with no problem but this is a physical science report and I need to give error estimators on those values

I know from statistics that standard deviation exists for simple linear regression coefficients.

How can I calculate then in Matlab

Thank you

The second output of the regress command will give you 95% confidence intervals for the regression coefficients. Here's an example:

```>> x = [ones(100,1), (1:100)'];
>> alpha = 3; beta = 2;
>> y = x*[alpha; beta]+randn(100,1);
>> [coeffs, coeffints] = regress(y,x);
>> coeffs
coeffs =
2.9712
1.9998
>> coeffints
coeffints =
2.5851       3.3573
1.9932       2.0064
```

Here alpha has been estimated 2.9712, with 95% confidence interval of between 2.5851 and 3.3573, and beta has been estimated as 1.9998, with 95% confidence interval between 1.9932 and 2.0064.

The easiest solution is to use LSCOV:

```%# create some data
x = 1:10;
y = 3*x+randn(size(x))*0.1;

%# create the design matrix
A = [x(:),ones(length(x),1)];

[u,std_u] = lscov(A,y(:));

u =
3.0241
-0.070209
std_u =
0.018827
0.11682
```

Or just use the relationship that the length of the 95% Confidence Interval is 2*1.9654 standard errors so the standard errors in the example with regress above are given by:

st errors = (coeffints(:,2)-coeffints(:,1))/(2*1.9654).

The number 1.9654 appears because of the normality assumption in the regress function