6 Linear model
While the assumtions of a linear model are never perfectly met, we must still check if they are reasonable assumtions to work with.
6.1
## Data from https://github.com/thomas-haslwanter/statsintro_python/blob/master/ISP/Code_Quantlets/08_TestsMeanValues/anovaOneway/galton.csv
tab<-read.csv("data/galton.csv")
head(tab)
## family father mother sex height nkids
## 1 1 78.5 67.0 M 73.2 4
## 2 1 78.5 67.0 F 69.2 4
## 3 1 78.5 67.0 F 69.0 4
## 4 1 78.5 67.0 F 69.0 4
## 5 2 75.5 66.5 M 73.5 4
## 6 2 75.5 66.5 M 72.5 4
6.2 Extract male data
tab_son = tab[tab$sex=="M", ]
head(tab_son)
## family father mother sex height nkids
## 1 1 78.5 67.0 M 73.2 4
## 5 2 75.5 66.5 M 73.5 4
## 6 2 75.5 66.5 M 72.5 4
## 9 3 75.0 64.0 M 71.0 2
## 11 4 75.0 64.0 M 70.5 5
## 12 4 75.0 64.0 M 68.5 5
plot(father~height, data=tab_son)
6.3 Reference
How to apply Linear Regression in R: https://datascienceplus.com/how-to-apply-linear-regression-in-r/
R for Data Science: https://r4ds.had.co.nz/model-basics.html#a-simple-model