Simple linear regression (3/5)- standard error of slope and intercept

Simple linear regression (3/5)- standard error of slope and intercept


Previous post!!
Simple linear regression (1/5)- correlation and covariance
Simple linear regression (2/5)- slope and intercept of linear regression model




In my previous post, I explained how to calculate slope (β1) and intercept (β0) of linear regression model.

x=c(10,20,30,40,50)
y=c(100,120,140,150,160)
dataA=data.frame(x,y)
summary(lm(y~x))

If you well followed my previous posts, you will get the above result, y= 89.0 + 1.5x 

Now our interest is how to calculate standard error in the intercept and slope (Red box). Here is the equation to obtain standard error of intercept (β0) and slope (β1).

The following question would be what ei2 is. Let’s calculate ei2 which is the sum of square of error.

nxi(xi – x̄)(xi – x̄)2yiŷ (ŷ= 89.0+1.5x)(yi – ŷ)(yi – ŷ)2
110-20.0400.0100104.0-4.016.0
220-10.0100.0120119.01.01.0
3300.00.0140134.06.036.0
44010.0100.0150149.01.01.0
55020.0400.0160164.0-4.016.0
x̄ = 30.0Σ (xi – x̄)2 = 1000.0Σ (yi – ŷ)2 = 70.0

Σei2 is 70.0. This is Sum Squared Error (SSE), Σ(yi - ŷ)2

If we divide this value by degree of freedom (n-2), it will be variance of error (also we call Mean squared error, MSE). Let’s divide 70.0 by 3 (=5-2).

It would be 23.3 (=70.0 / 3)

Then let’s calculate square root of 23.3.

√ 23.3 = 4.83

We calculate square root of variance. This is the concept of standard deviation.

Therefore, the above equation will be calculated as √(Σ(yi - ŷ)2 / (n-2)) = √70.0 / (5-2) ≈ 4.83

Let’s calculate the other equation.

√(1/5 + 30.02 / 1000.0) ≈ 1.05

Therefore, the standard error of intercept would be

√(Σ(yi - ŷ)2 / (n-2)) * √(1/n + x̄2 / Σ(xi – x̄)2)
= 4.83 * 1.05 ≈ 5.07

The standard error of intercept is 5.07. In R, it was 5.0662. It’s the same value.



Now, let’s calculate standard error of slope.

We already know variance of error; Σ(yi - ŷ)2 / (n-2)

It’s 23.3

We already calculated Σ (xi – x̄)2

It’s 1,000

Then SE(b1) will be √ 23.3 / 1000 ≈ 0.153

It’s the same as R provided.



Mean squared error, MSE

I told you when Sum Squared Error (SSE), Σ(yi - ŷ)2 is divided by degree of freedom (n-2), it will be variance of error (also we call Mean squared error, MSE); Σ(yi - ŷ)2 / (n-2)

Statistical programs automatically calculate this value.

x<- c(10,20,30,40,50)
y<- c(100,120,140,150,160)
dataA<- data.frame(x,y)
linear<-lm(y~x)
summary(linear)
anova(linear)

If you run statistical programs, you will find two results. One is the table for coefficients, and another is the ANOVA table. In ANOVA table, you can find MSE. Here, it’s 23.33 which is the same value we calculated by hand. About ANOVA table in regression model, I’ll explain 5th chapter; R-squared (Coefficient of determination).



The next question is how to calculate t-value of slope and intercept in the table for coefficients?

The answer will be in the next post!!


Follow up!!
Simple linear regression (4/5)- t value on the slope and intercept



Leave a Reply

If you include a website address in the comment section, I cannot see your comment as it will be automatically deleted and will not be posted. Please refrain from including website addresses.