I have been given data

`x = c(21,34,6,47,10,49,23,32,12,16,29,49,28,8,57,9,31,10,21,26,31,52,21,8,18,5,18,26,27,26,32,2,59,58,19,14,16,9,23,28,34,70,69,54,39,9,21,54,26) y = c(47,76,33,78,62,78,33,64,83,67,61,85,46,53,55,71,59,41,82,56,39,89,31,43,29,55, 81,82,82,85,59,74,80,88,29,58,71,60,86,91,72,89,80,84,54,71,75,84,79)`

How can I obtain the residuals and plot them versus $x$? And how can I test if the residuals appear to be approximately normal?

I’m not sure if I do the original linear fit correctly as I got the equation $y=6.9x-5.5$ but the lecture notes says that the linear regression line should be of the form $y_i=\beta_0+\beta_1x+\epsilon$.

**Answer**

EDIT: You have an `R`

tag but then in a comment say you don’t know much about it. This is `R`

code. I know nothing about Sage. End edit

You can do this

```
x = c(21,34,6,47,10,49,23,32,12,16,29,49,28,8,57,9,31,10,21,
26,31,52,21,8,18,5,18,26,27,26,32,2,59,58,19,14,16,9,23,
28,34,70,69,54,39,9,21,54,26)
y = c(47,76,33,78,62,78,33,64,83,67,61,85,46,53,55,71,59,41,82,
56,39,89,31,43,29,55, 81,82,82,85,59,74,80,88,29,58,71,60,
86,91,72,89,80,84,54,71,75,84,79)
m1 <- lm(y~x) #Create a linear model
resid(m1) #List of residuals
plot(density(resid(m1))) #A density plot
qqnorm(resid(m1)) # A quantile normal plot - good for checking normality
qqline(resid(m1))
```

**Attribution***Source : Link , Question Author : guest , Answer Author : Peter Flom*