Linear Model – How to Calculate Residuals from a Given Linear Model

linear modelmatrixrresiduals

So I have been given a linear model, with the Beta0 = 0 as well as given equations. I have done several calculations needed in order to calculate residuals, as shown in my work below:

enter image description here

I also went ahead and calculated the normal equations as well:

enter image description here

From here, I have been tasked with calculating the residuals and then inserting the model into R to compare to results to make sure they are the same. The whole point of this particular exercise is to understand how residuals are calculated. My results of my manual residual calculations are below:

enter image description here

This works just fine and matches the R output. However, R gives an additional set of 3 more residuals, seen from my code:

Y <- c(1.3, 0.9, 0.8)
X1 <- c(-1, 0, 1)
X2 <- c(1, -2, 1)
SB <- lm(Y ~ 0 + X1 + X2)
summary(SB)
## 
## Call:
## lm(formula = Y ~ 0 + X1 + X2)
## 
## Residuals:
## 1 2 3 
## 1 1 1 
## 
## Coefficients:
##    Estimate Std. Error t value Pr(>|t|)
## X1  -0.2500     1.2247  -0.204    0.872
## X2   0.0500     0.7071   0.071    0.955
## 
## Residual standard error: 1.732 on 1 degrees of freedom
## Multiple R-squared:  0.04459,    Adjusted R-squared:  -1.866 
## F-statistic: 0.02333 on 2 and 1 DF,  p-value: 0.9775

How do I calculate these other residuals (the 1 2 and 3)? I get the second set of 1 1 1, but I'm not sure where 1 2 3 is coming from? I attached some code that should allow matrices to be recreated as well:

b1 <- c(1/3, 1/3, 1/3)
b2 <- c(1/3, 1/3, 1/3)
b3 <- c(1/3, 1/3, 1/3)
Matrix <- cbind(b1, b2, b3)
Matrix

c1 <- c(1.3, 0.9, 0.8)
Y <- bind(c1)
Y

Best Answer

The top row tells you the position to which the number in the bottom row corresponds. Your first residual is $1$, your second residual is $1$, and your third residual is $1$.

Related Question